Sequential Logic-Latchs and Flip-Flops

本文详细介绍了数字系统设计中的各种触发器实现方法,包括基本的D触发器、带同步复位的D触发器、16位D触发器、锁存器、JK触发器以及脉冲边沿检测等高级应用。同时探讨了这些触发器如何用于信号检测和状态维护。

D触发器:

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );//
    always @(posedge clk) begin
         q<=d;
    end
    // Use a clocked always block
    //   copy d to q at every positive edge of clk
    //   Clocked always blocks should use non-blocking assignments

endmodule

加reset:

Create 8 D flip-flops with active high synchronous reset. All DFFs should be triggered by the positive edge of clk.

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);
    always @(posedge clk) begin
        if(!reset)
            q<=d;
        else
            q<=1'b0;
    end
endmodule

创建一个16D触发器,有时我们仅需要修改部分触发器中的值。字节使能信号控制当前时钟周期中16个寄存器中哪个字节需被修改。byteena[1]控制高字节d[15:8],而byteena[0]控制低字节d[7:0]。

resetn是一个同步,低复位信号。

所有的D触发器由时钟的上升沿触发。

module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);

    always @(posedge clk) begin
        if(resetn) begin
            if(byteena[1])
               
### RS Flip - Flops An RS flip - flop is a fundamental bistable circuit. It has two inputs (R and S) and two complementary outputs (Q and $\overline{Q}$). Its characteristic equations are as follows: - When $S = 1$ and $R = 0$, $Q^{n + 1} = 1$, which is the set state, making the output $Q$ high - level. - When $S = 0$ and $R = 1$, $Q^{n + 1} = 0$, which is the reset state, making the output $Q$ low - level. - When $S = 0$ and $R = 0$, $Q^{n + 1} = Q^{n}$, maintaining the original state. - When $S = 1$ and $R = 1$, the output state is indeterminate, and this situation should be avoided in practical applications. Here is a simple Verilog code example to implement an RS flip - flop: ```verilog module rs_flip_flop( input wire R, input wire S, output reg Q, output wire Q_bar ); assign Q_bar = ~Q; always @(*) begin if (S == 1 && R == 0) Q = 1; else if (S == 0 && R == 1) Q = 0; else if (S == 0 && R == 0) Q = Q; else Q = 1'bx; // Indeterminate state end endmodule ``` ### D Flip - Flops A D flip - flop has only one data input (D) and one clock input (clk). Its output (Q) stores the input data D at the effective edge (rising or falling edge) of the clock signal. The characteristic equation is $Q^{n + 1} = D$. Verilog code example: ```verilog module d_flip_flop( input wire clk, input wire D, output reg Q ); always @(posedge clk) begin Q <= D; end endmodule ``` ### JK Flip - Flops A JK flip - flop has two inputs (J and K) and one clock input (clk). It is an improvement over the RS flip - flop, eliminating the indeterminate state when $S = 1$ and $R = 1$ in the RS flip - flop. Its characteristics are as follows: - When $J = 0$ and $K = 0$, $Q^{n + 1} = Q^{n}$, maintaining the original state. - When $J = 0$ and $K = 1$, $Q^{n + 1} = 0$, which is the reset state. - When $J = 1$ and $K = 0$, $Q^{n + 1} = 1$, which is the set state. - When $J = 1$ and $K = 1$, $Q^{n + 1} = \overline{Q^{n}}$, which is the toggle state. Verilog code example: ```verilog module jk_flip_flop( input wire clk, input wire J, input wire K, output reg Q ); always @(posedge clk) begin if (J == 0 && K == 0) Q <= Q; else if (J == 0 && K == 1) Q <= 0; else if (J == 1 && K == 0) Q <= 1; else if (J == 1 && K == 1) Q <= ~Q; end endmodule ``` ### Basics of using flip - flops to build sequential logic circuits Sequential logic circuits are circuits whose outputs depend not only on the current inputs but also on the previous states. Flip - flops are the basic building blocks of sequential logic circuits. - **State storage**: Flip - flops can store binary states. For example, a D flip - flop can store the value of the input D at the clock edge, which is crucial for maintaining the state of a sequential circuit over time. - **Synchronization**: In a sequential circuit, flip - flops are often synchronized by a common clock signal. This ensures that all state changes occur at the same time, making the circuit more predictable and easier to design and analyze. - **Building larger circuits**: Multiple flip - flops can be combined with combinational logic circuits to build more complex sequential circuits such as counters, shift registers, and finite - state machines. For example, a counter can be constructed by connecting multiple flip - flops in a certain way so that the output of the counter changes in a sequential manner with each clock pulse.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值