by Taniwha · 7y ago · 0 comments
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)These days I build embedded stuff, living on the hardware/software edge I still get to make the software/hardware tradeoffs that others often can't do