Events on individual bits of a vector

Discussion in 'VHDL' started by Hybr1dz, Apr 2, 2008.

  1. Hybr1dz

    Hybr1dz

    Joined:
    Feb 27, 2008
    Messages:
    6
    I want to test for events on individual bits of a std_logic_vector signal... something like this:

    Assume vec is signal vec : std_logic_vector(63 downto 0)...

    Code:
    for i in 63 downto 0 loop
    if (vec(i)'event) then
    [COLOR="SeaGreen"]--do something[/COLOR]
    end if;
    end loop;
    
    Unfortunately you can't do this. I get the compile error:

    Attribute "event" requires a static signal prefix.

    Is there a way to check individual bits of a signal vector for an event?
     
    Hybr1dz, Apr 2, 2008
    #1
    1. Advertising

  2. Hybr1dz

    gzidude

    Joined:
    Feb 17, 2008
    Messages:
    19
    this might work

    Since you need to check 64 bits for events which can occur at any time, you need to generate concurrent hardware to check each one. This code might work:

    Code:
    for i in vec'range generate
    	if (vec(i)'event) then
    		--do something
    	end if;
    end generate;
    Keep in mind that whatever you put where it says "--do something" will be generated in hardware 64 times.

    On second thought, you know what else you can do? To save on hardware you could do this:

    Code:
    --
    signal check : bit := '0';
    --
    check <= vec(63) OR vec(62) OR vec(61) OR vec(60) OR vec(59) OR vec(58) OR vec(57) OR vec(56) OR vec(55) OR vec(54) OR 
             vec(53) OR vec(52) OR vec(51) OR vec(50) OR vec(49) OR vec(48) OR vec(47) OR vec(46) OR vec(45) OR vec(44) OR 
             vec(43) OR vec(42) OR vec(41) OR vec(40) OR vec(39) OR vec(38) OR vec(37) OR vec(36) OR vec(35) OR vec(34) OR 
             vec(33) OR vec(32) OR vec(31) OR vec(30) OR vec(29) OR vec(28) OR vec(27) OR vec(26) OR vec(25) OR vec(24) OR 
             vec(23) OR vec(22) OR vec(21) OR vec(20) OR vec(19) OR vec(18) OR vec(17) OR vec(16) OR vec(15) OR vec(14) OR 
             vec(13) OR vec(12) OR vec(11) OR vec(10) OR vec(9)  OR vec(8)  OR vec(7)  OR vec(6)  OR vec(5)  OR vec(4)  OR 
             vec(3)  OR vec(2)  OR vec(1)  OR vec(0);
    
    if (check 'event) then
    	--do something
    end if;
    
    ..that's what I would do. It'll save a lot more hardware space. Your code is uglier, but you get better results
     
    Last edited: Apr 2, 2008
    gzidude, Apr 2, 2008
    #2
    1. Advertising

  3. Hybr1dz

    Hybr1dz

    Joined:
    Feb 27, 2008
    Messages:
    6
    hmmm... interesting. I didn't know you can use generate in that manner (I only used it to for entities).

    But are you sure that works? I just tried it and I get an "Illegal concurrent statement" error. I was supposed to check for events in my testbench but I decided to use your code inside my entity (where I also use several generate statements) and it gives me that error.
     
    Hybr1dz, Apr 2, 2008
    #3
  4. Hybr1dz

    gzidude

    Joined:
    Feb 17, 2008
    Messages:
    19
    Sorry about that. I just modified my previous post. Perhaps that'll help. I've been away from VHDL for a while and have gotten pretty rusty.
     
    Last edited: Apr 2, 2008
    gzidude, Apr 2, 2008
    #4
  5. Hybr1dz

    Hybr1dz

    Joined:
    Feb 27, 2008
    Messages:
    6
    Thanks for your input! I really appreciate it.

    Unfortunately, there was something I forgot to mention. That "do something" actually needs to know which bit has that event. To do something like this:

    Code:
    if (vec(i)'event) then
           another_vec(i) := '1';
    else
           another_vec(i) := '0';
    end if;
    
    And actually, instead of having that vec(63) OR .... OR vec(0) concurrent signal assignment. You actually can do the following:

    Code:
    if(vec'event) then
         --do something
    end if;
    
    Which should do the same thing.

    vec'event compiles. vec(i)'event does not. So my problem is that I actually need to know which bit in the vector has an event.

    Thanks again for your efforts though!
     
    Hybr1dz, Apr 2, 2008
    #5
  6. Hybr1dz

    gzidude

    Joined:
    Feb 17, 2008
    Messages:
    19
    Dang! I really have been away.
     
    gzidude, Apr 2, 2008
    #6
  7. Hybr1dz

    Hybr1dz

    Joined:
    Feb 27, 2008
    Messages:
    6
    I have a basic solution going... not really elegant. Basically I have another variable that stores the previous values of 'vec' and XORs them with current values of vec.

    Code:
    -- assume variable prev_vec_vals : std_logic_vector (63 downto 0) := (others => '0');
    -- assume variable events : boolean := (others => false);
    -- assume signal vec : std_logic_vector (63 downto 0);
    
    for i in vec'range loop
         if ( vec(i) xor prev_vec_vals(i) = '1') then
              events(i) := true;
              prev_vec_vals(i) := vec(i);
         end if;
    end loop;
    
    
    Then I would examine the events vector to see which bits had an event. If I were to use this in a looping testbench, then that events vector must be cleared before each iteration.

    It seems to be working fine right now. Perhaps someone who ran into my problem could find this useful.
     
    Hybr1dz, Apr 2, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allerdyce.John@gmail.com
    Replies:
    8
    Views:
    1,939
    Csaba
    Feb 18, 2006
  2. benn
    Replies:
    5
    Views:
    529
    Joseph Kesselman
    Mar 20, 2008
  3. harijay
    Replies:
    4
    Views:
    458
    harijay
    Feb 24, 2009
  4. Daku
    Replies:
    6
    Views:
    6,674
  5. googler

    Accessing individual bits in a number

    googler, May 19, 2008, in forum: Perl Misc
    Replies:
    0
    Views:
    110
    googler
    May 19, 2008
Loading...

Share This Page