Creating and Using Testbenches

Creating Flip-Flop Example

Welcome to our tutorial on TestBenches in ChipInventor. We’ll create a simple Flip-Flop circuit to highlight how to set up and run TestBench simulations. Rather than focusing on circuit details, this guide emphasizes verifying behavior and generating waveforms with the TestBench. By the end, you’ll know how to efficiently validate digital logic in ChipInventor and be ready for more complex projects.

a. Creating the Flip-Flop Project

1. Click New Project in the top menu.

2. Fill the project details:

3. Click on Create Chip to start the project.

 

b. Flip-Flop in the Blocks Tab

4. Add one output (Output) and name it Q.

c. Configuring the TestBench


d. Improving the TestBench

2. Re-running the Simulation

3. Understanding the Static TestBench

If you notice differences in the signals displayed in the newly generated VCD, it means your changes to the TestBench were successfully applied.


e. Analyzing the Results

Building Frequency Dividers

In this section, instead of using an external clock signal, we will manually generate input transitions and define a custom TestBench to verify the behavior of the circuit. The goal is to demonstrate how to create a manual TestBench in Verilog instead of relying on the automated tools provided by ChipInventor.

 

Writing a Manual TestBench

Since we are not using the automated ChipInventor TestBench, we need to manually define input signals in Verilog to simulate our circuit.

Steps to Write the TestBench:


module testbench;

  reg b0, Reset;

  wire Q1, Q2, led0;


  // Instantiate the Flip-Flops

  D_FLIP_FLOP FF1 (.D(b0), .sync_reset(Reset), .Q(Q1));

  D_FLIP_FLOP FF2 (.D(Q1), .sync_reset(Reset), .Q(Q2));

  D_FLIP_FLOP FF3 (.D(Q2), .sync_reset(Reset), .Q(led0));


  // Generate a clock signal for b0

  initial begin

    Reset = 1;

    b0 = 0;

    #10 Reset = 0; // Release reset

  end


  always #5 b0 = ~b0;  // Toggle b0 every 5 time units (creates clock signal)


  // Simulation control

  initial begin

    $dumpfile("testbench.vcd");

    $dumpvars(0, testbench);

    #1000 $finish; // Run the simulation for sufficient time

  end

endmodule

 

Explanation of Key Sections in the Code

To ensure that the reader can understand and modify the TestBench if needed, let's go through the main parts of the code:

D_FLIP_FLOP FF1 (.D(b0), .sync_reset(Reset), .Q(Q1));

D_FLIP_FLOP FF2 (.D(Q1), .sync_reset(Reset), .Q(Q2));

D_FLIP_FLOP FF3 (.D(Q2), .sync_reset(Reset), .Q(led0));

always #5 b0 = ~b0;  // Toggle b0 every 5 time units (creates clock signal)

initial begin

  Reset = 1;

  b0 = 0;

  #10 Reset = 0; // Release reset

end


initial begin

  $dumpfile("testbench.vcd");

  $dumpvars(0, testbench);

  #1000 $finish; // Run the simulation for sufficient time

end

 

Running the Simulation

To test the frequency division, follow these steps:

 

Wrapping Up

This tutorial provided a practical guide for creating and validating Flip-Flops using ChipInventor. Through the practices described, you:

These fundamental concepts will serve as a foundation for more advanced projects, enabling the development of robust and effective digital solutions.