2

I have a std_logic_vector and I need to know when some changes occur on it. So far I wrote this:

process (cp, l1)
begin
    if rising_edge(cp) then
        rL1 <= l1;
    end if;
end process;
tickL1 <= rL1 xor l1;

rL1 is delayed version of l1, and l1 is the std_logic_vector I'm checking for changes. The problem is that xor returns std_logic_vector, but I need just 0 or 1. How can I get that?

2
  • 1
    This is not entirely clear. Do you want to know when it's changing or what changes? Commented Apr 28, 2012 at 15:01
  • Just when something changes, I don't care what changes. Commented Apr 28, 2012 at 15:09

3 Answers 3

9

Why has everyone got an obsession with XOR?

changed <= '0' when rL1 = l1 else '1';
Sign up to request clarification or add additional context in comments.

4 Comments

Hahah thx :D I tried just "changed <= rL1 = l1" but that didn't work because = returns boolean and not std_logic. Also I forgot about "when" :)
Won't such implementation lead to frequency lose and increasing of source usage comparing to xor implementation?
@AlehDouhi what do you think an equality comparison will synthesise to? Probably an XOR and an OR reduce. So you'll probably get the same thing, but you might get some smaller, faster method that you hadn't thought of. Rule 1 of readable code, say what you mean and only optimise when necessary. Rule 1 of fast code, say what you mean and don't limit the compiler/synthesiser into one (and only one) implementation.
Don't know, probably AND, NOT, comparators and MUX :) Sorry, just kidding :) Thank you for explanation!
3

You can use

change <= or_reduce(tickL1)

or

change <= or_reduce(rL1 xor l1);

Which OR's all signals of the result together, so if any of these is 1 the signal change will also be 1.

Edit: All of these reduce functions are in ieee.std_logic_misc.all

2 Comments

When I use or_reduce I get "Undefined symbol 'or_reduce'". Can you tell me what should I include ?
You have to use ieee.std_logic_misc.all.
0

You can try:

process (cp, l1)
begin
    if rising_edge(cp) then
        rL1 <= l1;
    end if;
end process;
changed <= '0' when (rL1 xor l1) = (others => '0') else '1';

In this case changed is a single bit.

I don't really remember if you can use the others operator inside a condition... that's the reason I said "you can TRY"... So, let me know if it works for you....

1 Comment

Unfortunatel this doesn't work (Error: Can not determine the "others" values in aggregate. (LRM 7.3.2.2)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.