题解 | #脉冲同步电路#
脉冲同步电路
http://www.nowcoder.com/practice/b7f37e6c55e24478aef4ec2d738bbf07
//反转电路+两级同步+边沿检测
`timescale 1ns/1ns
module pulse_detect(
input clk_fast ,
input clk_slow ,
input rst_n ,
input data_in ,
output dataout
);
reg sync_f;
always@(posedge clk_fast or negedge rst_n)
if(!rst_n)
sync_f <= 0;
else
sync_f <= data_in?~sync_f:sync_f;
reg sync1_s,sync2_s,sync3_s;
always @(posedge clk_slow or negedge rst_n)
if(!rst_n)
{sync1_s,sync2_s,sync3_s}<=0;
else
{sync1_s,sync2_s,sync3_s}<={sync_f,sync1_s,sync2_s};
assign dataout = sync2_s^sync3_s;
endmodule