Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

Shift constant by variable amount

For some reason, I can't get this to work. I want to logically shift left the 8-bit number 1 (x"01") by a variable amount (named counter between 0 and 7) and store as an inverted std_logic_vector. Nothing I try is working with the compiler.

None of these work and I've tried many additional variants and conversions:

leds_w <= NOT (STD_LOGIC_VECTOR(2 ** counter));

leds_w <= NOT (STD_LOGIC_VECTOR(1 SLL TO_INTEGER(counter)));

leds_w <= NOT (STD_LOGIC_VECTOR(shift_left(x"01", counter)));

I have 1164 and numeric_std libraries referenced. counter is currently type unsigned, but I can change that if necessary. Help!

Steve

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The are problems with all 3, because you have type errors in all 3.

    I don't think you want to shift 1 to the left at all. Just connect the output to 2**CNT. You just want

    
    Leds_w <= std_logic_vector( to_unsigned( 2**counter, leds_w'length));
    --Or use a for loop
    For i in leds_w'range loop
      If counter = i then
        Leds_w(i) <= '1';
      Else
        Leds_w(i) <= '0';
      End if
    End loop;
    -- or you could do it in a process
    Process (counter)
    Begin
      Leds_w <= (others => '0');
      Leds_w( to_integer (counter)) <= '1';
    End process;
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Well, I still kept getting errors about **, so I put in the counter-sensitive process solution, inverting the values since I need it active low for LEDs. It seems to work! Thanks for the help!