最新日志

发表于:2007-3-2 19:01:07
标签:双口RAM  VHDL  testbench  

8

双口RAM的testbench

需要的朋友可以参考,我是用Modelsim仿真的

-----------------------------------------------------------------------------------------------------------
-- Designer  : skycanny
-- Date   : 2007-2-3
-- Description : This VHDL file is a testbench file designed to simulate a dual port ram


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

entity dualram_tb is
end entity;

architecture Behavioral of dualram_tb is
constant delay : time  := 3 ns;
constant width : positive := 16;
constant depth : positive := 8;  
signal clka : std_logic;
signal wr  : std_logic;
signal addra : std_logic_vector(7 downto 0)  := "00000000";
signal datain : std_logic_vector(15 downto 0) := x"0002";

signal clkb : std_logic;
signal rd  : std_logic;
signal addrb : std_logic_vector(7 downto 0) := "00000000";
signal dataout : std_logic_vector(15 downto 0);

component dualram
-- 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 component;

begin
 ----------------------------------------------------------------------------------------
 tb : dualram
-- generic map
-- (
--  width,
--  depth
-- )
 port map
 (
  clka => clka,    
  wr  => wr,  
  addra => addra, 
  datain => datain, 
  --------=> --------
  --------=> --------
  clkb => clkb,    
  rd  => rd,  
  addrb => addrb, 
  dataout => dataout 
 );
 ----------------------------------------------------------------------------------------
 
 ----------------------------------------------------------------------------------------
 process
 begin
  clka <= '0';
  wait for 13 ns;
  loop
   clka <= not clka;
   wait for 10 ns;
  end loop;
 end process;
 
 process
 begin
  clkb <= '0';
  wait for 12 ns;
  loop
   clkb <= not clkb;
   wait for 7 ns;
  end loop; 
 end process;

 process
 begin
  wr <= '1';
  rd <= '1';
  wait for 24 ns;
  wr <= '0';
  wait for 60 ns;
  rd <= '0';
  wait for 300 ns;
  wr <= '1';
  wait;
 end process;
 
 process(clka)
 begin
  if clka'event and clka = '1' then
   if wr = '0' then
    addra <= addra + 1 after delay;
   end if;
   datain<= datain + 1 after delay;
  end if;
 end process;
 
 process(clkb)
 begin
  if clkb'event and clkb = '1' then
   if rd = '0' then
    addrb <= addrb + 1 after delay;
   end if;
  end if;
 end process;
end Behavioral;

点击此处查看原文 >>

系统分类: CPLD/FPGA   |    用户分类:    |    来源: 原创

评论(10) | 阅读(1911)
发表于:2007-2-5 22:39:36
标签:ripple  FIFO  VHDL  

13

感谢ripple的回复和建议

感谢ripple的回复和建议!终于看到有人回复了,心里特别的高兴,我以为我写的东西都是垃圾。另外ripple的建议确实很好,尤其是半满半空,读写指针时序关系等。当时写这个的初衷主要是为了描述一个同步FIFO的模型,所以考虑的还不是特别的全面,尤其对于半空半满这个当时根本就没有考虑。关于“正逻辑”,尤其复位信号,因为DFF一般都提供一步复位接口,所以我喜欢低电平的复位信号,至于内部接口用正逻辑,尤其是读写控制信号,当时也只是根据自己的习惯就用了“负逻辑”。Ripple的这些建议如果以后有机会再增加和更改。

       我主要使用Quartus II 6.0对代码进行了综合和布局布线,使用Modelsim6.0进行功能和时序仿真,布局布线选用的器件是Cyclone II 系列的EP2C5T144C8,没有添加任何约束。下面给出有关综合布局布线以及时序分析的RTL和报告。

点击看大图

 

                 图1 RTL顶层图

1 RTL顶层图,可以对照我刚开始画的原理框图(见<同步FIFOVHDL描述1>

 

点击看大图

 

                    2 Fitter报告概要

从图2Fitter报告概要中可以看出,所用FIFO所用RAMFPGA内部的RAM资源

 

 

点击看大图

 

              图3 时序分析概要报告

       布局布线时没有进行任何时序约束,从图3可以看出,这种同步FIFOVHDL描述可以在EP2C5T144C8运行在150MHz(不知道这样看对不对)

       最后再次感谢ripple!

       欢迎大家访问skycanny的笔记(副站)

 

 

 

 

 

 

点击此处查看原文 >>

系统分类: CPLD/FPGA   |    用户分类:    |    来源: 原创

评论(9) | 阅读(1269)
发表于:2007-2-4 20:37:23
标签:FIFO  VHDL  

8

同步FIFO之VHDL描述5(大结局)

同步FIFOVHDL描述5

       昨天晚上把所有的模块描述都完成了,同时还完成了双端口RAM的后仿真,从目前的仿真结果来看,应该没有什么问题。今天的任务就是把这些模块组装起来并完成前后仿真,这样同步FIFOVHDL描述就算全部完成了。按照前面的思路和框图,把这些模块组装起来应该很简单,下面就直接给出VHDL代码。当然组装的过程还要排查除了双口RAM以外电路的代码描述有没有问题,如果有问题的话就就地改正了,呵呵。

       在代码的集成和仿真的时候还真发现了一些问题,主要包括数据的寄存,以及空满状态判断上,最后的代码使用Quartus II6.0综合和布局布线,选用的是CycloneII系列的器件,并用Modelsim进行了功能仿真和时序仿真,两种仿真均通过。下面主要是集成的定层文件和时序仿真图(图1,图2,图3,图4,图5

 

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

-- Designer            :      skycanny

-- Date                  :      2007-2-4

-- Description :      Synchronous FIFO created by VHDL

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

 

entity sfifo is

       generic

       (

              width      :      positive   := 16;

              depth      :      positive   := 8

       );

       port

       (

              clk          :      in     std_logic;

              rst          :      in     std_logic;

              wq          :      in     std_logic;

              rq           :      in     std_logic;

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

              q            :      out   std_logic_vector(width - 1 downto 0);

              empty     :      out   std_logic;

              full   :      out   std_logic

       );

end entity sfifo;

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

architecture structure of sfifo is

signal      empty_t   :      std_logic;

signal      full_t       :      std_logic;

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

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

signal      wr          :      std_logic;

signal      rd           :      std_logic;

component write_pointer

       generic

       (

              depth      :      positive   :=8  

       );

       port

       (

              clk          :      in     std_logic;

              rst          :      in     std_logic;

              wq          :      in     std_logic;

              full          :      in     std_logic;

              wr          :      out   std_logic;

              wr_pt      :      out   std_logic_vector(depth - 1 downto 0)         

       );

end component;

component read_pointer

       generic

       (

              depth      :      positive   :=8  

       );

       port

       (

              clk          :      in     std_logic;

              rst          :      in     std_logic;

              rq           :      in     std_logic;

              empty     :      in     std_logic;

              rd           :      out   std_logic;

              rd_pt       :      out   std_logic_vector(depth - 1 downto 0)         

       );

end component;

 

component judge_status

       generic

       (

              depth      :      positive :=8

       );

       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 component;

component dualram

       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 component;

begin

       empty <= empty_t;

       full <= full_t;

       u0    :      dualram

       generic map

       (

              width => width,

              depth => depth

       )

       port map

       (

              --------=>

        clka        => clk,

        wr          => wr,

        addra      => wr_pt,

        datain      => data,

        --------=>

        --------=>

        clkb => clk,

        rd           => rd,

        addrb      => rd_pt,

        dataout    => q

       );

u1    :      write_pointer

       generic map

       (

              depth => depth

       )

       port map

       (

              clk          => clk,

           rst          => rst,

           wq          => wq,

           full          => full_t,

           wr          => wr,

           wr_pt      => wr_pt

       );

      

       u2    :      read_pointer

       generic map

       (

              depth => depth

       )

       port map

       (

              clk          => clk,   

           rst          => rst,

           rq           => rq,

           empty     => empty_t,

           rd           => rd,

           rd_pt       => rd_pt                       

       );

      

       u3    :      judge_status

       generic map

       (

              depth => depth

       )

       port map

       (

              clk          => clk,

           rst          => rst,

           wr_pt      => wr_pt,

           rd_pt       => rd_pt,

           empty     => empty_t,

           full   => full_t 

       );

       end structure;

 

点击看大图

                                                                

                                                          图1 时序仿真图全貌

 

点击看大图

 

                                                                2写数据到空的FIFO

 

点击看大图

                                                                                                                               3 FIFO被写满

 

点击看大图

                                                                                                                             4 FIFO被读空

 

点击看大图

                                                                       

                                                                   图5 同时对FIFO进行读写

 

从上面的时序仿真图来看,同步FIFOVHDL描述满足设计要求,可以在需要应用到的地方直接调用,同时支持参数话的调用,以满足不同的应用需求。大家如果有什么关于这个FIFO实现的问题可以直接提问,我回尽快回复,另外不要忘了投票哟。最后欢迎大家访问skycanny的笔记(副站)

 

 

 

 

 

 

点击此处查看原文 >>

系统分类: CPLD/FPGA   |    用户分类:    |    来源: 原创

评论(6) | 阅读(1730)
发表于:2007-2-4 0:00:06
标签:FIFO  VHDL  双口RAM  

6

同步FIFO之VHDL描述4

       同步FIFOVHDL描述4

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