如何在VHDL中以8MHz时钟数4us?
我需要检查 4us 之前的总线活动。所以我需要算一下。时钟为8MHz。请帮助我。
下面的代码可以工作吗?
process(sync_dw_reg,data_edge)
begin
if(rst_n='1' or data_edge='1' )then
gapen<='0';
elsif(falling_edge(sync_dw_reg))then
gapen<='1';
end if;
end process;
process(dec_clk,sync_dw_reg,rst_n,gapen)
begin
if(rst_n='1')then
gapcnt<="000000";
elsif(gapen='1')then
if(dec_clk'event and dec_clk='1')then
if(gapcnt="111111")then
gaperr_bit<='1';
elsif(data_edge='1')then --if this condition comes within 4us then no setting of error
gaperr_bit<='0';
gapcnt<="000000";
else gapcnt<=gapcnt+'1';
end if;
end if;
end if;
结束进程;
I need to check the bus activity till 4us. So I need to count it. And clock is 8MHz. Please help me in this.
Will the following code work?
process(sync_dw_reg,data_edge)
begin
if(rst_n='1' or data_edge='1' )then
gapen<='0';
elsif(falling_edge(sync_dw_reg))then
gapen<='1';
end if;
end process;
process(dec_clk,sync_dw_reg,rst_n,gapen)
begin
if(rst_n='1')then
gapcnt<="000000";
elsif(gapen='1')then
if(dec_clk'event and dec_clk='1')then
if(gapcnt="111111")then
gaperr_bit<='1';
elsif(data_edge='1')then --if this condition comes within 4us then no setting of error
gaperr_bit<='0';
gapcnt<="000000";
else gapcnt<=gapcnt+'1';
end if;
end if;
end if;
end process;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,计算出 4us 在您的时钟速率下有多少个时钟周期。
更好的是,让 VHDL 为您完成这项工作。如果您的设计有一个全局包,其中包含一个常量(即时钟周期):
那么您可以执行以下操作:
然后,在进程中创建一个整数变量。每个时钟周期递增它。当它达到你上面计算的数字时,你的 4 我们就结束了。
编辑:
现在您已经发布了一些代码和一些评论:
gapen
。if gearcnt = bus_timeout then
In general, figure out how many clock cycles 4us is at your clock rate.
Even better, get VHDL to do the work for you. If you have a global package for your design with a constant in it which is the clock period:
you can then do:
Then, create an integer variable in your process. Increment it every clock cycle. When it reaches the figure you calculated above, that's the end of your 4 us.
EDIT:
Now you've posted some code some comments:
gapen
can be a variable within the one process. And checkgapen
inside the "clocked" part.if gapcnt = bus_timeout then