题解 | #多bit MUX同步器#
多bit MUX同步器
https://www.nowcoder.com/practice/30e355a04a454e16811112cb82af591e
`timescale 1ns/1ns module mux( input clk_a , input clk_b , input arstn , input brstn , input [3:0] data_in , input data_en , output reg [3:0] dataout ); // 脉冲使能方法(多中期路径)加握手协议 reg [2:0] reg_b; reg reg_a; reg [1:0] syn_a; always @(posedge clk_a or negedge arstn) begin if(~arstn) reg_a <= 1'b0; else reg_a <= ~syn_a[1] & data_en & (~data_en|~reg_a); if(!arstn) syn_a <= 2'd0; else syn_a <= {syn_a[0], reg_b[1]}; end always @(posedge clk_b or negedge brstn) begin if(~brstn) reg_b <= 3'd0; else reg_b <= {reg_b[1], reg_b[0], reg_a}; if(!brstn) dataout <= 4'd0; else if(reg_b[2]^reg_b[1]) dataout <= data_in; end endmodule
除了根据题目信息选择直接打拍同步外,也可以使用握手协议进行控制信号data_en的请求和认证,此时根据题意数据变化频率很低,故可以不用在A时钟域打拍同步。