HDLBits刷题记录 Circuits—Sequential Logic—Latches and Flip-Flops

这篇博客探讨了组合逻辑设计,以Z的计算为例,展示了如何在没有寄存器的情况下用数据流描述。同时讲解了边沿捕获寄存器的实现,通过一个示例展示如何在上升沿和下降沿捕获输入信号。此外,还介绍了双沿触发器的工作原理,利用异或门巧妙地在每个时钟边沿保持输入值。这些内容深入揭示了数字逻辑设计的基本概念。
摘要由CSDN通过智能技术生成

· DFFs and gates

 注意组合逻辑Z的位置,暂时可按如下方式考虑(由于Z无寄存器构成流水线,需单独从always的时序模块中拎出来,用数据流形式描述)

module top_module (
    input clk,
    input x,
    output z
); 
    reg q2,q1,q0;
    assign z = ~(q2 | q1 | q0);
    always @(posedge clk) begin
    q2 <= x ^ q2;
    q1 <= x & ~q1;
    q0 <= x | ~q0;
    end
endmodule

·Edge capture register

module top_module (
    input clk,
    input reset,
    input [31:0] in,
    output [31:0] out
);
    reg [31:0] o;
    always @(posedge clk) begin
        o <= in;
        if (reset)	
            out <= 32'h0;
        else 
        	out <= o & ~in | out;
    end
endmodule

细细品味这个 out <= o & ~in | out;   真的很绝!

·Dualedge

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

掌握这个 a^b^b=a, 也很绝!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值