The accepted answer to this question notes that "every reg variable can only be assigned to in at most one always statement". It's clear that in a lot of cases assigning a reg to multiple always blocks is meaningless. However, it's seems that there could be hardware-meaning instances of a reg in different always blocks. For example, what if a same reg is assigned to always @(posedge clk1) , always @(posedge clk2) where clk1 , clk2 never beat of the same time? There would be no race-condition. Why is there a "hard rule" concerning reg s in different always blocks?
asked Apr 10, 2012 at 8:37 Randomblue Randomblue 11.1k 31 31 gold badges 107 107 silver badges 178 178 bronze badgesFor example, what if a same reg is assigned to always @(posedge clk1), always @(posedge clk2) where clk1, clk2 never beat of the same time? There would be no race-condition.
The case you mention will not be synthesizable. The flip-flop that implements the reg can only be clocked from one source.
As an aside, I'd like to clarify that the rule about reg s having affinity to always blocks affects synthesizability, not validity. Software simulator will handle assignments from different always blocks without any problems.
answered Apr 10, 2012 at 8:54 3,236 2 2 gold badges 18 18 silver badges 20 20 bronze badges \$\begingroup\$ What about always @(posedge clk), always @(negedge clk) ? \$\endgroup\$ Commented Apr 10, 2012 at 10:10\$\begingroup\$ @Rocketmagnet, that's the same problem. Flip-flops react to one of the edges. \$\endgroup\$
Commented Apr 10, 2012 at 10:18\$\begingroup\$ DDR flip-flops (available in IO blocks of many FPGAs) react to both edges. But even then, there's only one input, so it doesn't make sense to have the logic split up into multiple blocks. always @(posedge clk or negedge clk) or just always @clk would make sense. Even so, I'm not sure if any tools will synthesize those -- I have always explicitly instantiated the library block instead. \$\endgroup\$
Commented Apr 10, 2012 at 15:36\$\begingroup\$ @ThePhoton, that is my experience as well with Altera FPGAs: special peripherals (including DDR transceivers) are black-box modules, which can be instantiated into your design. \$\endgroup\$
Commented Apr 10, 2012 at 15:51 \$\begingroup\$Although you may know that two clock edges will never arrive simultaneously, the synthesizer can't assume that. It's possible to construct a reasonable-cost circuit which will latch D1 on the rising edge of C1, and D2 on the rising edge of C2, provided that rising edges of C1 and C2 are always sufficiently separated. On the other hand, a pair of "always" blocks would indicate that such a circuit should also correctly and without glitches handle the case where the latch start out low, D1 and D2 are both high, and C1 and C2 arrive in arbitrary sequence, with arbitrary time between them. Even if a synthesizer could generate such a thing, the circuit cost would be more than double what would be needed to handle the case where C1 and C2 are always disjoint.
answered Apr 10, 2012 at 16:12 47.1k 3 3 gold badges 88 88 silver badges 148 148 bronze badgesTo subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2024 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2024.9.4.14806