题解 | #脉冲同步器(快到慢)#
脉冲同步器(快到慢)
https://www.nowcoder.com/practice/9f7c92635b5f49579e8e38fd8c8450d7
`timescale 100ps/100ps
module pulse_detect(
input clka ,
input clkb ,
input rst_n ,
input sig_a ,
output sig_b
);
//快时钟->慢时钟的跨时钟域处理,不能简单的打两拍。脉冲同步器步骤如下:
//1、首先将快时钟下的脉冲信号转换为边沿信号
//2、使用转换的边沿信号在慢时钟域中打三拍
//3、使用reg2和reg3进行转换为脉冲信号即可
//1、将快时钟下的脉冲信号sig_a转换为边沿信号tmp
reg tmp; //边沿信号
always@(posedge clka or negedge rst_n)
begin
if(!rst_n)
tmp <= 0;
else if(sig_a)
tmp <= ~tmp;
else
tmp <= tmp;
end
//2、使用边沿信号tmp在慢时钟域打三拍
reg tmp_reg1,tmp_reg2,tmp_reg3;
always@(posedge clkb or negedge rst_n)
begin
if(!rst_n)
begin
tmp_reg1 <= 0;
tmp_reg2 <= 0;
tmp_reg3 <= 0;
end
else begin
tmp_reg1 <= tmp;
tmp_reg2 <= tmp_reg1;
tmp_reg3 <= tmp_reg2;
end
end
//3、使用tmp_reg2 和tmp_reg3进行异或,将边沿信号最后转换为脉冲信号
assign sig_b = tmp_reg2 ^ tmp_reg3;
endmodule
腾讯云智研发成长空间 258人发布
查看5道真题和解析