Wednesday 5 March 2014

Printing to the screen using VHDL

When I write a testbench I like to write messages to the transcript window in Modelsim. This is something I normally do using the VHDL REPORT statement. I also sometimes use the VHDL statements WRITE and WRITELINE to achieve a similar effect. This is better, but more effort!   I wish VHDL had a more flexible way of printing to the screen. Well now I have found it. Thanks to a webpage called www.stefanvhdl.com which contains a VHDL package txt_util I can now easily print to the screen.

The following is a simple VHDL testbench called tb_text that is used to demonstrate the print procedure found in the txt_util package. All it does is print a simple message to the transcript window in modelsim.

library ieee;
use ieee.std_logic_1164.all;

library work;
use work.txt_util_pkg.all;

entity tb_text is
end entity;

architecture arch_tb_text of tb_text is
begin
   process
   begin
     print("================================");
     print("This is using the print function");
     print("xxxx");
     print("================================");  
     wait;
   end process;
   
end architecture; 
The output from this VHDL file is as follows:

The VHDL procedure taken from the txt_util package used to implement this print facility is as follows:

 procedure print(text: string) is
     variable msg_line: line;
     begin
        write(msg_line, text);
        writeline(output, msg_line);
   end print;
References
http://www.stefanvhdl.com/
http://www.stefanvhdl.com/vhdl/vhdl/txt_util.vhd