library ieee;
use ieee.std_logic_1164.all;
entity tb is
end entity;
architecture sim of tb is
signal info : string(1 to 5);
begin
process is
begin
info <= "Hello";
wait for 1 us;
info <= "VHDL ";
wait for 1 us;
info <= "world";
wait for 1 us;
info <= "!!! ";
wait for 1 us;
wait;
end process;
end architecture;
在 Intel Quartus ModelSim Starter Edition(免费)中进行仿真,然后给出:
当我制作带有标签的测试平台时,这种情况经常发生。由于字符串信号是有界的(固定长度),并且 VHDL 是强类型的,因此您必须始终像 @morten-zilmer 在他的代码中所做的那样进行填充。信号是首选,因为某些模拟器 (Vivado) 无法在波形中放置变量,因为它们没有像信号那样定义事件时间。
我在下面创建了一个实用函数来帮助实现此目的,称为
string_cast()
SIGNAL testname: STRING(1 to 255);
FUNCTION string_cast(s: STRING; width: INTEGER := testname'LENGTH) RETURN STRING IS
return s & (1 to width - s'LENGTH => ' '); -- pad spaces
END FUNCTION string_cast;
现在用作
testname <= string_cast("ShortName");
do_test1 actions...
testname <= string_cast("LongNameButNot255Chars");
do_test2 actions...
希望这有帮助
当我制作带有标签的测试平台时,这种情况经常发生。由于字符串信号是有界的(固定长度),并且 VHDL 是强类型的,因此您必须始终像 @morten-zilmer 在他的代码中所做的那样进行填充。信号是首选,因为某些模拟器 (Vivado) 无法在波形中放置变量,因为它们没有像信号那样定义事件时间。
我在下面创建了一个实用函数来帮助实现此目的,称为
string_cast()
SIGNAL testname: STRING(1 to 255);
FUNCTION string_cast(s: STRING; width: INTEGER := testname'LENGTH) RETURN STRING IS
return s & (1 to width - s'LENGTH => ' '); -- pad spaces
END FUNCTION string_cast;
现在用作
testname <= string_cast("ShortName");
do_test1 actions...
testname <= string_cast("LongNameButNot255Chars");
do_test2 actions...
希望这有帮助