In this tutorial we are going to simulate the design we created in the last Hello World tutorial.
|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.
Written tutorial (VHDP)
Create the simulation file
- 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.
led: OUT STD_LOGIC := '0';
btn : in STD_LOGIC;
if(btn = '1')
led <= '0';
led <= '1';
- Click on the button with the pulse symbol or click on Tools/Simulation
- 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.
- Click on Save
Emulate the inputs
- Select the input to emulate
- Set the time for that the input should have a value
When the data is '1' or '0':
- Click on the rising or falling edge button
When you have an individual value:
- Set the value the input should have
- Click on the plus symbol
When you want to repeat the value sequence (e.g. for a clock signal)
- Set the data to repeat (e.g. 1ms '1', 1ms '0')
- Click on the repeat button
With the code you can emulate the inputs.
.ghdp file is like with
.vhdp, but with some changes.
wait for ...;adds a delay between the operations before and after
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
- Click on the run symbol in the simulation bar
- Check for errors in the output window
- After GTK Wave is open, click on the component of which you want to see the signal
- Double click the signal to display in the wave window
- You can zoom out and see the simulated behavior
- Write your VHDL simulation code
- Right click on the VHDL file
- Select "Simulate with GHDL"