4

What I want to do:

entity FIRfilter is
   generic (
      NTAPS : integer );
   port (
      -- ...
      h : in array(0 to NTAPS-1) of std_logic_vector(15 downto 0) );
end FIRfitler;

But the syntax on the line with h is not correct.

This question is similar: How to specify an integer array as generic in VHDL? But that doesn't get me the generic number of taps when instantiating. Is this even possible?

1 Answer 1

6
+100

If you declare an unconstrained array type in a package, then you can constrain the array based on a generic, as shown in the code below:

library ieee; use ieee.std_logic_1164.all;

package FIRfilter_pkg is
  type x_t is array(natural range <>) of std_logic_vector(15 downto 0);
end package;


library ieee; use ieee.std_logic_1164.all;
library work; use work.FIRfilter_pkg.all;

entity FIRfilter is
   generic (
      NTAPS : integer );
   port (
     x : in x_t(0 to NTAPS-1);
     z : out std_logic_vector(15 downto 0) );  -- For simple example below
end FIRfilter;


library ieee; use ieee.numeric_std.all;

architecture syn of FIRfilter is
begin
  z <= std_logic_vector(unsigned(x(0)) + unsigned(x(1)));  -- Usage example
end architecture;
Sign up to request clarification or add additional context in comments.

6 Comments

A port declaration may contain an interface signal declaration where following the mode (in) a subtype indication is provided consisting of an optional resolution function declaration (none), a type mark (x_t) and a constraint, either range or index (shown). The operative idea is that an interface signal declaration declares a named subtype not a type. An entity declarative part declaration for a type can't be rearward referenced so the type is declared in a package.
Perfect. I'm new to VHDL and hadn't ever created an unconstrained type before. That all makes perfect sense, and David's addition helped as well.
Good to hear; if you could use a book, then take a look at The Designer's Guide to VHDL, and you may need no other ;-)
@MortenZdk I actually own that book (happy-face and embarrassed-face). I had looked through some of the parts on array declarations, but apparently nothing clicked for me. Thanks for clearing this up. I'll be looking through the book again.
What if you don't have either dimension fixed ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.