I want to know if we assign something to a register ( or do anything else ) in a specific clock cycle, this assignment is performed in the current clock cycle or the next cycle? (Setting: Xilinx , Spartan-3. coded by Verilog via ISE Webpack)
Example:
always @(negedge GCLK)
foo<= bar; // foo is equal to bar in this cycle or next?
Best Answer
For simple cases where there is nothing going on elsewhere in your code to cause
bar
to change simultaneously withGCLK
, this block says, when a negative-going edge is seen on GCLK, "immediately" change the value offoo
to whateverbar
is at that instant."Immediately" means something like one simulation tick after the negative edge arrived.
This means that any other tranisitions that happen on the same negative edge of GCLK and depend on the value of
foo
will see the old value offoo
. Butfoo
will have the new value starting right away until the next negative edge of GCLK.Edit in reply to comments,
In the simulator, yes. In real life you need to check propagation delays and setup and hold times to be sure.
No, as mentioned before, any other tranisitions that happen on the same negative edge of GCLK and depend on the value of foo will see the old value of foo.
If you want the other behavior you can use blocking assignment:
Modern synthesis tools should be able to compile this correctly but old tools might not be able to. What the modern tool will do is simply translate this to
and compile that. Since I learned Verilog before this behavior was reliable I find it less familiar to read the code with blocking assignments.
I'm not quite clear what you mean by this. What a blocking assignment does (in the simulator) is prevent the next statement from executing until after it is complete. Both types of assignment are immediate, but the blocking assingment causes the next statement to be delayed.
For small delays in simulation you can just use delay events
For small delays in synthesized code, you'd better be sure the hardware can actually do what you're asking for.