这是刚开始学习FPGA时候,积累的一点资料。
具体如下,其实作者强调了在用FPGA做设计的时候,要注意同步设计,盲目的使用
信号做时钟,在时序分析上有很大问题,隐含着很大风险。
来到本论坛后发现一些同仁提出上升沿和下降沿计数的问题,工作中也碰到一些同事问及此问题。现在我把我多年来一直采用的办法奉上,但愿对初学者有所帮助。
以一个最简单的计数器为例:
Port(
      clock:in  std_logic;
      pulse:in  std_logic;
      q:    out std_logic_vector(3 downto 0)
    );
--q输出为对pulse跳变沿的递增计数。clock为系统高速时钟。
Process(clock) begin
  if rising_edge(clock) then
    dly1pul <= pulse;
    dly2pul <= dly1pul;
  end if;
End process;
en <= dly1pul and not dly2pul;  --上升沿
--en <= not dly1pul and dly2pul;--下降沿
--en <= dly1pul xor dly2pul;    --上升沿和下降沿
Process(clock) begin
  if rising_edge(clock) then
    if en = '1' then
      cnt <= cnt + 1;
    end if;
  end if;
End process;
q <= cnt;
我看到的一些设计中,动辄采用某一信号作为时钟,应该说这种做法是欠妥的。因为不是全局时钟的时钟信号最大扇出是有限的,其很难保证时钟延时应小于信号延时的基本要求。当遇到要对某个信号的跳变沿处理时,建议采用上述小例子中en信号的处理办法。