by Taniwha · 7y ago · 0 comments
And you are mixing <= and = in the same code (look in execute() ) this should never happen.
In general use <= in places that are gated by an "always @(posedge clk)" and = in things gated by "always @(*)"
(with the exception that it's OK to assign a temp variable in a clocked always with '=' provided its lifetime doesn't extend past the block's execution (your use of SKIP_FLAG is an example of this being done correctly)
But it is ok to do something like:
cnt <= cnt + 1;
if (cnt > 100) cnt <= 0;
If not, how else should something like this be done?
Thanks for your help, I'm finding HDL to be anything but easy. :-)
if (cnt > 100)
cnt <= 0;
else
cnt <= cnt + 1;Essentially what happens is:
tmp_cnt1 = cnt + 1;
if (cnt > 100) tmp_cnt2 = 0;
some time later: cnt = tmp_cnt1;
and after that (if cnt >100) cnt = tmp_cnt2;
Better to say: if (cnt >= 99) {
cnt <= 0;
} else {
cnt <= cnt+1;
} always @(posedge clk)
r <= v;
and in some more complex cases where r is only set once in one always statement (or once in any path through an always statement) - but something like: always @(*)
r <= c;
is a nightmare that essentially means that r can have many changes scheduled in the same instant of time, more importantly it's a number of changes that can't be determined at compile time (could be 1000s of transitions) - resulting in code that's mallocing space to store all those changes - simulation can slow down if you use <= in a non-clocked place because the behaviour can't be determined staticallyAlso using <= a smart compiler can merge multiple always statements:
always @(posedge clk)
r1 <= c1;
always @(posedge clk)
r2 <= c2;
......
into a single always @(posedge clk) {
r1 <= c1;
r2 <= c2;
......
}
behind your back, effectively converting 2*N simulation events into 2 (a very good thing)