Reputation: 292
This code fails to compile and gives the error as in the title at the "if(overflow)" line.
always @(posedge clk or negedge overflow) begin
if(overflow)
count_posedge = count_posedge + 1;
else
count_posedge = 0;
end
I've somewhere on the internet that I must change it like this:
always @(posedge clk or negedge overflow) begin
if(~overflow)
count_posedge = 0;
else
count_posedge = count_posedge + 1;
end
...and it works perfectly.
From my understanding, the 2 code should behave the same. What's the problem with the first one?
Upvotes: 7
Views: 13753
Reputation: 19112
This is more likely an issue with your synthesizer then your simulator. The likely problem is that the first code does not match any of it's templates for a synchronous flip-flop with asynchronous reset.
The common coding practice is to assign your reset logic before any other logic. This coding practice has been around for decades. I assume the rational behind this particular coding practice stems from:
In your case, your synthesizer is doing a lint check and has determined your code is not following the conventional coding practices. The creator of your synthesizer has decided to only support the common coding structure and there is little incentive to change.
FYI: you should be assigning synchronous logic with non-blocking assignments (<=
). Blocking assignments (=
) should be used for combinatonal logic. If you do not follow proper coding practices you increase the risk of introducing race-conditions, RTL vs gate mismatch, and other bugs.
Upvotes: 5