VHDL: use the length of an integer generic to determine number of select lines

前端 未结 5 1567
-上瘾入骨i
-上瘾入骨i 2021-02-08 08:34

I\'m trying to create a reusable barrel shifter; it takes an input array of bits and shifts them a certain number of positions (determined by another input). I want to parameter

5条回答
  •  天涯浪人
    2021-02-08 09:15

    You can instead of inputting the NUMBITS value as 8, input it as 2 (log2(8)), then retype as below to get around the problem, your generic just won't be as clean but it is scale-able.

    entity BarrelShifter is
    
    generic ( NUMBITS : integer :=2);                                                   
    Port    ( INPUT     : in   std_logic_vector (((2**Nbits)-1) downto 0);                
              OUTPUT    : out  std_logic_vector (((2**Nbits)-1) downto 0);                
              SHIFT_CNT : in   std_logic_vector ((NUMBITS-1) downto 0)                 
            );                                                               
    end BarrelShifter;
    

提交回复
热议问题