用vhdl将txt文件读入数组
我想一次读取一行文本文件中的数据。并在特定实例中输出。 为此,我创建了一个流程。该代码用于在测试台上生成刺激信号 第一道工序:- 在这里,我们试图预读取数组中的数据。我们还想计算一行中的数据值数量用vhdl将txt文件读入数组,vhdl,fpga,test-bench,Vhdl,Fpga,Test Bench,我想一次读取一行文本文件中的数据。并在特定实例中输出。 为此,我创建了一个流程。该代码用于在测试台上生成刺激信号 第一道工序:- 在这里,我们试图预读取数组中的数据。我们还想计算一行中的数据值数量 data_count: process variable anc_line : line; variable anc_data : std_logic_vector(9 downto 0); variable data_available : boolean; variabl
data_count: process
variable anc_line : line;
variable anc_data : std_logic_vector(9 downto 0);
variable data_available : boolean;
variable result : anc_array;
variable count : integer := 0;
begin
file_open(file_anc, "file_anc.txt", read_mode); -- open file
if read_line_enable = '1' then -- read line only when it is high
readline(file_anc, anc_line); -- read 1st line
hread(anc_line, result(1), data_available); -- directing readin into the array and checking
-- data_available boolean. Return false when no data in line remain
while (data_available = true) loop -- LOops till the last data in one line is reached
for i in result'range loop -- initialising the array
hread(anc_line, anc_data, data_available); --redaing one data from the line
result(i) := anc_data;
data_counter <= count + 1; -- counting the no. of data values in one line. Will be used later
end loop;
wait until rising_edge(video_clk);
end loop;
end if;
file_close(file_anc);
wait;
end process;
create_enable: process (video_clk)
begin
if rising_edge(video_clk) then -- creating the enable signal
if vcount = true and hcount = 0 then -- checking for conditions
read_line_enable <= '1';
else
read_line_enable <= '0';
end if;
-- insert data
if hcount <= data_counter then -- output data when condition is met
din_anc <= arr(hcount); -- output data<= array with index using hcoutn
else -- cause hcount increases from 0 to +1 at every clk
-- cycle.
din_anc <= "00"&x"20"; -- if hcount gets greater than the amnt of data in one line
-- put 20h in output
end if;
end if;
end process;
数据计数:进程
变量anc_线:线;
变量anc_数据:标准逻辑向量(9到0);
变量数据_可用:布尔值;
可变结果:anc_数组;
变量计数:整数:=0;
开始
文件打开(文件anc,“文件anc.txt”,读取模式);--打开文件
如果read_line_enable='1',则--read line only在高电平时才读取
readline(文件anc,anc行);--读第1行
线程(anc_行,结果(1),数据可用);--将readin定向到数组中并检查
--数据可用布尔值。当行中没有数据保留时返回false
while(data_available=true)loop——循环直到到达一行中的最后一个数据
对于结果范围循环中的i——初始化数组
线程(anc_行、anc_数据、数据_可用)--从行中重新生成一个数据
结果(i):=anc_数据;
数据计数器您的模拟环境是什么?一些模拟器需要一个特殊的路径来访问文件。我使用的是sim 10.3d模型。但别担心,我能够使用基本的读文本io代码读出数据。但是现在,当我想扩展我的代码以包含功能时,它无法按我所希望的方式工作。您的文本文件在哪里?您可以尝试以“write_模式”打开一个文件,并向其中写入一些内容,以查看将在何处生成该文件:您读取的文件应位于同一位置。它可能是你应该把它放在'work'目录中(modelsim的默认库名)。嗨,谢谢你的回复。代码是有效的。问题在于文本文件字符格式。显然,在Linux系统中存在这样的错误。另外,在我读取文件的其他情况下,这也很奇怪。所以,给大家一个提示,如果你的代码很好,但不起作用,请删除你的文本文件,然后重新创建。