fpga4fun.com - where FPGAs are fun.
Home
Welcome
Information


FPGA projects
Music box
Pong game
R/C servos
Text LCD module
Quadrature decoder
PWM and one-bit DAC
Debouncer
LED displays
Crossing clock domains
External contributions

FPGA interface projects
RS-232
JTAG
I2C
EPP
SPI
CNC steppers

FPGA advanced projects
Graphic LCD panel
Digital oscilloscope
10BASE-T interface
PCI interface
Spoc CPU core

Hands-on
A simple oscilloscope


FPGA introduction
What are FPGAs?
How FPGAs work
FPGA pins
Clocks and global lines
Download cables
Configuration
Learn more

FPGA software
Design software
Pin assignment
Design-entry/HDL
Simulation/HDL
Synthesis and P&R

FPGA electronic
SMD technology
Crystals and oscillators

HDL info
HDL tutorials
Verilog tips
VHDL tips

Quick-start guides
ISE
Quartus

Site
News
FPGA links
HDL tutorials
Forum


FPGA simulation

Once the hardware design entry is completed (either using a schematic or HDL), you may want to simulate your design on a computer to gain confidence that it works correctly.

Simulation requires a form of stimulus to provide to the inputs of the FPGA design, and then an FPGA simulator software can determine the corresponding FPGA outputs.

There are 2 ways you can create the simulation stimulus:

Interactive waveform editor

Using an interactive waveform editor, you enter the shape of the inputs (with a few clicks of your computer mouse), and the simulator software draws the shape of the outputs.

If you are just starting to play with FPGAs, try an interactive waveform editor first since it is easier than writing testbenches.

Testbench designs

A testbench design is a non-synthesizable HDL file that creates stimulus for another (usually synthesizable) file.
Here's an example:

Let's assume that this synthesizable circuit needs to be exercised.

module gates(a, b, q, r);
input a, b;
output q, r;

assign q = a & b;    // one AND gate
assign r = a | b;     // one OR gate

endmodule

A testbench could be:

module testbench_for_gates;

// we create some stimulus by toggling the signals "a" and "b" every 50 time-units
reg a, b;
initial
begin
  a = 0; b = 0;
  #50 a = 1;
  #50 a = 0; b = 1;
  #50 a = 1;
  #50 $finish;
end

// and we apply the stimulus to "gates". In response, "gates" drives "q" and "r" signals
wire q, r;
gates my_gates(a, b, q, r);

// and we can verify that "q" and "r" have the right values
always @(a or b) if(q != (a & b)) $display("ERROR in signal q");
always @(a or b) if(r != (a | b)) $display("ERROR in signal r");

endmodule

The testbench is usually written in the same behavioral language (VHDL or Verilog) than your circuit under test.
VHDL and Verilog have different strengths. For example, advanced users might like VHDL's advanced type structures, or Verilog's interface with C code (Verilog "PLI").

HDL simulator

A testbench is run (simulated) using an "HDL simulator". FPGA software don't include HDL simulators. Sometimes you can get a free time-limited trial of a commercially available simulator with FPGA software. Or try one of these:

VCD simulation viewer

The HDL simulator can, while running the simulation, record every signal and write them to a "VCD" file. That allows in turn to use a graphical VCD viewer to look at the signal values during the simulation. Try the free GTKWave waveform viewer.



>>> NEXT: Synthesis and place-and-route (P&R) >>>



This page was last updated on April 02 2007.