在帖子“上升沿与下降沿触发小论”中,采用了高速时钟提取低速时钟跳变沿的办法实现了低速时钟上升沿和下降沿触发的问题。在论坛仍见到有设计者提出双沿触发的问题,实现类似于DDR双沿跳变技术。本文给出一个用VHDL实现的双沿跳变计数器DDRcnt,旨在给出设计双沿触发的一个思路。DDRcnt中用到一个上升沿计数器rcnt和一个下降沿计数器fcnt,双沿计数器cnt通过clock在rcnt和fcnt之间进行选择。
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
Entity DDRcnt is Port(
clock : in std_logic;
q : out std_logic_vector(3 downto 0)
);
End DDRcnt;
Architecture myFavor of DDRcnt is
Signal cnt,rcnt,fcnt : std_logic_vector(3 downto 0);
Begin
q <= cnt;
cnt <= rcnt when clock = '1' else
fcnt;
Process(clock) begin
if rising_edge(clock) then
rcnt <= cnt + 1;
end if;
End process;
Process(clock) begin
if falling_edge(clock) then
fcnt <= cnt + 1;
end if;
End process;
End myFavor;
双沿触发采用了时钟馈入数据逻辑的办法,在FPGA的设计中是不提倡的,我没有做过ASIC,也许在ASIC设计中建议采用这种办法。