载入中...
时 间 记 忆
载入中...
最 新 评 论
载入中...
专 题 分 类
载入中...
最 新 日 志
载入中...
最 新 留 言
载入中...
搜 索
用 户 登 录
载入中...
友 情 连 接
博 客 信 息
载入中...


 
同步FIFO之VHDL描述4
[ 2007-2-4 20:44:00 | By: skycanny ]
 
同步FIFOVHDL描述4

       今天准备完成同步FIFO其他模块的代码,主要包括读指针管理和产生电路,FIFO状态判断电路,以及双端口RAMVHDL描述。先是读指针管理和产生电路:

-----------------------------------------------------------------------------------------------------------
-- Designer  : skycanny
-- Date   : 2007-2-3
-- Description : read_pointer is created

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity read_pointer is
 generic
 (
  depth : positive 
 );
 port
 (
  clk  : in std_logic;
  rst  : in std_logic;
  rq  : in std_logic;
  empty : in std_logic;
  rd_pt : out std_logic_vector(depth - 1 downto 0)  
 );
end entity read_pointer;

architecture RTL of read_pointer is
signal rd_pt_t : std_logic_vector(depth - 1 downto 0);  -- read pointer counter

begin
 process(rst, clk)
 begin
  if rst = '0' then
   rd_pt_t <= (others => '0');
  elsif clk'event and clk = '1' then
   if rq = '0' and empty = '0' then
    rd_pt_t <= rd_pt_t + 1;
   end if;
 end process;
 rd_pt <= rd_pt_t;
end RTL;
------------------------------------------------------------------------------------------------------------

 

 

刚才想了一下,读写指针产生电路必须要对FIFO的状态进行判断,所以又对上面的代码进行了一点修改(上面的代码是修改过的),判断FIFO的状态,这一点在刚开始的时候给疏忽了,幸好刚才给发现了。同样昨天写的写指针产生电路没有判断FIFOfull状态,也要进行修改,还是在昨天的基础上修改吧,就不在这里罗嗦了,下面就是FIFO状态判断电路的VHDL描述。

-----------------------------------------------------------------------------------------------------------

-- Designer            :      skycanny

-- Date                  :      2007-2-3

-- Description :      read_pointer is created

 

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

 

entity judge_status is

       generic

       (

              depth      :      positive

       );

       port

       (

              clk          :      in     std_logic;

              rst          :      in     std_logic;

              wr_pt      :      in     std_logic_vector(depth - 1 downto 0);

              rd_pt       :      in     std_logic_vector(depth - 1 downto 0);

              empty     :      out   std_logic;

              full   :      out   std_logic

       );

end entity judge_status;

 

architecture RTL of judge_status is

 

begin

 

       process(rst, clk)

       begin

              if rst = '0 then

                     empty <= '1';

              elsif clk'event and clk = '1' then

                     if wr_pt = rd_pt then

                            empty <= '1';

                     else

                            empty <= '0';

                     end if;

              end if;

       end process;

      

       process(rst, clk)

       begin

              if rst = '0' then

                     full <= '0';

              elsif clk 'event and clk = '1' then

                     if wr_pt > rd_pt then

                            if (rd_pt + depth) = wr_pt then

                                   full <= '1';

                            else

                                   full <= '0';

                            end if;

                     else

                            if (wr_pt + 1 ) = rd_pt then

                                   full <= '1';

                            else

                                   full <= '0';

                            end if;

                     end if;

              end if;

       end process;

 

end RTL;

-----------------------------------------------------------------------------------------------------------


    广告时间欢迎访问skycanny的笔记(副站) 。现在就开始双口RAMVHDL描述吧,这个可是很重要的。下面的代码在AlteraCycloneII系列的器件上通过了后仿真。

-----------------------------------------------------------------------------------------------------------

-- Designer            :      skycanny

-- Date                  :      2007-2-3

-- Description :      This VHDL file is designed to generate a dual port ram   

-- Device        :      Cyclone II

 

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

 

entity dualram is

       generic

       (

              width      :      positive   := 16;

              depth      :      positive   := 8

       );

       port

       (

              ------------------------- port a is only for writing -------------------------------

              clka :      in     std_logic;

              wr          :      in     std_logic;

              addra      :      in     std_logic_vector(depth - 1 downto 0);

              datain      :      in     std_logic_vector(width - 1 downto 0);

              ------------------------------------------------------------------------------------

              ------------------------- port b is only for reading -------------------------------

              clkb :      in     std_logic;

              rd           :      in     std_logic;

              addrb      :      in     std_logic_vector(depth - 1 downto 0);

              dataout    :      out   std_logic_vector(width - 1 downto 0)         

              ------------------------------------------------------------------------------------

       );

end entity dualram;

 

architecture Behavioral of dualram is

 

type ram is array(2 ** depth - 1 downto 0) of std_logic_vector(width - 1 downto 0);

signal      dualram          :      ram;

 

begin

 

       process(clka, clkb)

       begin

              if clka'event and clka = '1' then

                     if wr = '0' then

                            dualram(conv_integer(addra)) <= datain;

                     end if;

              end if;

       end process;

      

       process(clkb)

       begin

              if clkb'event and clkb = '1' then

                     if rd = '0' then

                            dataout <= dualram(conv_integer(addrb));

                     end if;

              end if;

       end process;

 

end Behavioral;

-----------------------------------------------------------------------------------------------------------

抓个后仿真的图形吧,需要testbench的投票留言。另外今天还发现前仿真的时候可以用generic传递参数,而后仿真的时候就不能用generic传递参数了,Modelsim会报错“No default binding for component at”。后来想了一下确实应该是这样的,因为后仿真的时候电路都已经布局布线完成了,还有什么参数需要generic传递呀?

点击看大图

 

今天就到这里吧,大家赶快给我投票啊,吼吼!欢迎访问skycanny的笔记(副站)

 
 
  • 标签:FIFO VHDL 双口RAM 
  •  
    Re:同步FIFO之VHDL描述4
    [ 2007-7-25 20:55:00 | By: 社会主义大学生(游客) ]
     
    社会主义大学生(游客)前辈您好:
    我现在正在参加全国 电子设计大塞,听说使用CPLD或FPGA得分会高一些,但是我的EDA基础比较差,想问以下怎么样才能在尽量段的时间掌握一些比较实用的EDA技术? 谢谢!
     
    个人主页 | 引用 | 返回 | 删除 | 回复
     
     
    2个时钟都出来了,还同步
    [ 2007-6-5 16:24:00 | By: 什么玩易儿(游客) ]
     
    什么玩易儿(游客)同步个毛啊
     
    个人主页 | 引用 | 返回 | 删除 | 回复
     
    发表评论:
    载入中...