EmbDev.net

Forum: FPGA, VHDL & Verilog Generic Adder in VHDL


Author: Martin (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello,
as I just started learning VHDL I still have a number of problems 
getting things running.
I would like to write a generic adder which adds to input values bit by 
bit.
In order to realize the generic functionality of the adder three 
std_logic_vectors were introduced which contain the input and the output 
(when the input was processed).

To check, if everything works correctly, I wrote a test bench. And 
that's where the problems start. When running the syntax check I get an 
error message telling me that n is not declared (in the section where 
the signals are declared).

VHDL code of the test bench:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;

ENTITY adder_tb IS
END adder_tb;

architecture behaviour of adder_tb is
  component adder
    generic(n : integer := 4);
    port(
      x : IN std_logic_vector(n-1 downto 0);
      y : IN std_logic_vector(n-1 downto 0);
      sum : OUT std_logic_vector(n-1 downto 0 );
      cout : OUT std_logic
    ); 
  end component;

  signal x_sig, y_sig, sum_sig : std_logic_vector(n-1 downto 0);
  signal cout_sig : std_logic := '0';
  
begin
    uut: adder PORT MAP (
          x => x_sig,
          y => y_sig,
          sum => sum_sig,
          cout => cout_sig
        );
end behaviour;


Does anybody see the problem? Thanks very much in advace!!!!

Author: Morin (Guest)
Posted on:

Rate this post
0 useful
not useful
The problem is in the line
signal x_sig, y_sig, sum_sig : std_logic_vector(n-1 downto 0);

n is not declared at this point. You have to add it as a generic or 
local in adder_tb.

You might think that the line
    generic(n : integer := 4);
declares n to be 4. However, this declaration is local to the component 
'adder' and does not extend to the signal declaration for x_sig and the 
like.

Author: Hartmut Scheffler (scheff)
Posted on:

Rate this post
0 useful
not useful
Hi Martin,

the error arises at the line

signal x_sig, y_sig, sum_sig : std_logic_vector(n-1 downto 0);

thats because your architecture doesn't know "n". "n" is defined in the 
component part only and will be forwarded to "adder" only. So add a 
"signal n : integer := 4;" before the signal definitions in the 
architecture and it will run.

Author: Martin (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi,
thanks for the quick reply. Unfortunately it didn't quite help. The 
syntax check tells me there is a syntax error in the line where I 
declare n and that n is still not declared in the line below. Seems 
strange to me...

Author: Hartmut Scheffler (scheff)
Posted on:

Rate this post
0 useful
not useful
Sorry I was too fast: The correct answer ist "constant n : integer := 
4;". A signal can't do the job.

Author: Martin (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi,
thanks a lot. It works!!!

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.