题解 | #时钟切换#

时钟切换

https://www.nowcoder.com/practice/1de5e9bf749244cb8e5908626cc36d36

`timescale 1ns/1ns

module huawei6(
	input wire clk0  ,
	input wire clk1  ,
	input wire rst  ,
	input wire sel ,
	output wire clk_out
);
//*************code***********//
//为避免毛刺,在两个时钟都是低电平的时候进行切换-->用两个下降沿触发的DFF(D触发器)
reg q0,q1;
always@(negedge clk0 or negedge rst)
  if(!rst)
     q0 <= 0;
  else
     q0 <= ~sel & ~q1 ;

always@(negedge clk1 or negedge rst)
  if(!rst)
     q1 <= 0;
  else
     q1 <= sel & ~q0 ;

assign clk_out = (q0 & clk0)|(q1 & clk1);
//*************code***********//
endmodule

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务