MathJax

Sunday, August 7, 2011

VHDL - Using Image attribute to report value of scalar types.

Here is example of how to report values of scalar type to console. This maybe handy for unit test and first stages of code development. For serious test benches other approaches should be considered maybe something like -

http://bear.cwru.edu/VHDL/doc/snug2002_20020313_paper.pdf (http://bear.cwru.edu/VHDL/)

Any way this is example of how it works:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

---------------------------------------------
entity test is
---------------------------------------------
end entity;

---------------------------------------------
architecture test of test is
---------------------------------------------

signal signal_a: std_logic;
signal signal_b: boolean;
signal signal_c: natural;
signal signal_d: std_logic_vector(1 downto 0);

begin

signal_a <= '0';
signal_c <= 567;
signal_d <= "11";

---------------------------------------------
test_proc:process is
---------------------------------------------
begin
report "signal signal_a is " & std_logic'image(signal_a);
report "signal signal_b is " & boolean'image(signal_b);
report "signal signal_c is " & natural'image(signal_c);
report "signal signal_d is " &
integer'image(to_integer(unsigned(signal_d)));
wait for 100 ns;
end process;

end;
And the results:

# ** Note: signal signal_a is '0'
# Time: 100 ns Iteration: 0 Instance: /test
# ** Note: signal signal_b is false
# Time: 100 ns Iteration: 0 Instance: /test
# ** Note: signal signal_c is 567
# Time: 100 ns Iteration: 0 Instance: /test
# ** Note: signal signal_d is 3
# Time: 100 ns Iteration: 0 Instance: /test

No comments: