Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Represent what you need in diagram.
module pulse_rise(
input clk,
input rst,
input signal_a,
output signal_rise);
reg signal_reg1, signal_reg2;
wire signal_rise;
always @ (posedge clk, posedge rst) begin
if(rst) begin
signal_reg1 <= 1'b0;
signal_reg2 <= 1'b0;
end else begin
signal_reg1 <= signal_a;
signal_reg2 <= signal_reg1;
end
end
assign signal_rise = signal_reg1 & ~signal_reg2;
endmodule
always @ (*) begin
if((signal_reg1== 1'b1) && (signal_reg2 == 1'b0)) begin
signal_rise = 1'b1;
end else begin
signal_rise = 1'b0;
end
end
Sun_ray,
Simply replace assign statements with
Code:always @ (*) begin if((signal_reg1== 1'b1) && (signal_reg2 == 1'b0)) begin signal_rise = 1'b1; end else begin signal_rise = 1'b0; end end
@rca: signal_rise is indeed a pulse.
It turns out that the original question is not clear at all, because it doesn't mention the timing relation between clk and input signal.Here in your code, it will synthesize to two flops. Is it necessary to use two flipflops?
Here, one flipflop should be sufficient.
module pulsegenerateonposedge(
clk,
signal,
rst_output,
out
);
input clk,signal;
input rst_output;
output out;
reg reg1,reg2,reg3;
wire out;
assign out = reg2^reg3;
always @(posedge signal or negedge rst_output)
begin
if (rst_output == 1'b0)
reg1 <= 1'b0;
else
reg1 <= ~reg1;
end
always @(posedge clk or negedge rst_output)
begin
if(rst_output == 1'b0)
{reg3,reg2} <= 2'b00;
else
{reg3,reg2} <= {reg2,reg1};
end
endmodule
It turns out that the original question is not clear at all, because it doesn't mention the timing relation between clk and input signal.
In the general case (timing unrelated), you need three flip-flops to handle possible metastable events, two synchronizers and one edge differentiator.
I didn't yet consider the case that the input signal is smaller than a clock cycle. In this case, a toggle synchronizer would be suggested.
Use a code tag (# symbol in tool bar)sorry i don't know how to wrap the code like above, which has a scroll bar
Your code shows a classical toggle synchronizer.My code can only detect the pulses that are one clock away from each other. the signal drive the first flip flop,FF1, which toggles its output when signal has risedge. and then the output of the FF1 works as input of FF2, FF2 works as input of FF3, output= D_{ff2} xor D_{ff3};
The answer depends on the exact meaning of detect? Count the number of clock edges (up to a certain number), or detect the presence of at least one clock edge?I don't know how to detect random signal waveform, which i mean the timing distance between two risedges of the signal is less than one clock cycle.
anyone has idea?
Use a code tag (# symbol in tool bar)
Your code shows a classical toggle synchronizer.
The answer depends on the exact meaning of detect? Count the number of clock edges (up to a certain number), or detect the presence of at least one clock edge?
Counting edges can work with a gray encoded counter on the source clock domain. Detecting the presence of at least one edge requires some kind of handshake between both clock domains. Random signal waveforms must respect the minimum pulse width specification of the used logic family anyway.
can you recommend some articles about this(preferred :-D) or give more details.Counting edges can work with a gray encoded counter on the source clock domain. Detecting the presence of at least one edge requires some kind of handshake between both clock domains.
sorry for the confusion, how about counting the edges? is that what you mean in #13. you said "counting edge can work with a gray code counter....",I don't have literature at hand, I'm designing these things according to the respective requirements, or use stanadard IP like domain crossing FIFO where applicable.
Your requirement isn't clear yet, counting multiple pulses or just detect presence of >=1 pulse?