Installing GHDL and Compiling VHDL with GHDL tutorial.

Written by Tom on Tuesday 13/02/07


I’m stuck in the hills of Pakistan and don’t have US$1000 to buy a license for Altera Quartus II tool chain. So what can I use to compile and debug some VHDL code? GHDL is a GNA project that is free, it’s driven from the command line but is fast for small projects. Get the Win32 .exe from here.


Installation:

Just double click the installer and follow your nose. Make sure you tick add to path.


GHDL is command line driven there are three basic commands.

1) ghdl -a myvhdl.vhdl -- this will analyse the vhdl code, this is the same as compiling the code.

2) ghdl -e myvhdl The "-e" option means elaborate. With this option, GHDL creates code in order to elaborate a design, with the "myvhdl" entity at the top of the hierarchy.

3) ghdl -r myvhdl -- The simulation is launched using this command.


Tips:
GHDL would hang when I used the following code to generate the clk and reset signals in my test bench code even though I had the "wait" statement at the end of my process.


-- clock generation

clock_gen: process(clk, reset) -- clock generator and one shot clear signal

begin

if reset ='1' then -- happens only once

reset <= '0' after 200 ps;

elsif reset='0' then -- avoid time zero glitch

clk <= not clk after 5 ns; -- 10 ns period

end if;

end process clock_gen;


Solution was to run with the following option, "--stop-time=1us" with this the simulation completed.


By adding the --vcd=myvhdl.vcd option to the command line a .vcd file is created with signals that GTKWave can view. (GTKWave is the discussed in the next article)


So the -r command looks like this.


ghdl -r myvhdl --vcd=myvhdl.vcd --stop-time=1us


For a complete overview get the manual from here.


The below code was taken from the manual so can test the compilation process


-- Hello world program.

use std.textio.all; -- Imports the standard textio package.


-- Defines a design entity, without any ports.

entity hello_world is

end hello_world;


architecture behaviour of hello_world is

begin

process

variable l : line;

begin

write (l, String'("Hello world!"));

writeline (output, l);

wait;

end process;

end behaviour;


The result of the simulation appears on the screen:

Hello world!