VHDL D触发器:
一、同步置位复位的D触发器。
library ieee;
use ieee.std_logic_1164.all;
entity sync_rsdff is
port(d,clk:in std_logic;
set : in std_logic;
reset: in std_logic;
q,qb : out std_logic);
end sync_rsdff;
architecture rtl_arc of sync_rsdff is
process(clk)
begin
if (clk'event and clk='1') then
if(set='0' and reset='1') then
q<='1';
qb<='0';
elsif (set='1' and reset='0') then
q<='0';
qb<='1';
else
q<=d;
qb<=not d;
end if;
end process;
end rtl_arc;
二、 异步复位的D触发器,是将复位信号直接连接到触发器的复位端,而同步复位是指当复位信号有效时,一个时钟信号将“0”锁进触发器。总之,同步和异步是相对于钟信号而言的,同步指与时钟信号同步,异步是指与时钟信号异步。
以时钟信号clk,输入信号D,复位信号clr作为进程的敏感信号。以复位信号clr=“0”作为D触发器的先决工作条件,指定时钟信号clk的上升沿触发还是下降沿触发。在本例中,如果复位信号为“1”,则输出Q为“0” 当复位信号为“0”,且时钟的上升沿到来时,Q为“D”(输入信号电平);当时钟的上升沿未到来时,则等待它的到来,直到时钟信号上升沿到来为止。
程序设计
library ieee;
use ieee.std_logic_1164.all;
entity dff2 is
port(D,clk,clr:in std_logic;
Q:out std_logic);
――定义输入、输出端口
end entity dff2;
architecture one of dff2 is
begin
process(clk,D,clr) ――进程敏感信号
begin
if clr='1' then
Q<='0';
Elsif clk'event and clk='1' then
――时钟触发状态
Q<=D;
end if;
end process;
end architecture one;