如何在 for 循环中放入 2 秒计数器
我想在我的 for 循环中有一个 2 秒计数器,这样每次迭代之间就有 2 秒的间隙。我试图有一个移动的 LEDR 显示
代码:
parameter n =10;
integer i;
always@(*)
begin
for(i=0;i<n;i=i+1)
begin
LEDR[i]=1'b1;
//2 second counter here
end
end
I want to have a 2 sec counter in my for loop such that there is a gap of 2 seconds between every iteration.I am trying to have a shifting LEDR Display
Code:
parameter n =10;
integer i;
always@(*)
begin
for(i=0;i<n;i=i+1)
begin
LEDR[i]=1'b1;
//2 second counter here
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要的功能是什么?我假设:每 2 秒切换一次亮起的 LED,保持所有其他 LED 关闭? “滑动 LED”...
另外,我假设您的目标是 FPGA 类型的板。
FPGA世界里不存在免费的“等待X时间”。你想要做什么的关键是计算时钟周期。您需要知道该块所使用的时钟的时钟频率。一旦知道了这一点,您就可以计算在需要采取“操作”之前需要计数多少个时钟上升沿。
我推荐两个流程。在其中一个中,您将观察时钟的上升沿,并运行足够大小的计数器,使其每两秒翻转一次。每当你的计数器为 0 时,你就为一个时钟周期设置一个“标志”。
另一个进程将简单地监视“标志”的出现。当出现该标志时,您可以切换打开的 LED,并关闭所有其他 LED。
What is your desired functionality? I assume: shifting which LED is on every 2 seconds, keeping all the other LEDs off? "Sliding LED"...
Also, I am assuming your target is an FPGA-type board.
There is no free "wait for X time" in the FPGA world. The key to what you are trying to do it counting clock cycles. You need to know the clock frequency of the clock that you are using for this block. Once you know that, then you can calculate how many clock rising edges you need to count before "an action" needs to be taken.
I recommend two processes. In one, you will watch rising edge of clock, and run a counter of sufficient size, such that it will roll over once every two seconds. Every time your counter is 0, then you set a "flag" for one clock cycle.
The other process will simply watch for the "flag" to occur. When the flag occurs, you shift which LED is turned on, and turn all other LEDs off.
我认为这个模块实现了 Josh 所描述的内容。该模块将创建两个寄存器,一个计数器寄存器(counter_reg)和一个移位寄存器(leds_reg)。计数器寄存器将在每个时钟周期递增一次,直到翻转。当它翻转时,“tick”变量将等于1。发生这种情况时,移位寄存器将向左旋转一个位置。
I think this module implements what Josh was describing. This module will create two registers, a counter register (counter_reg) and a shift register (leds_reg). The counter register will increment once per clock cycle until it rolls over. When it rolls over, the "tick" variable will be equal to 1. When this happens, the shift register will rotate by one position to the left.