Skip to main content

Simulate your design

note

In this tutorial we are going to simulate the design we created in the last Hello World tutorial.

Requirements

VersionInformation
VHDPlus IDE0.9+Instructions
Packages-GHDL or ModelSim

In order to help with finding errors and not always have to program the FPGA, you can simulate your program. You can set the inputs of Main or a Component to trigger an operation and after running the simulation, you can see how the values of all signals change while running the code. This way, you have a lot of information to compare at a glance, which helps to find the error or check if your code works as expected.

Video Tutorial

Written tutorial (VHDP)

Create the simulation file

  1. Open your main .vhdp file to simulate. For this example we are going to use the Blink code from the last helloworld tutorial, but we change the blink frequency. Also, we added a button signal which needs to be '1' for the led to blink.
Main
(
led: OUT STD_LOGIC := '0';
btn : in STD_LOGIC;
)
{
Process()
{
Thread
{
if(btn = '1')
{
led <= '0';
Wait(50ms);
led <= '1';
Wait(50ms);
}
}
}
}
  1. Click on the button with the pulse symbol or click on Tools/Simulation

Simulation Assistant Button

  1. Set the time to simulate (don't set the time too high, or the simulation will take a long time to finish). For this example we are going to use 250ms. Set CLK frequency to your CLK. For our official hardware use 12MHz. Check the box to use the btn input.

Simulation Assistant

  1. Click on Save

Emulate the inputs

Visual

  1. Select the input to emulate
  2. Set the time for that the input should have a value
When the data is '1' or '0':
  1. Click on the rising or falling edge button
When you have an individual value:
  1. Set the value the input should have
  2. Click on the plus symbol
When you want to repeat the value sequence (e.g. for a clock signal)
  1. Set the data to repeat (e.g. 1ms '1', 1ms '0')
  2. Click on the repeat button

Code

With the code you can emulate the inputs. Programming the .ghdp file is like with .vhdp, but with some changes. For example:

  • wait for ...; adds a delay between the operations before and after
  • wait; stops process
  • wait until ...; waits until condition is true

There are much more tools that you can use for the simulation, but the best way is to just search for "VHDL Simulation". The same operations for VHDL work with GHDP as well.

Start the simulation

  1. Click on the run symbol in the simulation bar
  2. Check for errors in the output window
  3. After GTK Wave is open, click on the component of which you want to see the signal
  4. Double click the signal to display in the wave window
  5. You can zoom out and see the simulated behavior

Simulation with VHDL

  1. Write your VHDL simulation code
  2. Right click on the VHDL file
  3. Select "Simulate with GHDL"

Done ✔ Need help?

If everything worked as planned, the LED of your FPGA should blink every second.
If anything went wrong, feel free to ask for help. For the fastest response, join us on Discord.