首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有办法从modelsim模拟中将信号值打印到文件中?

有没有办法从modelsim模拟中将信号值打印到文件中?
EN

Stack Overflow用户
提问于 2014-06-20 22:04:22
回答 3查看 9.8K关注 0票数 2

我需要获得几个信号的值,以便与仿真进行比较(仿真是在Matlab中)。有很多值,我想把它们放到一个文件中,这样我就可以在脚本中运行它,避免手动复制这些值。

有没有办法将几个信号的值自动打印到一个文本文件中?

(设计是用VHDL实现的)

EN

Stack Overflow用户

回答已采纳

发布于 2014-06-21 05:38:48

首先制作将std_logicstd_logic_vector转换为string的函数,如下所示:

代码语言:javascript
复制
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_logicstd_logic_vector中的字符串写入文件的过程,例如在rising_edge(clk)中:

代码语言:javascript
复制
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_1cnt_3作为std_logic_vector(7 downto 0)。在"out.txt“中产生的输出结果是:

代码语言:javascript
复制
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 00010010
票数 4
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24329155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档