1

我有两个新手问题。我正在尝试将数组中的数据输出到 vhdl 上的文本文件中。尽管参考了许多在线指南来执行此操作,但我总是提出“文件不存在”。关于出了什么问题的任何建议?

其次,当我尝试使用下面的数组信号作为 write 函数的参数时,它会出错。我还能如何使用非常量数据作为操作数?

entity Top_Module is
Port ( clk : in  STD_LOGIC);
end Top_Module;

architecture Behavioral of Top_Module is

type array_1 is array (0 to 127) of integer range -128 to 127;
signal sample_1: array_1  := (104,40,-40,-104,-128,-104,-40,40,104,127,104,40,40,-4);
constant  a :std_logic_vector(3 downto 0):= "0111";
begin


process(clk)    -- process for writing the outputs to the "*.txt" file
file result_file: text  is out "fft_output.txt";
variable outline:line;
constant tmp_fft:integer:=0;
begin
    if(clk'event and clk='1') then
                --tmp_fft  :=to_integer(signed(sample_1));
                write(outline,a);
                writeline(result_file,outline);
    end if;
end process;
4

2 回答 2

1

文件声明是 VHDL 1987 语法,因此请尝试使用:

file result_file : text open write_mode is "fft_output.txt";

您的代码没有显示它,但我假设您包含如下std.textio包:

library std;
use std.textio.all;

在 VHDL 2002中,这个包不知道如何line从 . 因此,如果您使用的是 VHDL 2002,则问题可能是由于对过程 中的参数提供了支持。std_logic_vectorwrite(outline, a)std_logic_vectorwrite

非标准 Synopsys 包std_logic_textio在大多数工具中都可用,并且包括用于std_logic_vector. 该软件包可用于:

library ieee;
use ieee.std_logic_textio.all;

VHDL 2008 标准std_logic_vectorstd_logic_1164包中添加了对 write of 的支持,因此您可能需要检查您使用的模拟器是否支持 VHDL 2008 中的此功能。请注意,二进制和十六进制输出也支持bwritehwrite

请注意,通常无法使用writeand 进行综合textio,因为它们是基于line类型的,而类型又是一种access类型,类似于其他语言中的指针类型,并且无法综合。对于综合使用函数 the slv_imagein David Koontz's answer。

于 2014-10-08T14:51:36.920 回答
1

除了 Morten 的回答之外,您还没有表示sample_1聚合默认值中的每个元素,这可以通过, others => 0在右括号之前附加来解决。

因为您的 VHDL 设计规范在其他方面符合 IEEE Std 1076-1987,所以我使用 ghdl 的 --std=87 标志使用我坐过的字符串转换例程一起生成了一点。(而且 -1987 年缺少 'VALUE 是一件麻烦事):

library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;

entity Top_Module is
Port ( clk : in  std_logic);
end Top_Module;

architecture Behavioral of Top_Module is
    function slv_image(constant inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            case input_str(i) is
                when 'U' => image_str(i) := 'U';
                when 'X' => image_str(i) := 'X';
                when '0' => image_str(i) := '0';
                when '1' => image_str(i) := '1';
                when 'Z' => image_str(i) := 'Z';
                when 'H' => image_str(i) := 'H';
                when 'L' => image_str(i) := 'L';
                when 'W' => image_str(i) := 'W';
                when '-' => image_str(i) := '-';
            -- image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
            end case;
        end loop;
        return image_str;
    end;
    type array_1 is array (0 to 127) of integer range -128 to 127;
    signal sample_1: array_1  := (104,40,-40,-104,-128,-104,-40,40,104,127,104,40,40,-4, others => 0);
    constant  a : std_logic_vector(3 downto 0):= "0111";
begin

Unlabelled:
    process(clk)    -- process for writing the outputs to the "*.txt" file
        file result_file: text  is out "fft_output.txt";
        -- file result_file : text open write_mode is "fft_output.txt";
        variable outline: line;
        constant tmp_fft:integer := 0;
    begin
        if(clk'event and clk='1') then
                    --tmp_fft  :=to_integer(signed(sample_1));
                    write(outline,slv_image(a));
                    writeline(result_file,outline);
        end if;
    end process;
end Behavioral; -- architecture;

带测试台:

library ieee;
use ieee.std_logic_1164.all;

entity tb_topmod is
end tb_topmod;

architecture foo of tb_topmod is
    signal clk:  std_logic := '0';
    component Top_Module   -- no is
        Port ( clk : in  std_logic);
    end component;
    for DUT: Top_Module use entity work.Top_Module(Behavioral);
begin
DUT:
    Top_Module   -- entity work.Top_Module
        port map (clk => clk);
CLOCK:
    process
    begin
        wait for 20 ns;
        clk <= not clk;
        if Now > 100 ns then
            wait;
        end if;
    end process;
end foo;

ghdl -a --std=87 topmod.vhdl
ghdl -e --std=87 tb_topmod foo
ghdl -r tb_topmod foo

(分析、阐述和运行(模拟)设计。)

文件 fft_output.txt 文件包含:

更多 fft*
0111
0111
0111

Now这是测试台CLOCK过程中测试的预期输出。您的设计规范只为a.

现在您真的在使用 VHDL -1987 工具吗?

于 2014-10-08T16:03:40.117 回答