When I am doing some development with Verilog and Vivado, I wrote some Verilog code as follows:
module min_rep_example_A(input clk, input rst_n, output reg[3:0] LED);
always @(posedge clk or negedge rst_n)
begin
if(rst_n)
begin
LED <= {LED[0], LED[3:1]};
end
else
begin
LED <= 4'b0000;
end
end
endmodule
But when I try to synthesize it, it reports this error:
[Synth 8-7213] Expression condition using operand 'rst_n' does not match with the corresponding edges used in event control"
and synthesis failed.
And expression with ? : operator is the same:
module min_rep_example_A(input clk, input rst_n, output reg[3:0] LED);
always @(posedge clk or negedge rst_n)
begin
LED <= rst_n? LED{LED[0], LED[3:1] : 4'b0000;
end
endmodule
If I change the rst_n to !rst_n, the Verilog code works as expected with no errors:
module min_rep_example_B(input clk, input rst_n, output reg[3:0] LED);
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
LED <= 4'b0000;
end
else
begin
LED <= {LED[0], LED[3:1]};
end
end
...
And so it is with ? : operator:
module min_rep_example_B(input clk, input rst_n, output reg[3:0] LED);
always @(posedge clk or negedge rst_n)
begin
LED <= (!rst_n)? 4'b0000 : LED{LED[0], LED[3:1];
end
endmodule
What is the reason and why rst_n usage reports synthesis error and !rst_n usage will work?
This is a minimal reproducible example. And because it is "minimal" reproducible example, I directly use "clk" as signal name, it may be slower and may not directly binding to hardware clk (such as 50MHz).