题解 | #脉冲同步器(快到慢)#

脉冲同步器(快到慢)

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
);
    
reg data_fast_reg;
reg data_fast_reg_slow_1;
reg data_fast_reg_slow_2;
reg data_fast_reg_slow_3;

always @(posedge clka or negedge rst_n)begin
	if(rst_n == 1'b0)
		data_fast_reg <= 0;
	else if(sig_a == 1'b1)
		data_fast_reg <= ~data_fast_reg;
	else 
		data_fast_reg <= data_fast_reg;
end

always @(posedge clkb or negedge rst_n)begin
	if(rst_n == 1'b0)begin
		data_fast_reg_slow_1 <= 0;
		data_fast_reg_slow_2 <= 0;
		data_fast_reg_slow_3 <= 0;
	end
	else begin
		data_fast_reg_slow_1 <= data_fast_reg;
		data_fast_reg_slow_2 <= data_fast_reg_slow_1;
		data_fast_reg_slow_3 <= data_fast_reg_slow_2;
	end
end	

assign sig_b = data_fast_reg_slow_2 ^ data_fast_reg_slow_3;






endmodule

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-27 10:52
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务