用vhdl实现FIFO
我正在为fifo编写VHDL,但是当我模拟时,没有输出?我不能在行为模拟中查看输出。这就好像data_in中没有数据可供读取写入fifo的输出。在我的代码中,将数据写入fifo首先将数据推送到DataIn总线上,然后在一个时钟周期内选通写入输入高电平用vhdl实现FIFO,vhdl,fpga,Vhdl,Fpga,我正在为fifo编写VHDL,但是当我模拟时,没有输出?我不能在行为模拟中查看输出。这就好像data_in中没有数据可供读取写入fifo的输出。在我的代码中,将数据写入fifo首先将数据推送到DataIn总线上,然后在一个时钟周期内选通写入输入高电平 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use std.textio.all;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use std.textio.all;
use IEEE.NUMERIC_STD.ALL;
entity fifo_mem is
port ( clk : in std_logic;
reset : in std_logic;
enr : in std_logic;
enw : in std_logic;
data_in : in std_logic_vector (15 downto 0); --input data
data_out : out std_logic_vector(15 downto 0); --output data
fifo_empty : out std_logic;
fifo_full : out std_logic );
end fifo_mem;
architecture Behavioral of fifo_mem is
type fifo_type is array(0 to 10) of bit_vector (15 downto 0);
signal memory : fifo_type :=(others => (others => '0'));
signal readptr,writeptr : integer := 0; --read and write pointers.
signal empty,full : std_logic ;
impure function InitRamFromFile (RamFileName : in string) return fifo_type is
FILE RamFile : text is in RamFileName;
variable RamFileLine : line;
variable RAM : fifo_type;
begin
for I in 0 to 10 loop
readline (RamFile, RamFileLine);
read (RamFileLine, RAM(I));
end loop;
return RAM;
end function;
signal RAM : fifo_type :=InitRamFromFile("C:\Users\hp\Desktop\file\file1.txt");
begin
fifo_empty <= empty;
fifo_full <= full;
process(Clk,reset)
--this is the number of elements stored in fifo at a time.
--this variable is used to decide whether the fifo is empty or full.
variable num_elem : integer := 0;
begin
if(reset = '1') then
data_out <= (others => '0');
empty <= '0';
full <= '0';
readptr <= 0;
writeptr <= 0;
num_elem := 0;
elsif(rising_edge(Clk)) then
if(enr = '1' and empty = '0') then --read
data_out <=to_stdlogicvector(RAM(readptr));
readptr <= readptr + 1;
num_elem := num_elem-1;
end if;
if(enw ='1' and full = '0') then --write
RAM(writeptr)<= to_bitvector(data_in);
writeptr <= writeptr +1;
num_elem := num_elem+1;
end if;
if(readptr = 10) then --resetting read pointer.
readptr <= 0;
end if;
if(writeptr = 10) then --resetting write pointer.
writeptr <= 0;
end if;
--setting empty and full flags.
if(num_elem = 0) then
empty <= '1';
else
empty <= '0';
end if;
if(num_elem = 10) then
full <= '1';
else
full <= '0';
end if;
end if;
end process;
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
使用std.textio.all;
使用IEEE.NUMERIC_STD.ALL;
实体fifo_mem为
端口(时钟:在标准逻辑中;
复位:在标准逻辑中;
enr:标准逻辑;
enw:标准逻辑;
数据输入:标准逻辑向量(15到0);--输入数据
数据输出:输出标准逻辑向量(15到0);--输出数据
fifo_empty:输出标准_逻辑;
fifo_full:输出标准_逻辑);
结束先进先出存储器;
fifo_mem的体系结构是
fifo类型是位向量(15到0)的数组(0到10);
信号存储器:fifo_类型:=(其他=>(其他=>“0”);
信号readptr,writeptr:整数=0--读写指针。
信号空、满:标准逻辑;
不纯函数InitRamFromFile(RamFileName:in string)返回的fifo_类型为
文件RamFile:文本在RamFileName中;
变量RamFileLine:line;
可变RAM:fifo_型;
开始
对于0到10循环中的I
readline(RamFile,RamFileLine);
读取(RamFileLine,RAM(I));
端环;
回程闸板;
末端功能;
信号RAM:fifo_类型:=InitRamFromFile(“C:\Users\hp\Desktop\file\file1.txt”);
开始
fifo_empty是您的测试台将数据放在
中的data_上,而您还没有向我们展示这一点,所以…欢迎使用堆栈溢出。如果你遵循指导原则,你更有可能得到一个有用的答案。具体来说,发生了什么,你期望发生什么?(没有输出,我无法查看输出,因为输出并不能真正回答这些问题。)其次,提供一些可执行的内容,以便其他人可以轻松看到您看到的内容。最后,只需提供重现问题所需的最低代码。最后两个被称为an。@JHBonarius,不,你错了,我没有删除任何问题,我不知道你为什么会这样?如果你不回答我,那么不要让好人回答我。thankyou@BrianDrummond,谢谢你的回复,好的,我会写我的testbenchA也会暗示file1.txt的内容,虽然为什么要在FIFO中初始化内存在这里并不明显,fifo11深似乎有点奇怪。