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:
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.
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
A testbench could be:
// we create some stimulus by toggling the signals "a" and "b" every 50 time-units
reg a, b;
a = 0; b = 0;
#50 a = 1;
#50 a = 0; b = 1;
#50 a = 1;
// 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");
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").
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:
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.