在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1942|回复: 0

讨论: 2 个 D-Flip Flop 的 区别 , VHDL

[复制链接]
发表于 2008-8-14 23:11:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
我写了2种DFF进行比较, 代码如下,本已为simulate 的结果一样,可是事实并非如此。
付上testbench , 有兴趣的朋友可以试一试。
大家讨论一下2 种代码的区别及仿真的结果吧。

-----------------------------------------------------------------
--Type 0 dff
--file name: dff_enable.vhd
-----------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use work.all;
entity dff_enable is
port(
clk : in std_logic;
reset  : in std_logic;
en : in std_logic;
d : in std_logic;
q: out std_logic
);
end dff_enable;
architecture rtl of dff_enable is
signal q_reg: std_logic;
signal q_next: std_logic;
begin
     -- DFF
     process (clk, reset)
     begin
     if(reset = '1') then
        q_reg <= '0';
     elsif (clk = '1' and clk'event ) then
    q_reg <= q_next;
     end if;
     end process;
     --next state
     q_next <=  d when en='1' else
                q_reg;
     --output logic
     q <= q_reg;
end rtl;

-----------------------------------------------------------------
--Type 1 dff
--file name: dff_enable1.vhd
-----------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use work.all;
entity dff_enable1 is
port(
clk : in std_logic;
reset  : in std_logic;
en : in std_logic;
d : in std_logic;
q: out std_logic
);
end dff_enable1;
architecture rtl of dff_enable1 is
begin
process (clk, reset)
  begin
  if(reset = '1') then
    q <= '0';
  elsif (clk = '1' and clk'event
         and en = '1') then
    q <= d;
  end if;
end process;
end
rtl;

-----------------------------------------------------------------
--testbench
--file name: dff_enable_TB.vhd
-----------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity dff_enable_TB is  -- entity declaration
end dff_enable_TB;
architecture TB of dff_enable_TB is
    signal T_d:  std_logic;
    signal T_clk: std_logic;
    signal T_reset: std_logic;
    signal T_en: std_logic;
    signal T_q: std_logic;
    signal T_q1: std_logic;
   
    component dff_enable
    port(clk : in std_logic;
         reset  : in std_logic;
         en : in std_logic;
         d : in std_logic;
         q: out std_logic
       );
    end component;
        
    component dff_enable1
    port(clk : in std_logic;
         reset  : in std_logic;
         en : in std_logic;
         d : in std_logic;
         q: out std_logic
       );
    end component;
   
begin
    U_DFF: dff_enable port map (T_clk,T_reset,T_en,T_d, T_q);
    U_DFF1: dff_enable1 port map (T_clk,T_reset,T_en,T_d, T_q1);
        -- concurrent process to offer clock signal
    process
    begin
      T_clk <= '0';
         wait for 5 ns;
      T_clk <= '1';
         wait for 5 ns;
    end process;   
   
    process
     
    begin
        
       T_d <= '1';
       T_reset <= '1';
       T_en <= '1';
       wait for 6 ns;
       assert (T_q='0') report "Error1!" severity error;
       T_reset <= '0';   
       T_d <= '0';
       wait for 5ns;
       assert (T_q='0') report "Error1!" severity error;
      
       T_d <= '1';
       wait for 5ns;
       assert (T_q='1') report "Error1!" severity error;
      
       T_en <= '0';
       T_d <= '0';
       wait for 5ns;
       assert (T_q='1') report "Error1!" severity error;
      
      
      
    end process;
   
   
   
end TB;
-----------------------------------------------------------------
configuration CFG_TB of dff_enable_TB is
for TB
end for;
end CFG_TB;
-----------------------------------------------------------------

[ 本帖最后由 lalabu 于 2008-8-14 23:12 编辑 ]

dff.rar

1.29 KB, 下载次数: 7 , 下载积分: 资产 -2 信元, 下载支出 2 信元

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-9-27 10:22 , Processed in 0.021429 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表