1

Hello I have a question about Verilog grammar.

I am aware that @ is used with always usually.

but I want to do some action when a variable changes its value.

for example, I want to find out if switch is changing.

So, I tried if (@ posedge switch or negedge switch)

But this made an error.

Is there any other way to do this?

Thanks in advance

4
  • 1
    Please show us your error and if this is for synthesizable code Commented Dec 14, 2017 at 15:46
  • @close-voters In what way is this question less about programming than most other Verilog questions? And if you think that HDLs have nothing to do with programming, how come I find myself teaching, Factory Pattern, Subscriber Pattern, Singleton Pattern? Commented Dec 15, 2017 at 9:09
  • @MatthewTaylor , at least two of the close votes are for insufficient information; hence my up-vote on dave_59's comment. A MCVE would be useful. Commented Dec 15, 2017 at 17:05
  • Using another always was not what I intended since one variable can be changed in only one always statement. Thank you. Commented Dec 16, 2017 at 15:54

1 Answer 1

1

If you want to write a synchronous design (And you want to do that ;), you have to change state of all your signal on one clock edge (generally rising).

Then to detect switch edge you have to save state of switch value and compare it with actual on rising edge of clock.

always @(posedge clock)
   begin

       if (switch_old != switch)
             switch_edge <= 1'b1;
       else
             switch_edge <= 1'b0;

       switch_old  <= switch;
   end

You can't do what you ask in a synchronous design, then it can't be syntesizable reasonably.

Sign up to request clarification or add additional context in comments.

Comments

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.