【问题标题】:VHDL Clock or Trigger Upscaler DelayVHDL 时钟或触发升频器延迟
【发布时间】:2015-03-13 22:25:32
【问题描述】:

我正在开发 FPGA 上的控制算法,但我不能声称对 VHDL 有经验。我需要的一个功能是一种“触发升频器”,所以我想增加触发频率而不是降低它。

这里有一个解释:

我得到一个 50 MHz 的系统 clk,并得到一个 1 kHz 频率的 1 个 clk 周期的触发脉冲,因此每个 ms 一个。这个触发器是某些微积分的开始,它必须运行得比这更快。所以我想知道我是否可以生成一个 10 kHz 的新触发器。这是我到目前为止的基本代码:

  calc_prescaler: process

 begin
  wait until rising_edge(clk);

  -- When a new trig appears, send 1 tick and reset counters
  if trig_in = '1' then
     cnt_clk    <= (others => '0');
     cnt_active <= '1';
     trig_out <= '1';
     trig_count <= (others => '0');
  else 
     trig_out <= '0';

     -- Safety feature: Do not send more ticks than estimated
     -- Useful in case trig_in freezes
     if trig_count > par_max - 1 then
        cnt_active <= '0';
        trig_count <= (others => '0');
     end if; 

     if cnt_active = '1' then
        cnt_clk <= cnt_clk + 1; 
     end if;

     -- If Counter reaches desired values, send 1 tick and increase tick counter
     if cnt_clk = par_fac - 1 then
        trig_count <= trig_count + 1;
        trig_out <= '1';
        cnt_clk <= (others => '0');
     end if; 
  end if; 


  -- Reset
  if res_n = '0' then   

    trig_out        <= '0';

    cnt_clk         <= (others => '0');
    trig_count      <= (others => '0');
    cnt_active      <= '0';                 

  end if;

有两个变量,par_fac 是期望(更高)触发频率与系统 clk 之间的比率,par_max 是如果没有新的 trig_in 时 trig_out 上的滴答数。

目前对我有用,但问题是两个触发器不同步,有 1 个 clk 周期的延迟。

您对如何修改我的方法有任何建议吗?欢迎任何实施方式,我的唯一要求是: - trig_in 和 trig_out 之间没有延迟 - 如果 trig_in 滴答声停止,则没有 trig_out 滴答声

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    在任何时序逻辑中,输出总是相对于输入延迟一个时钟周期。这意味着您无法为流程内的每个触发器输入生成第一个刻度。

    if trig_in = '1' then
        cnt_clk    <= (others => '0');
        cnt_active <= '1';
        --trig_out <= '1'; don't do this
        trig_count <= (others => '0');
    

    对于剩余的滴答声,只需使用较低的计数器值提前一个时钟周期生成它们:

    if cnt_clk = par_fac - 1 then
       trig_count <= trig_count + 1;
       --trig_out <= '1'; don't do this
       cnt_clk <= (others => '0');
    end if;
    -- instead:
    if cnt_clk = par_fac - 2 then
        trig_out <= '1';
    end if;
    

    然后,在进程之外,无论您以前使用过trig_out,现在都使用trig_in or trig_out

    【讨论】:

    • 太棒了!这显然有效!非常感谢!我刚试过。但与其降低计数器值 (par_fac-2),不如使用 1 而不是 0 来初始化计数器。否则后面的滴答声将过早发送一个 clk 周期。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    相关资源
    最近更新 更多