HDLBits-Dualedge

该博客介绍了如何在FPGA中创建一个功能类似双沿触发触发器的电路。由于FPGA不支持双沿触发的触发器,作者通过组合两个单边沿触发的触发器来模拟双沿触发的行为。在给定的Verilog代码中,正边沿触发的DFF用于更新'n'寄存器,而负边沿触发的DFF则更新'p'寄存器。通过异或操作(p^n),在每个时钟边缘,电路都能保持输入'd'的最新值,从而达到双沿触发的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You're familiar with flip-flops that are triggered on the positive edge of the clock, or negative edge of the clock. A dual-edge triggered flip-flop is triggered on both edges of the clock. However, FPGAs don't have dual-edge triggered flip-flops, and always @(posedge clk or negedge clk) is not accepted as a legal sensitivity list.你所熟悉的触发器是在时钟的正边或负边触发的。双边沿触发的触发器是在时钟的两个边沿上触发的。然而,FPGA没有双边沿触发的触发器,而且总是@(posedge clk或negedge clk)不被接受为合法的灵敏度列表。

Build a circuit that functionally behaves like a dual-edge triggered flip-flop:建立一个功能上类似于双沿触发触发器的电路。

官方答案:

module top_module(
	input clk,
	input d,
	output q);
	
	reg p, n;
	
	// A positive-edge triggered flip-flop
    always @(posedge clk)
        p <= d ^ n;
        
    // A negative-edge triggered flip-flop
    always @(negedge clk)
        n <= d ^ p;
    
    // Why does this work? 
    // After posedge clk, p changes to d^n. Thus q = (p^n) = (d^n^n) = d.
    // After negedge clk, n changes to d^p. Thus q = (p^n) = (p^d^p) = d.
    // At each (positive or negative) clock edge, p and n FFs alternately
    // load a value that will cancel out the other and cause the new value of d to remain.
    assign q = p ^ n;
    
    
	// Can't synthesize this.
	/*always @(posedge clk, negedge clk) begin
		q <= d;
	end*/
    
    
endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无牙大白鲨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值