2015-03-13 54 views
0

我正在FPGA上开发控制算法,但我不能声称有VHDL的经验。我需要的一种功能是一种'Trigger Upscaler',所以我想增加触发频率而不是减少触发频率。VHDL时钟或触发器上标延迟

下面是一个说明:

enter image description here 我得到50MHz的系统CLK和得到了1个CLK周期的触发脉冲与1千赫频率,从而各一个毫秒。这个触发器是某些微积分运算的开始,它必须比这个运算更快。所以我想知道我是否可以用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与是作为上trig_out蜱数目的期望(高)的触发频率和系统CLK和par_max之间的比率,如果没有新的TRIG_IN。

对我来说迄今为止,但问题是,两个触发器不同步,有1个时钟周期的延迟。

你有什么建议如何修改我的方法?实现任何方式是值得欢迎的,唯一的要求我必须是: - TRIG_IN和trig_out 之间没有延迟 - 如果TRIG_IN蜱停止

回答

0

在任何顺序逻辑输出总是由一个时钟周期相对于延迟的无trig_out蜱到输入。这意味着您不能为流程内的每个触发输入生成第一个记号。

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之外。

+0

太棒了!这显然有效!非常感谢!我只是试了一下。但是不应该降低计数器值(par_fac-2),而应该用1而不是0来初始化计数器。否则,稍后的滴答将过早发送一个clk循环。 – Clemens 2015-03-13 14:51:54