我需要获得几个信号的值,以便与仿真进行比较(仿真是在Matlab中)。有很多值,我想把它们放到一个文件中,这样我就可以在脚本中运行它,避免手动复制这些值。
有没有办法将几个信号的值自动打印到一个文本文件中?
(设计是用VHDL实现的)
发布于 2014-06-21 05:38:48
首先制作将std_logic和std_logic_vector转换为string的函数,如下所示:
function to_bstring(sl : std_logic) return string is
variable sl_str_v : string(1 to 3); -- std_logic image with quotes around
begin
sl_str_v := std_logic'image(sl);
return "" & sl_str_v(2); -- "" & character to get string
end function;
function to_bstring(slv : std_logic_vector) return string is
alias slv_norm : std_logic_vector(1 to slv'length) is slv;
variable sl_str_v : string(1 to 1); -- String of std_logic
variable res_v : string(1 to slv'length);
begin
for idx in slv_norm'range loop
sl_str_v := to_bstring(slv_norm(idx));
res_v(idx) := sl_str_v(1);
end loop;
return res_v;
end function;使用逐位格式的优点是,任何非01值都将与准确的std_logic值一起显示,例如,十六进制表示不是这种情况。
然后进行将std_logic和std_logic_vector中的字符串写入文件的过程,例如在rising_edge(clk)中:
library std;
use std.textio.all;
...
process (clk) is
variable line_v : line;
file out_file : text open write_mode is "out.txt";
begin
if rising_edge(clk) then
write(line_v, to_bstring(rst) & " " & to_bstring(cnt_1) & " " & to_bstring(cnt_3));
writeline(out_file, line_v);
end if;
end process;上面的示例使用rst作为std_logic,使用cnt_1和cnt_3作为std_logic_vector(7 downto 0)。在"out.txt“中产生的输出结果是:
1 00000000 00000000
1 00000000 00000000
1 00000000 00000000
0 00000000 00000000
0 00000001 00000011
0 00000010 00000110
0 00000011 00001001
0 00000100 00001100
0 00000101 00001111
0 00000110 00010010https://stackoverflow.com/questions/24329155
复制相似问题