Getting started with VHDL : software setup

This tutorial is currently partly outdated and will be updated soon. The current version of code is run with VUnit thus the .bat scripts are no longer maintained.

In this tutorial we are going to create a single phase inverter PI control simulation in VHDL that is synthesized to FPGA. We start from installing the proper software, then we run a test bench with a script using the installed software.

The project sources are managed, tested and developed using mainly three softwares Git, GHDL and GTKWave. Git is used for source code management and Git commands are also used for simulation scripts to use relative paths from the projects .git folder. GHDL is used as the general purpose VHDL simulator an GTKWave is used to visualize the waveforms.

I have found this combination of tools to be by far the fastest, easiest and most convenient to use for simulating, testing and developing VHDL source code. GHDL also integrates well to most most tools and I also use it for syntax checking the code.

Git

Git is needed for source management. It is also required for the project scripts to work since the projects Git folder is used as root to where source paths refer to. Git can be installed from

git-scm.com/download.

The setup is straightforward, download, install and done. After installing git, then the power supply repository can be cloned by by

After Git has cloned the repository, the sources should be found from the ac_inout_psu folder that git created.

MSYS2 package manager for automated installation

The MSYS2 is a package manager for the Windows which is used for automating updating and installing software. I highly recommend MSYS2 for installing the GHDL and GTKWave toolchain. I also recommend using powershell or powershell7 instead of command prompt as the powershell is simply easier to navigate.

The installation is made in short by downloading the installer, running it and then updating the packages.

The step by step instructions for installing the MSYS2 is found on the MSYS2 web page

https://www.msys2.org/

Note that you should probably do all of the steps which include inputting the two commands to update the database and base packages.

After MSYS2 has been installed, then the rest of the tools are one-liner installs.

GHDL setup with MSYS2

GHDL is the simulation software that is used to produce a waveform from the simulation code, which is then

After the MSYS2 has been installed, then you can install the GHDL by with

pacman -S mingw-w64-i686-ghdl-mcode

The ghdl.exe will then be available in the mingw folder found under the MSYS2 installation folder, which in my case is

C:\Programs\msys64\mingw32\bin\

Adding this to path allows the system to find GHDL and hence run the simulations. After GHDL has been installed, then it can be tested to be available by typing ghdl to console. Note that a new console needs to be opened after the path environmental variable is updated.

GTKWave

VHDL produces the voltage waveform file .vcd which is then input to the GTK wave that is used to visualize the result. The GTKWave can be installed with MSYS2 with command

pacman -S mingw-w64-x86_64-gtkwave

The gtkwave.exe is then found in mingw64 folder which in my case is

C:\Programs\msys64\mingw64\bin\

After both GHDL and GTKWave are found on system path you should be done.

Testing GHDL and GTKWave

The tools can be tested by launching a simulation model with a script. For testing GHDL all test benches can be run from the console by navigating to the ac_inout_psu folder and running the .bat script found on the project root. If you are using powershell, which is highly recommended, then just typing run and pressing tab should complete the command to

run_ghdl_testbenches.bat

This takes a minute or two during which all test benches are run. There are some output reported to the console, but as of now the test benches are not self checking so the idea is just to test that they can indeed be run at all.

After that has finished, then we go to simulate and plot a waveform. First navigate to multiplier simulation folder

cd source/math_library/multiplier/simulation/

To view some waveforms with GTKWave, a filter simulation is used. We launch the simulation with

sim_lcr_model.bat 1

The argument ‘1’ at the end lets the script open the gtkwave which should now pop on your screen. If run the .bat again with ‘0’ as argument the script should just trigger the simulation without opening another GTKwave.

To view the waveform with the GTKwave, first click the lcr_model in the SST window and then double click the capacitor_voltage in the list that opens with the selection of the lcr_model then the zoom should be set to full view.

Figure 1. View waveform with GTK wave, first click on the lrc_model, then double click on the capacitor voltage and lastly click on the “zoom fit” button

Next right click on the “capacitor_voltage” and then choose “insert analog height extension”. You can copy&paste a few more of these.

Figure 2. Add analog height extension to expand the space to which the waveform will be drawn

Lastly the data is changed to analog waveform by first selecting the capacitor_voltage again and the right clicking and navigating to the analog data format and then choosing step.

Figure 3. navigating the to the analog waveform

This should yield the following waveform

Figure 4

Congratulations, you now have a 4th order synthesizable simulation of a LCLC filter step responce on you GTKwave window (:

Next open the lcr_model.vhd file with your favourite text editor*

From the lcr_model.vhd file, change the step from load resistance to load current which is found at line 172

Figure 5. change simulation exitation to load current step at from file lcr_model.vhd

After this take out your command line and then run the script again but with changing the argument from “1” to “0”. This prevents the script from opening a new instance of the GTKwave.

sim_lcr_model.bat 0

If you opened a new one then you can congratulate your self as you have again managed to simulate a 4th order LCLC filter with synthesizable VHDL \o/.

Now select the previous window which should still have the previous waveform and press ctrl+shift+R and it should update the figure to the new waveform without changing anything but the data. And this is why GHDL + GTKwave is great, since you can simply iterate through small steps that simulate almost instantly and then see if anything changed from a waveform.

Figure 6. LCR filter model simulated with load current step

If you have the above waveform, congratulations you now have simulated the same LCLC filter by changing the load resistance to load current!

In the next part of this tutorial we will create from scratch a new simulation model, which uses the modelling tools from the math_library to model a buck converter and then tune a controller for it.

*(which should of course be VIM, or EMACS, though VIM >> EMACS >> everything else, also vscodium is also acceptable and *extremely highly recommended* if neither VIM nor EMACS are already familiar to you}).

Scroll to Top