I have a problem with an "always" block in Verilog. First let me present the code:
module syncRX(clk, signal, detect, output clk_1khz);
input clk, signal;
output reg [7:0] detect = 0;
//wire clk_1khz;
freq_div div(.clk(clk), .clk_1khz(clk_1khz));
always @(posedge signal, posedge clk_1khz)
begin
detect <= detect + 1;
end
endmodule // top
module freq_div(input clk, output reg clk_1khz);
reg [12:0] count = 0;
always @(posedge clk)
begin
if(count == 6000)
begin
clk_1khz <= ~clk_1khz;
count <= 0;
end
else
count <= count + 1;
end
endmodule
I got this error message (using Icestorm):
Executing PROC_DFF pass (convert process syncs to FFs).
Creating register for signal \freq_div.\clk_1khz' using process \freq_div.$proc$syncRX.v:22$4'.
created $dff cell $procdff$15' with positive edge clock.
Creating register for signal \freq_div.\count' using process \freq_div.$proc$syncRX.v:22$4'.
created $dff cell $procdff$16' with positive edge clock.
Creating register for signal \syncRX.\detect' using process \syncRX.$proc$syncRX.v:8$1'.
ERROR: Multiple edge sensitive events found for this signal!
make: *** [Makefile:44: syncRX.bin] Error 1
I could detect that the "always" block involved is:
always @(posedge signal, posedge clk_1khz)
begin
detect <= detect + 1;
end
becaise if change "always @(posedge signal, posedge clk_1khz)" for "always @(posedge signal)" works.
Also fails in that same way:
always @(posedge signal)
begin
detect <= detect + 1;
end
always @(posedge clk_1khz)
begin
detect <= detect + 1;
end
And the error disappears when comment the line "detect <= detect + 1;" in bought of cases. Then the error is related to the access to the "detect" counter register. I have not idea why I can not trigger this counter from two different signals, but in fact, I have to increase the counter in bought post edge signals (and I can figure out in my mind a very simple digital circuit doing this), I know that HDL dont allow synthesis of multiple driven register (handle register from many different always block), but in fact I can draw a OR Gate in my mind for do it, also there is many features can not be implemented without this practice, then should be a way to do in Verilog.
I add a schematic about that I have in mind: