题解 | #脉冲同步器(快到慢)#
脉冲同步器(快到慢)
http://www.nowcoder.com/practice/9f7c92635b5f49579e8e38fd8c8450d7
`timescale 100ps/100ps
module pulse_detect(
input clka ,
input clkb ,
input rst_n ,
input sig_a ,
output wire sig_b
);
reg trigger;
reg syn_1;
reg syn_2;
reg syn_3;
always@(posedge clka or negedge rst_n) begin
if(!rst_n) begin
trigger<=1'b0;
end
else if(sig_a) begin
trigger<=~trigger;
end
else begin
trigger<=trigger;
end
end
always@(posedge clkb or negedge rst_n) begin
if(!rst_n) begin
syn_1<=1'b0;
syn_2<=1'b0;
syn_3<=1'b0;
end
else begin
syn_1<=trigger;
syn_2<=syn_1;
syn_3<=syn_2;
end
end
assign sig_b=syn_2^syn_3;
endmodule
module pulse_detect(
input clka ,
input clkb ,
input rst_n ,
input sig_a ,
output wire sig_b
);
reg trigger;
reg syn_1;
reg syn_2;
reg syn_3;
always@(posedge clka or negedge rst_n) begin
if(!rst_n) begin
trigger<=1'b0;
end
else if(sig_a) begin
trigger<=~trigger;
end
else begin
trigger<=trigger;
end
end
always@(posedge clkb or negedge rst_n) begin
if(!rst_n) begin
syn_1<=1'b0;
syn_2<=1'b0;
syn_3<=1'b0;
end
else begin
syn_1<=trigger;
syn_2<=syn_1;
syn_3<=syn_2;
end
end
assign sig_b=syn_2^syn_3;
endmodule