Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File io VHDL文件中输入的一组数字中的两个数字之差_File Io_Vhdl - Fatal编程技术网

File io VHDL文件中输入的一组数字中的两个数字之差

File io VHDL文件中输入的一组数字中的两个数字之差,file-io,vhdl,File Io,Vhdl,我试图从文件中可用的一组数字中找出两个数字的差异。“read.txt”包含以下数字: 5. 15 25 36 98 654 256 20 354 我希望输出为101162556398236334 但是我在我的输出文件“realout.txt”中得到了0 0 10 11 556 236 236 236 236 236 236 我不知道为什么每次在起始位置0被打印,在结束位置数字被重复5次以上..请帮助我解决这个问题我的代码在这里 library IEEE; library std; use iee

我试图从文件中可用的一组数字中找出两个数字的差异。“read.txt”包含以下数字: 5. 15 25 36 98 654 256 20 354 我希望输出为101162556398236334 但是我在我的输出文件“realout.txt”中得到了0 0 10 11 556 236 236 236 236 236 236 我不知道为什么每次在起始位置0被打印,在结束位置数字被重复5次以上..请帮助我解决这个问题我的代码在这里

library IEEE;
library std;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
use IEEE.MATH_REAL.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.STD_LOGIC_TEXTIO.ALL;
use std.textio.all; --include package textio.vhd

entity testvhdl is
end testvhdl;
architecture Behavioral of testvhdl is
constant MAX : integer := 256*256-1;
SIGNAL rstb :  std_logic := '0';
SIGNAL clk :  std_logic := '0';
SIGNAL a :  std_logic_vector(7 downto 0) := (others=>'0');
--Outputs
SIGNAL sum :  std_logic_vector(7 downto 0);
--period of clock,bit for indicating end of file.
signal endoffile : bit := '0';
signal d1,d2,intt,n: integer:=0;
signal aa,ab,ac: integer:=0;
signal linenumber : integer:=1;
--signal dbus: std_logic_vector(7 downto 0) := x"00";
--------------------------------------------------------------------------------------------
function CONV_STDLV8bit_2INT(ARG: std_logic_vector (7 downto 0)) 
return integer is
variable int: integer:=0;
variable tmp: std_logic_vector(7 downto 0);

begin
    int :=0;
    tmp := ARG;
    for i in 0 to 7 loop
        if (tmp(i) ='1') then
            int := int+(2**i);
        else 
            int := int+0;
        end if;
    end loop;
    return int; 
end CONV_STDLV8bit_2INT;
--------------------------------------------------------------------------------------------
function CONV_INT2STDLV(ARG: INTEGER; SIZE: INTEGER) 
return STD_LOGIC_VECTOR is
variable result: STD_LOGIC_VECTOR (SIZE-1 downto 0):=x"00";
variable temp: integer:= 0;
begin
    temp := ARG;
    for i in 0 to SIZE-1 loop
        if ((temp mod 2) = 1) then
            result(i) := '1';
        else 
            result(i) := '0';
        end if;
        if temp > 0 then
            temp := temp / 2;
        elsif (temp > integer'low) then
            temp := (temp - 1) / 2; -- simulate ASR
        else
            temp := temp / 2; -- simulate ASR
        end if;
    end loop;
    return result; 
end CONV_INT2STDLV;
--------------------------------------------------------------------------------------------
    constant PERIOD : time := 20 ns;
    constant DUTY_CYCLE : real := 0.5;
    constant OFFSET : time := 30 ns;

begin

-- Instantiate the Unit Under Test (UUT)
--uut: imadder PORT MAP(
--      rstb => rstb,
--      clk => clk,
--      a => a,
--      b => b,
--      sum => sum
--  );

CLOCK: PROCESS    -- clock process for clk
        BEGIN
            WAIT for OFFSET;
            CLOCK_LOOP : LOOP
                clk <= '0';
                WAIT FOR (PERIOD - (PERIOD * DUTY_CYCLE));
                clk <= '1';
                WAIT FOR (PERIOD * DUTY_CYCLE);
            END LOOP CLOCK_LOOP;
    END PROCESS;

tb: PROCESS
    BEGIN
        rstb <='0';
        wait for 60ns;
        rstb <='1';
        wait for 1312us; -- will wait forever

    END PROCESS;

reading : process
    file infile : text is in "real.txt"; --declare input file 1987
    file outfile : text is out "realout.txt"; --declare output file 1987

    --file infile2 : text is in "img2.txt"; --declare input file 1987
    variable inline,inline2 : line; --line number declaration
    variable dataread1 : integer;
    variable dataread2 : integer;
    variable buff_out : line; --line number declaration
--  variable aa,ab,ac: integer:=0;
    begin
        wait until clk = '0' and clk'event;
        if(n < 10) then
            if (not (endfile(infile))) then --checking the "END OF FILE" is not reached.
                    readline(infile, inline);
                    readline(infile, inline2);
                    read(inline, dataread1);
                    read(inline2, dataread2);
                    d1 <= dataread1;
                    d2 <= dataread2;
--          if n mod 5 = 0 then
                    aa <= abs(d1 - d2);
--                  a <= CONV_INT2STDLV(aa,8);
--                  
--       n <= n+1;
--      elsif (d1 > aa) then
--          ab <= d1 - aa;
--          ac <= ac+ab;
--          aa <= d1;
--          
--     else
--       ab <= aa - d1;
--       ac <= ac+ab;
--       aa <= d1;
--       
--       end if;    
--      d1 <= ac;
                    --readline(infile2, inline2); 
                    --read(inline2, dataread1);
                    --d2 <=integer(dataread1);
                --b <= CONV_INT2STDLV(d2,8);
            else
                a<=x"00";

                --b<=x"00";
            end if;
        else    
          endoffile <='1'; --set signal to tell end of file read file is reached.
        end if;
--  end process reading;

--write process @negative edge
--writing : process

--  begin
--      wait until clk = '0' and clk'event;
        if(endoffile='0') then --if the file end is not reached.
            --intt <= CONV_STDLV8bit_2INT(aa);
            if(linenumber > 0) then
                n <= n+1;
                --if(linenumber>11) then
                write(buff_out, aa);  
                writeline(outfile, buff_out);-- write line to output_image text file.
                --end if; 
          end if;      
                linenumber <= linenumber + 1;
        else
            null;
        end if;
    end process reading;

end Behavioral;

--WRITE (buf, string'("hello"));
--WRITELINE(fileptr,buf);
--WRITE (buf, bit_vector'(" 010111 "));
--WRITELINE(fileptr,buf);

--http://myfpgablog.blogspot.in/2011/12/memory-initialization-methods.html
-- constant MEM_DEPTH : integer := 2**ADDR_WIDTH;
-- type mem_type is array (0 to MEM_DEPTH-1) of signed(DATA_WIDTH-1 downto 0);
-- impure function init_mem(mif_file_name : in string) return mem_type is
    -- file mif_file : text open read_mode is mif_file_name;
    -- variable mif_line : line;
    -- variable temp_bv : bit_vector(DATA_WIDTH-1 downto 0);
    -- variable temp_mem : mem_type;
-- begin
    -- for i in mem_type'range loop
        -- readline(mif_file, mif_line);
        -- read(mif_line, temp_bv);
        -- temp_mem(i) := signed(to_stdlogicvector(temp_bv));
    -- end loop;
    -- return temp_mem;
-- end function;

-- constant mem : mem_type := init_mem("mem_init_vhd.mif");
IEEE库;
图书馆标准;
使用ieee.std_logic_1164.all;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
使用ieee.numeric_std.all;
使用IEEE.MATH_REAL.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
使用IEEE.STD_LOGIC_TEXTIO.ALL;
使用std.textio.all--包括包textio.vhd
实体testvhdl是
端测试vhdl;
testvhdl的体系结构是
常量最大值:整数:=256*256-1;
信号rstb:std_逻辑:='0';
信号时钟:标准逻辑:='0';
信号a:std_逻辑_向量(7到0):=(其他=>'0');
--输出
信号和:标准逻辑向量(7到0);
--时钟周期,表示文件结束的位。
信号结束符:位:='0';
信号d1,d2,intt,n:整数=0;
信号aa、ab、ac:整数=0;
信号线号:整数:=1;
--信号dbus:std_逻辑_向量(7到0):=x“00”;
--------------------------------------------------------------------------------------------
函数CONV_STDLV8bit_2INT(参数:标准逻辑向量(7到0))
返回整数为
变量int:integer:=0;
变量tmp:std_逻辑_向量(7到0);
开始
int:=0;
tmp:=ARG;
对于0到7循环中的i
如果(tmp(i)='1'),则
int:=int+(2**i);
其他的
int:=int+0;
如果结束;
端环;
返回int;
结束转换标准8bit;
--------------------------------------------------------------------------------------------
函数CONV_INT2STDLV(参数:整数;大小:整数)
返回标准逻辑向量为
变量结果:标准逻辑向量(大小-1到0):=x“00”;
变量温度:整数:=0;
开始
温度:=ARG;
对于0到大小为1的循环中的i
如果((温度模式2)=1),则
结果(i):"1";;
其他的
结果(i):"0";;
如果结束;
如果温度>0,则
温度:=温度/2;
elsif(温度>整数低),然后
温度:=(温度-1)/2;——模拟ASR
其他的
温度:=温度/2;--模拟ASR
如果结束;
端环;
返回结果;
结束转换INT2STDLV;
--------------------------------------------------------------------------------------------
恒定周期:时间:=20ns;
恒定占空比:实际值:=0.5;
恒定偏移量:时间:=30ns;
开始
--实例化被测单元(UUT)
--uut:imadder端口映射(
--rstb=>rstb,
--时钟=>clk,
--a=>a,
--b=>b,
--sum=>sum
--  );
时钟:进程——时钟的时钟进程
开始
等待补偿;
时钟环路:环路
clk…我不知道为什么每次在起始位置0被打印,在结束位置数字被重复5次以上..请帮助我解决这个问题我的代码在这里。
除了疯狂的上下文从句和所有无关的噪音,这里还有两件明显错误的事情。首先,您建议real.txt的输入数据集具有奇数行(元素-整数)。其次,您误用了位信号文件:

reading : 
    process

        file infile : text is in "real.txt";
        file outfile : text is out "realout.txt"; 

        variable inline,inline2 : line;
        variable dataread1 : integer;
        variable dataread2 : integer;
        variable buff_out : line;

    begin
        wait until clk = '0' and clk'event;
        if(n < 10) then
            if (not (endfile(infile))) then 
                    readline(infile, inline);
                    readline(infile, inline2);
                    read(inline, dataread1);
                    read(inline2, dataread2);
                    d1 <= dataread1;
                    d2 <= dataread2;

                    aa <= abs(d1 - d2);
            else
                a<=x"00";
            end if;
        else    
          endoffile <='1'; 
        end if;

        if(endoffile='0') then 
            if(linenumber > 0) then
                n <= n+1;
                write(buff_out, aa);  
                writeline(outfile, buff_out);
          end if;      
                linenumber <= linenumber + 1;
        else
            null;
        end if;
    end process reading;

如果将n添加到波形显示中,它将提供有关如何修复前导零和缺少的尾随值的一些见解。一种触发器,它装载了告诉你0library IEEE; use ieee.std_logic_1164.all; use std.textio.all;