题意整理
本题要求实现跨时钟域的脉冲转换电路,将快时钟域的脉冲转换到慢时钟域。题目描述中已指示,无需担心快时钟域的脉冲间隔太近问题
题解主体
实现电路如下。
上图中最左端的数据选择器和寄存器,组成了快时钟域下的翻转电路;中间的两个寄存器是两级同步器;最后一个寄存器和异或门组成边沿检测电路。
根据电路设计,Verilog代码描述如下:
reg Q_fast; always @(posedge clk_fast or negedge rst_n) begin if(~rst_n) begin Q_fast <= 'd0; end else if(data_in)begin Q_fast <= ~Q_fast; end else if(~data_in)begin Q_fast <= Q_fast; end end reg Q_buff0; reg Q_buff1; always @(posedge clk_slow or negedge rst_n) begin if(~rst_n) begin Q_buff0 <= 'd0; Q_buff1 <= 'd0; end else begin Q_buff0 <= Q_fast; Q_buff1 <= Q_buff0; end end reg Q_slow; always @(posedge clk_slow or negedge rst_n) begin if(~rst_n) begin Q_slow <= 'd0; end else begin Q_slow <= Q_buff1; end end assign dataout = Q_buff1 ^ Q_slow;
参考答案
`timescale 1ns/1ns module pulse_detect( input clk_fast , input clk_slow , input rst_n , input data_in , output dataout ); reg Q_fast; always @(posedge clk_fast or negedge rst_n) begin if(~rst_n) begin Q_fast <= 'd0; end else if(data_in)begin Q_fast <= ~Q_fast; end else if(~data_in)begin Q_fast <= Q_fast; end end reg Q_buff0; reg Q_buff1; always @(posedge clk_slow or negedge rst_n) begin if(~rst_n) begin Q_buff0 <= 'd0; Q_buff1 <= 'd0; end else begin Q_buff0 <= Q_fast; Q_buff1 <= Q_buff0; end end reg Q_slow; always @(posedge clk_slow or negedge rst_n) begin if(~rst_n) begin Q_slow <= 'd0; end else begin Q_slow <= Q_buff1; end end assign dataout = Q_buff1 ^ Q_slow; endmodule