nichollsg
nichollsg

Reputation: 390

Initialize constant of varying length to something other than all zeros/ones

I am designing a simple LFSR with a variable polynomial for a randomizer. The lfsr length is being defined as a generic. I need to initialize the starting value constant as something other than zeros/ones. I've found the answer to this before, but I can't seem to find the answer again. Here is what I'm trying to do:

entity GaloisLfsr is
    generic
    (
        g_LFSR_LENGTH : integer := 5
    );
  ...
end entity GaloisLfsr;

architecture zGaloisLfsr of GaloisLfsr is
    constant c_INITIAL : std_logic_vector((g_LFSR_LENGTH - 1) downto 0) := ((others => '0'), '1');

What is the proper syntax for defining a constant with varying size to something that a pure '(others => '0')' can't capture?

Upvotes: 1

Views: 1530

Answers (2)

Vinay Madapura
Vinay Madapura

Reputation: 327

Assuming one would like to initialize the 5-bit constant c_INITIAL to "00001", then the declaration of the constant would be:

constant c_INITIAL : std_logic_vector((g_LFSR_LENGTH - 1) downto 1) := ((others => '0'), 0 => '1');

Upvotes: 1

Qermit
Qermit

Reputation: 11

You may convert natural/integer to vector

use IEEE.NUMERIC_STD.ALL;
...
constant c_INITIAL : std_logic_vector((g_LFSR_LENGTH - 1) downto 0) := std_logic_vector(to_unsigned(g_polynomial , g_LFSR_LENGTH));

Upvotes: 0

Related Questions