在 Vhdl 中创建实时延迟 [英] Creating a real-time delay in Vhdl

查看:27
本文介绍了在 Vhdl 中创建实时延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个设计,其中一个进程在 1 分钟后被激活.

I want to write a design in which , a process gets activated exactly after 1 minute.

我又创建了一个进程来使用计数器增量创建延迟,并切换一个信号,并在必须延迟的进程的敏感度列表中给出该信号.

I have created one more process to create a delay using a counter incrementation, and toggling a signal , and giving that signal in the sensitivity list of the process that has to be delayed.

signal delay_over : std_logic;

process ( delay_over )
begin 
     if clk'event and clk '1' then
         --design
     end if;
end process;

delay:process ( clk )
variable counter : integer := 0;
begin 
--design to create delay
end process;

我应该使用什么值或计数器类型来创建精确的 1 分钟延迟.

What is the value or and type of counter i should use to create a delay of exact 1 minute.

推荐答案

在同步设计(任何带有时钟的设计)中等同于实时延迟就像计数时钟一样简单,或计数使能通过计数时钟生成的时基.

Equating a real time delay in a synchronous design (any design with a clock) is as simple as counting clocks, or counting enables of a time base generated by counting clocks.

例如,假设您需要处理的最小实时单位是 1 秒(也就是说,您永远不需要处理十分之一、毫秒等).您的时基可以是秒.因此您需要弄清楚如何将单个时钟的周期(持续时间)转换为秒.

For example, say the smallest unit of real time you need to deal with is 1 second (that is, you will never need to deal with tenths, milliseconds, etc). Your timebase can then be seconds. So you need to figure out how to convert from the period (duration) of a single clock to a second.

假设您有一个 25MHz 的时钟.这意味着一秒钟有 25e6 个时钟.这意味着您需要数到 25e6(或 (25e6)-1,具体取决于您的设置方式),将计数器重置为零,然后再次开始计数.每当您的计数器达到 0(或 25e6,或计数中的任何其他单个值)时,您可以脉冲使能一个时钟周期.启用是您的秒"时基.

Let's assume you have a 25MHz clock. That means there are 25e6 clocks in a second. That means you need to count up to 25e6 (or (25e6)-1, depending how you set it up), reset the counter back to zero, and begin counting again. Every time your counter reaches 0 (or 25e6, or any other single value in the count), you can pulse an enable for one clock cycle. That enable is your "seconds" timebase.

所有其他逻辑都可以参考秒"时基启用.要创建 10 秒的实时延迟,您只需计算秒时基启用的 10 个脉冲.

All your other logic can be referenced to the "seconds" timebase enable. To create a realtime delay of 10 seconds, you simply need to count 10 pulses of the seconds timebase enable.

这是一个例子的片段,给你一个想法:

Here is a snippet of an example, to give you the idea:

   timebase : process (I_CLK) is
   begin
      if (rising_edge(I_CLK)) then
         counter_1sec_en <= '0';
         if (counter < COUNTS_IN_1_SEC-1) then
            counter <= counter + 1;
         else
            counter_1sec_en <= '1';
            counter         <= (others => '0');
         end if;
      end if;
   end process timebase;

   delay : process (I_CLK) is
   begin
      if (rising_edge(I_CLK)) then
         seconds_delay_done <= '0';
         if (counter_1sec_en = '1') then
            if (seconds_delay < NUM_SECONDS_TO_DELAY-1) then
               seconds_delay <= seconds_delay + 1;
            else
               seconds_delay_done <= '1';
               seconds_delay <= (others => '0');
            end if;
         end if;
      end if;
   end process delay;

此代码段的一些注意事项:

Some notes to go with this snippet:

  • 一切都与您的时钟同步,I_CLK
  • COUNTS_IN_1_SEC 是一个常数,表示您的时钟频率(以 Hz 为单位)
  • counter_1sec_en 每秒脉冲一次,用于单个 I_CLK 周期
  • NUM_SECONDS_TO_DELAY 是您想要延迟的秒数.例如,60 秒.
  • seconds_delay_done 脉冲,延迟完成后一个 I_CLK 周期.
  • 您可能需要更多地控制何时启用/启用延迟,并可能需要控制延迟多少秒(即 NUM_SECONDS_TO_DELAY 可能不是常数).
  • Everything is synchronous to your clock, I_CLK
  • COUNTS_IN_1_SEC is a constant that is your clock frequency in Hz
  • counter_1sec_en pulses once every second, for a single I_CLK cycle
  • NUM_SECONDS_TO_DELAY is some number of seconds you want to delay. For example, 60 seconds.
  • seconds_delay_done pulses for one I_CLK cycle when the delay has completed.
  • You will likely need more control over when to arm/enable the delay, and possibly control over how many seconds to delay (i.e. NUM_SECONDS_TO_DELAY may not be a constant).

在您的情况下,如果您想在 1 分钟后激活"某些内容,您可以使用 seconds_delay_done 启用来启动"您想要开始的任何内容.

In your case, if you want something to be "activated" after 1 minute, you can use the seconds_delay_done enable to "kick off" whatever it is you want to start.

另外,对于不同的问题,请参阅这个几乎相同的答案:https://stackoverflow.com/a/29948250/561560

Also, see this nearly identical answer for a different question: https://stackoverflow.com/a/29948250/561560

这篇关于在 Vhdl 中创建实时延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆