集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 3618|回复: 8

D触发器的问题 我用VHDL编写的维阻DFF

[复制链接]
encounter 发表于 2010-6-28 00:25:09 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-7-3 06:41 编辑

我用VHDL编写的维阻DFF。
-- dff.vhd
library IEEE;
use IEEE.Std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity dff is
port(
  D: instd_logic;
  CP : in std_logic;
  Sd: in std_logic;
  Rd: in std_logic;
  Q : out std_logic;
  Q_fan : out std_logic
  );
end dff;
architecture dff_a of dff is
  signal q1 : std_logic;
  signal q2 : std_logic;
begin
process(CP,Sd,Rd)
begin
  if (Sd='0') and (Rd='1') then
   q1<='1';
   q2<='0';
  elsif (Sd='1') and (Rd='0') then
   q1<='0';
   q2<='1';
  elsif rising_edge(CP) then
  
   q1<=D;
   q2<=not D;

  end if;
Q<=q1;
Q_fan<=q2;
end process;
end dff_a;

可是仿真结果不对
请大家看看哪儿出了问题
谢谢!
ups 发表于 2010-6-28 01:53:16 | 显示全部楼层
学校后天开网,目前在网吧,没有quartus 软件,到时候再看看
ngtim 发表于 2010-6-28 03:32:59 | 显示全部楼层
复制你的程序在quartus运行,直接用波形图方式进行的仿真,选择的器件是EP1C3T1448,有大概8ns的延迟,如果你的时钟周期很小如10ns,这样波形就延迟了一个大半个周期,所以看起来感觉不对,我也不很明白此延迟是由器件造成的还是由quartus自带的波形仿真不准确造成的?望各位大侠指点,谢谢!<br>
<br>
我按照类似于你的程序用verilog编写并在ISE环境下运行,然后用modesim仿真,波形没有延迟<br>
程序如下:<br>
module dff_test(clk,d,clear,set,q,q_fan);<br>
input clk,d,set,clear;<br>
output q,q_fan;<br>
<br>
reg q1,q2;<br>
assign&nbsp;&nbsp;q = q1;<br>
assign&nbsp;&nbsp;q_fan = q2;<br>
<br>
always @ (posedge clk or negedge clear or negedge set)<br>
begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; if(!set)<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q1 &lt;= 1'b1;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q2 &lt;= 1'b0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp; else if(!clear)<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q1 &lt;= 1'b0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q2 &lt;= 1'b1;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;q1 &lt;= d;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;q2 &lt;= ~d;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end<br>
end<br>
<br>
endmodule<br>
<br>
仿真程序如下:<br>
`timescale&nbsp;&nbsp;1ns / 1ns <br>
module dff_test_tp;<br>
reg clk;<br>
reg d;<br>
reg clear,set;<br>
wire q,q_fan;<br>
parameter step = 50;<br>
<br>
dff_test dff_test_inst(<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .clk(clk),<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .d(d),<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .clear(clear),<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .set(set),<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .q(q),<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; .q_fan(q_fan)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; );<br>
<br>
always <br>
#(step/10) clk = ~clk;<br>
<br>
always<br>
#(step/5)&nbsp;&nbsp;d&nbsp; &nbsp;= ~d;<br>
<br>
initial <br>
begin<br>
&nbsp; &nbsp;clk = 1'b0;<br>
&nbsp; &nbsp;set = 1'b1;<br>
&nbsp; &nbsp;clear = 1'b1;<br>
&nbsp; &nbsp;d&nbsp; &nbsp;= 1'b1;&nbsp;&nbsp;<br>
&nbsp; &nbsp;#(step/5) set = 1'b0;<br>
&nbsp; &nbsp;#(step/2) set = 1'b1;<br>
&nbsp; &nbsp;#step&nbsp; &nbsp;&nbsp;&nbsp;clear = 1'b0;<br>
&nbsp; &nbsp;#(step/2) clear = 1'b1; <br>
end<br>
endmodule
tim 发表于 2010-6-28 03:52:05 | 显示全部楼层
我也直接画的波形,感觉不对<br>
我用modesim试试
HANG 发表于 2010-6-28 05:40:58 | 显示全部楼层
我找到错误的原因了!<br>
去掉信号:<br>
signal q1 : std_logic;<br>
&nbsp; &nbsp; signal q2 : std_logic;<br>
这些信号会造成延时!<br>
程序改为:<br>
-- dff.vhd<br>
library IEEE;<br>
use IEEE.Std_logic_1164.all;<br>
use IEEE.std_logic_unsigned.all;<br>
entity dff is<br>
port(<br>
&nbsp; &nbsp;&nbsp; &nbsp;D: in&nbsp;&nbsp;std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;CP : in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;Sd: in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;Rd: in std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;Q : out std_logic;<br>
&nbsp; &nbsp;&nbsp; &nbsp;Q_fan : out std_logic<br>
&nbsp; &nbsp;&nbsp; &nbsp;);<br>
end dff;<br>
<br>
architecture dff_a of dff is<br>
<br>
<br>
begin<br>
process(CP,Sd,Rd)<br>
&nbsp;&nbsp;begin<br>
&nbsp; &nbsp; if (Sd='0') and (Rd='1') then<br>
&nbsp; &nbsp;&nbsp; &nbsp; Q&lt;='1';<br>
&nbsp; &nbsp;&nbsp; &nbsp; Q_fan&lt;='0';<br>
&nbsp; &nbsp; elsif (Sd='1') and (Rd='0') then<br>
&nbsp; &nbsp;&nbsp; &nbsp; Q&lt;='0';<br>
&nbsp; &nbsp;&nbsp; &nbsp; Q_fan&lt;='1';<br>
&nbsp; &nbsp; elsif rising_edge(CP) then<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q&lt;=D;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Q_fan&lt;=not D;<br>
<br>
<br>
&nbsp; &nbsp; end if;<br>
<br>
<br>
end process;<br>
<br>
end dff_a;<br>
<br>
然后用Modesim编写测试文件仿真。
CHA 发表于 2010-6-28 07:28:43 | 显示全部楼层
谢谢,又学到东西了,非常感谢
CTT 发表于 2010-6-28 07:37:12 | 显示全部楼层
再次感谢,看了一下,挺好的,并且运行了一下
chenhaoyumax 发表于 2011-5-27 10:27:07 | 显示全部楼层
新手请教~dff在vhdl中有特别的意思么?
chenhaoyumax 发表于 2011-5-27 10:27:11 | 显示全部楼层
新手请教~dff在vhdl中有特别的意思么?
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-23 13:11 , Processed in 0.079885 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表