0

I am new to VHDL and I wanted to ask that what generic term could I use If i wanted to write any size of input vector which could be developed?

GENERIC (n1 : integer); 
x:IN BIT_VECTOR(n1-1 downto 0);

Is that a correct example?

JOHN
  • 33
  • 6

3 Answers3

1

According to the " Paebbels" comment I edit this answer :

Every time you want to synthesize your code, synthesis tool should know about the size of parameters you used, Otherwise what exactly you want to synthesize ?!!! (what hardware ?!)

If you want to synthesize your top module code which contains a generic parameter in it's own entity, you can assign it with a default value such as the following code :

ENTITY ... IS
    GENERIC(n1 : INTEGER := 8);
    PORT(
         -- use generic parameter
    );
END ENTITY;

Also you can use the generic parameter inside architecture ( size of signals, index of loops, ... ).

Amir
  • 507
  • 3
  • 12
  • Could you please explain more? so the largest output could be infinite? and `GENERIC (n1 : integer:=3 ); x:IN BIT_VECTOR(n1-1 downto 0); ai:IN BIT_VECTOR (n1-2 downto0)` is not correct? – – JOHN Dec 13 '14 at 20:05
  • No, n1 is an integer and the maximum number of integers is 2^31-1. Then you can't use any initial value for n1. Also you can't use the large numbers for n1, because you used it as the size of inputs, but we don't have enough ports on FPGA. In the example of your comment, the range of x is (2 downto 0). The statements are correct, but use them in the right place as I mentioned in my answer. – Amir Dec 13 '14 at 20:29
  • Actually the size of ports (in entity) depends on where you want to use them. If you map them directly on fpga ports, then you can't use large numbers. But as "David Koontz" mentioned, maybe you want to use your code inside other designs (creating instances). It depends on your code ... – Amir Dec 13 '14 at 21:29
  • 1
    @Amir it's not needed to assign every generic value with a default value, but as you mentioned, it's useful. Pros for setting a default value: The module is synthesizable without setting special synthesize options, users of this component see a recommended default value, the generic map can be short but also flexible for advanced parameters. Pros for not settting a default value: if you want a user to think about the provided value. – Paebbels Dec 14 '14 at 02:06
1

Your generic has no default value visible.

Your declaration for x is incomplete. It appears to be an entity declarative item with a mode while you don't have a port declaration.

This VHDL code is syntactically and semantically valid:

entity foo is
    generic ( n1:   integer);
    port (
        x: in   bit_vector(n1-1 downto 0)
    );
end entity;

architecture fum of foo is

begin

end architecture;

It will analyze. It can't be elaborated without the value of n1 being known:

entity foo_tb is
    constant N_1: integer := 4;
end entity;

architecture fum of foo_tb is
    signal x:  bit_vector (N_1-1 downto 0);
begin
DUT:
    entity work.foo
    generic map (n1 => N_1)
    port map ( x => x);
end architecture;

Entity foo by itself can't be the top level of an elaborated model because n1 isn't defined for elaboration.

Entity foo_tb can be elaborated, it uses the constant N_1 to supply a value to n1.

foo_tb can even be simulated, but it will exit immediately because there are no pending signal assignments after initialization.

Neither foo nor foo_tb can be synthesize. foo_tb because it has no ports and any logic in it's design hierarchy would be optimized away as unused. foo because it only has an output and is at best a constant.

If foo had multiple ports, with outputs depending on inputs it would be eligible for synthesis or simulation as long as the generic was defined for elaboration.

(And the moral here is to use a Minimal, Complete, and Verifiable example so someone doesn't have to wave their hands around it's shortcomings).

Community
  • 1
  • 1
1

You can use every term, as far as it's result does not exceed the BIT_VECTORS's array range.

BIT_VECTOR definition: type BIT_VECTOR is array (NATURAL range <>) of BIT;
So your term can have results from 0 to 2**32 - 1

Term examples:

  • 4*n1 - 1 downto 0
  • n1/4 + 8 downto 0
  • log2ceilnz(n1) - 1 downto 0
  • 2**n1 - 1 downto 0
Paebbels
  • 15,573
  • 13
  • 70
  • 139
  • Could you please explain more? so the largest output could be infinite? and `GENERIC (n1 : integer:=3 );` `x:IN BIT_VECTOR(n1-1 downto 0);` `ai:IN BIT_VECTOR (n1-2 downto0)` is not correct? – JOHN Dec 13 '14 at 20:00
  • I get this error following your code: Error (10528): VHDL error at work.vhd(38): value "-2147483648" is outside the target constraint range (-2147483647 to 2147483647) – JOHN Dec 13 '14 at 20:10
  • Theoretically, n1 could be infinite, but there are two limits: (1) a generic parameter must have a type and the biggest one is integer (-2^31 .. +2^31-1), so n1 is less then 2^31; (2) your port x is a BIT_VECTOR which is constrained to use a range of NATURAL (positive INTEGER inclusing zero: 0 .. 2^31-1) so all calculations/terms with n1 must not exceed 2^31-1 otherwise all terms are valid. – Paebbels Dec 14 '14 at 08:39