-
Introduction
The output of a D Flip-Flop tracks the input, making transitions which match those of the input. The D in D Flip-Flop stands for Data i.e. this Flip-Flop stores the value on the data line. It can be thought of as a basic memory cell. A D Flip-Flop can be made from a Set/Reset Flip-Flop by tying the set line to the reset line through an inverter. The output of the Flip-Flop may be clocked. If the output is clocked then the D Flip-Flop is synchronous D Flip-Flop. Synchronous D Flip-Flop, thus, has output which is synchronized with the either the rising edge or the falling edge of the input clock pulse. The block diagram of synchronous D Flip-Flop is shown in Figure 1.
Figure 1. Block diagram of synchronous D Flip-Flop -
Truth Table
Figure 2 shows the truth table of synchronous D Flip-Flop which is clocked to the rising edge of input clock. The inputs to the D Flip-Flop are data-bit D, and control lines reset and clock. There are two outputs Q and Q'.
Figure 2. Truth table of synchronous D Flip-Flop -
Verilog Module
Figure 3 shows the Verilog module of D Flip-Flop. The input to the module is a 1-bit input data line D. The control lines to the module include a 1-bit clock line Clk which is supplied by the 50 MHz on-board clock generator and a 1-bit active high reset. The output lines are Q and Qbar (complement of output line Q). The output line Q takes the same value as that in the input line D on the rising edge of the clock line Clk when the reset line is at low.
Figure 3. Verilog module of synchronous D Flip-Flop -
Verilog Code for synchronous D Flop-Flop (DFF.v)
- module DFF( Q,
- Qbar,
- D,
- Clk,
- Reset
- );
- output reg Q;
- output Qbar;
- input D,
- Clk,
- Reset;
- assign Qbar = ~Q;
- always @(posedge Clk)
- begin
- if (Reset == 1'b1) //If not at reset
- Q = 1'b0;
- else
- Q = D;
- end
- endmodule
Figure 4. Verilog code for synchronous D Flip-Flop -
Verilog Test Bench for synchronous D Flop-Flop (DFF_tb.v)
- `timescale 1ns / 1ps
- module DFF_tb;
- // Inputs
- reg D;
- reg Clk;
- reg Reset;
- // Outputs
- wire Q;
- wire Qbar;
- // Instantiate the Unit Under Test (UUT)
- DFF uut (
- .Q(Q),
- .Qbar(Qbar),
- .D(D),
- .Clk(Clk),
- .Reset(Reset)
- );
- initial begin
- // Initialize Inputs
- D = 1'b0;
- Clk = 1'b0;
- Reset = 1'b1;
- // Wait 100 ns for global reset to finish
- #100;
- // Add stimulus here
- Reset = 1'b0;
- #20;
- forever #40 D = ~ D;
- end
- always #10 Clk = ~Clk;
- endmodule
Figure 5. Verilog Test bench for synchronous D Flip-Flop. -
Timing Diagram
Figure 6. Timing diagram of synchronous D Flip-Flop
D Flip-Flop
Subscribe to:
Posts (Atom)