VHDL 波形中的字符串

问题描述 投票:0回答:1

如何打印 VHDL 波形中的字符串? -> 就像这里“/></a></p>
    </question>
<answer tick=

字符串与其他类型的信号没有什么不同,所以你可以这样做:

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
1个回答
0
投票

当我制作带有标签的测试平台时,这种情况经常发生。由于字符串信号是有界的(固定长度),并且 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...

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.