Results 1 to 3 of 3

Thread: Shift constant by variable amount

  1. #1
    Join Date
    May 2013
    Rep Power

    Default 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!


  2. #2
    Tricky is offline Moderator **Forum Master**
    Join Date
    Oct 2008
    Rep Power

    Default Re: Shift constant by variable amount

    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';
        Leds_w(i) <= '0';
      End if
    End loop;
    -- or you could do it in a process
    Process (counter)
      Leds_w <= (others => '0');
      Leds_w( to_integer (counter)) <= '1';
    End process;
    Last edited by Tricky; January 14th, 2017 at 09:01 AM.

  3. #3
    Join Date
    May 2013
    Rep Power

    Default Re: Shift constant by variable amount

    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!

Similar Threads

  1. converting a signed shift amount to unsigned
    By JenC in forum Verilog and System Verilog
    Replies: 2
    Last Post: August 22nd, 2013, 11:54 PM
  2. Replies: 1
    Last Post: March 17th, 2013, 03:07 AM
  3. variable length shift register needed
    By mrbietola in forum IP Discussion
    Replies: 1
    Last Post: July 6th, 2012, 07:23 AM
  4. variable or constant error
    By jasonkee111 in forum Quartus II and EDA Tools Discussion
    Replies: 2
    Last Post: January 21st, 2009, 06:21 AM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts