always @(posedge clk_i or negedge rst_n_i) begin
if(!rst_n_i) begin
flipflop <= 1'b0;
end else begin
if(pulse) begin
flipflop <= 1'b1;
end else begin
flipflop <= 1'b0;
end
end
end
this is a race condition of sorts, a violation of setup timing. pulse should not switch at the same time as clk.Consider the following piece of Verilog
Code:always @(posedge clk_i or negedge rst_n_i) begin if(!rst_n_i) begin flipflop <= 1'b0; end else begin if(pulse) begin flipflop <= 1'b1; end else begin flipflop <= 1'b0; end end end
The pulse occurs during the negative period of clk_i but the simulator (Questasim) still shoes that it was captured by the flipflop. Why is that and does this also work after synthesis/in hardware?.
My understanding was that at the positive edge and before the next positive edge there was no pulse so flipflop should be 0 too, but that does not seem to be the case.
View attachment 191942
I don't have anything to add but I see FvM reply makes sense. What puzzles me is why your pulse is so short to get this observation and how did you generate it. It is just a wrong pulse if your design is meant to be synchronised to clock.Consider the following piece of Verilog
Code:always @(posedge clk_i or negedge rst_n_i) begin if(!rst_n_i) begin flipflop <= 1'b0; end else begin if(pulse) begin flipflop <= 1'b1; end else begin flipflop <= 1'b0; end end end
The pulse occurs during the negative period of clk_i but the simulator (Questasim) still shoes that it was captured by the flipflop. Why is that and does this also work after synthesis/in hardware?.
My understanding was that at the positive edge and before the next positive edge there was no pulse so flipflop should be 0 too, but that does not seem to be the case.
View attachment 191942
reg [3:0] enable_block_delayed;
wire enable_block_pulse = enable_block & ~enable_block_delayed[0];
always @(posedge clk_i or negedge rst_n_i) begin
if(!rst_n_i) begin
enable_block_delayed[0] <= 1'b0;
end else begin
if(enable_block) begin
enable_block_delayed[0] <= 1'b1;
end else begin
enable_block_delayed[0] <= 1'b0;
end
end
end
always @(posedge clk_i or negedge rst_n_i) begin
if(!rst_n_i) begin
enable_block_delayed[1] <= 1'b0;
end else begin
if(enable_block_pulse) begin
enable_block_delayed[1] <= 1'b1;
end else begin
enable_block_delayed[1] <= 1'b0;
end
end
end
What do you mean "it COULD be phase shifted"? Either it's synchronous or its not.The input enable_block is from a slower clock domain (4MHz). This slower clock is generated from the 24MHz clock but it could be phase shifted
My bad. This is what seems to be the issue with my understanding. I thought a clock can be synchronous to another and can be delayed and I set up my testbench this way.What do you mean "it COULD be phase shifted"? Either it's synchronous or its not.
yes, it can be phase-shifted AND synchronous. But when you said it COULD be phase-shifted, that implies an ambiguity that is not present in synchronous systems. Words matter.My bad. This is what seems to be the issue with my understanding. I thought a clock can be synchronous to another and can be delayed and I set up my testbench this way.
Both clocks have fixed relation, but clock edge of slower clock is delayed, domain crossing signals from fast to slow clock need additional sync measures.My understanding is since the slower clock is generated from the fast clock (divided) I don't have to worry about synchronization
I don't see ambiguity in the shown waveform, as stated the behaviour is expectable. I don't however understand how "pulse" is generated. Is the signal combining posedge and negedge triggered registers? Can't recognize if it's a "proper way" (meeting timing constraints).What would be a proper way to generate a pulse in a faster clock domain from a signal coming from a slower clock domain and avoid this kind of ambiguity?
"pulse" is "enable_block_pulse" in the RTL I provided in post#6. I was generating it based on a testbench signal "enable_block" as shown in the RTL above. In my testbenchI don't however understand how "pulse" is generated. Is the signal combining posedge and negedge triggered registers? Can't recognize if it's a "proper way" (meeting timing constraints).
#10000
@(posedge clk_4)
@(posedge clk_4)
enable_block = 1'b1
@(posedge clk_4)
enable_block = 1'b0
#10000
@(posedge clk_4)
@(posedge clk_4)
enable_block = 1'b1
@(posedge clk_4)
enable_block = 1'b0
apologies if what I did or what I asked was stupid. I understood a few things much better and got to clear a few misconceptions from reading everyone's responses. Thank youThis is another thread I just need to walk away from…
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?