Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Verilog

Designing a D Flip-Flop with Asynchronous Active-Low Reset

A D flip-flop is a sequential element that follows the input pin d at the given edge of a clock.

Design #1: With async active-low reset

  
  
module dff 	( input d,
              input rstn,
              input clk,
              output reg q);
	
	always @ (posedge clk or negedge rstn) 
       if (!rstn)
          q <= 0;
       else
          q <= d;
endmodule

  

Hardware Schematic

Testbench

  
  
module tb_dff;
	reg clk;
	reg d;
	reg rstn;
	reg [2:0] delay;
	
    dff  dff0 ( .d(d),
                .rsnt (rstn),
                .clk (clk),
                .q (q));
    
    // Generate clock
    always #10 clk = ~clk;
                   
    // Testcase
    initial begin
    	clk <= 0;
    	d <= 0;
    	rstn <= 0;
    	
    	#15 d <= 1;
    	#10 rstn <= 1;
    	for (int i = 0; i < 5; i=i+1) begin
    		delay = $random;
    		#(delay) d <= i;
    	end
    end
endmodule

  

Design #1: With sync active-low reset

  
  
module dff 	( input d,
              input rstn,
              input clk,
              output reg q);
	
	always @ (posedge clk) 
       if (!rstn)
          q <= 0;
       else
          q <= d;
endmodule

  

Hardware Schematic

Testbench

  
  
module tb_dff;
	reg clk;
	reg d;
	reg rstn;
	reg [2:0] delay;
	
    dff  dff0 ( .d(d),
                .rsnt (rstn),
                .clk (clk),
                .q (q));
    
    // Generate clock
    always #10 clk = ~clk;
                   
    // Testcase
    initial begin
    	clk <= 0;
    	d <= 0;
    	rstn <= 0;
    	
    	#15 d <= 1;
    	#10 rstn <= 1;
    	for (int i = 0; i < 5; i=i+1) begin
    		delay = $random;
    		#(delay) d <= i;
    	end
    end
endmodule

  

Verilog

  1. Understanding the J‑K Flip‑Flop: Design, Logic, and Applications
  2. Asynchronous Flip‑Flop Inputs: Preset and Clear Functionality
  3. Implementing Sequential Logic Using Verilog 'always' Blocks
  4. JK Flip‑Flop: Design, Implementation, and Testbench
  5. 4‑bit Counter: Efficient Binary Counting from 0 to 15
  6. Verilog Asynchronous Ripple Counter Design & Implementation
  7. Verilog Ring Counter Module: Design & Testbench Example
  8. 4‑Bit Johnson Counter in Verilog – Design, Testbench & Simulation
  9. Verilog Mod-N Counter Design: Parameterized Module & Testbench
  10. Verilog Gray Counter Module – 4‑bit Gray Code Generator