EmbDev.net

Forum: FPGA, VHDL & Verilog 4 bit adder in ghdl


von Fahim K. (fahimk)


Rate this post
useful
not useful
Hi,
I am trying to run the below example with error like
adder.vhdl:30:21: no function declarations for operator "+"
ghdl: compilation error

I am not able to recognise this error.
Can you please let me know where I am making mistake?

Also if the problem is with library then I have uncommented it and got 
different error like.

adder.vhdl:6:10: primary unit "std_logic_arith" not found in library 
"ieee"
adder.vhdl:7:10: primary unit "std_logic_unsigned" not found in library 
"ieee"


1
------Adder-------------------------------------------
2
3
library ieee;
4
use ieee.std_logic_1164.all;
5
use ieee.numeric_std.all;
6
--use ieee.std_logic_arith.all;
7
--use ieee.std_logic_unsigned.all;
8
9
-------------------------------------------------------
10
11
entity ADDER IS
12
13
generic( n: natural:=4);
14
15
port (A: in std_logic_vector(n-1 downto 0);
16
      B: in std_logic_vector(n-1 downto 0);
17
      CARRY: out std_logic;
18
      SUM: out std_logic_vector(n-1 downto 0)  
19
  );
20
end ADDER;
21
22
------------------------------------------------------
23
architecture behaviour of ADDER is
24
25
signal result:std_logic_vector(n downto 0);
26
 
27
begin
28
29
  --result <= ('0' & A)+('0' & B);
30
        result <= A + B;
31
  SUM <= result(n-1 downto 0);
32
  CARRY <= result(n);
33
end behaviour;
34
35
---------------------------------------------------------
36
---------TestBench--------------------------------------
37
---------------------------------------------------------
38
39
library ieee;
40
use ieee.std_logic_1164.all;
41
--use ieee.std_logic_unsigned.all;
42
--use ieee.std_logic_arith.all;
43
----------------------------------------------------------
44
entity ADDER_TB is        -- entity declaration
45
end ADDER_TB;
46
---------------------------------------------------------
47
architecture struct of ADDER_TB is 
48
49
component ADDER is
50
    port(  A:  in std_logic_vector(3 downto 0);
51
    B:  in std_logic_vector(3 downto 0);   
52
    CARRY:  out std_logic;          
53
    SUM:  out std_logic_vector(3 downto 0)
54
    );
55
    end component;
56
57
    signal A, B:  std_logic_vector(3 downto 0):="0000";
58
    signal CARRY:  std_logic;
59
    signal SUM:    std_logic_vector(3 downto 0):="0000";
60
61
begin
62
63
  result : ADDER port map(A => A,B => B,CARRY => CARRY,SUM => SUM);
64
65
   process
66
     begin
67
  
68
  --case1
69
  A<="0000";
70
  B<="0000";
71
  wait for 5 ns;
72
73
  ---case2
74
  A<="0000";
75
  B<="0010";
76
  wait for 5 ns;
77
78
  ---case3
79
  A<="0010";
80
  B<="0100";
81
  wait for 5 ns;
82
83
  ----case4
84
  A<="0110";
85
  B<="1001";
86
  wait for 5 ns;
87
88
  ----case5
89
  A<="1101";
90
  B<="0111";
91
  wait;
92
   end process;
93
end struct;

Regards,
Fahim

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
You cannot add two std_logic_vectors with the numeric_std!

You must add two unsigned values (defined in numeric_std) and therefore 
some casts are necessary:
1
signal result: unsigned(n downto 0);
2
3
   result <= unsigned(A) + unsigned(B);
4
   SUM    <= std_logic_vector(result(n-1 downto 0));


BTW:
You could add two vectors with std_logic_unsigned and std_logic_arith, 
but its strongly not recommended to use those old synopsys libs!

von Fahim K. (fahimk)


Rate this post
useful
not useful
Thanks Miller.

Just one question if I have to use unsigned then it is neccessary to use 
ieee.std_logic_unsigned.all; correct?

But when I am doing so I am getting the below error.

adder.vhdl:6:10: primary unit "std_logic_unsigned" not found in library 
"ieee"

Regards
Fahim

von Fahim K. (fahimk)


Rate this post
useful
not useful
Thanks Miller.

Just one question if I have to use unsigned then it is neccessary to use
ieee.std_logic_unsigned.all; correct?

But when I am doing so I am getting the below error.

adder.vhdl:6:10: primary unit "std_logic_unsigned" not found in library
"ieee"

Regards
Fahim

von berndl (Guest)


Rate this post
useful
not useful
try the cmd-line statement '--ieee=synopsys' and probably '-fexplicit' 
for ghdl...

von Fahim K. (fahimk)


Rate this post
useful
not useful
With -fexplicit  it is giving me same error however with --ieee=synopsys 
i am getting error but different one.

adder.vhdl:28:18: no declaration for "unsigned"
ghdl: compilation error

So I remove the unsigned part and run it with --ieee=synopsys and it 
works for me.

Thanks!!!!!!!!!!

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Fahim Khan wrote:
> Just one question if I have to use unsigned then it is neccessary to use
> ieee.std_logic_unsigned.all; correct?
You should NOT use ieee.std_logic_unsigned.all at all!

The datatypes unsigend and also signed are already defined in 
numeric_std.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.