问题描述
|
我需要检查公共汽车活动直到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;
结束过程
解决方法
通常,找出您的时钟速率有多少个时钟周期4us。
更好的是,让VHDL为您完成工作。如果您的设计有一个全局包,其中的常量是一个时钟周期:
constant clock_period : time := 125 ns;
然后,您可以执行以下操作:
constant bus_timeout_for_example : natural := 4 us / clock_period;
然后,在您的过程中创建一个整数变量。在每个时钟周期将其递增。当它达到您上面计算的数字时,这就是您4 us的终点。
编辑:
现在,您已经发布了一些注释代码:
不要使用std_logic_vectors进行算术运算-http://parallelpoints.com/node/3
使整个过程与一个clk信号同步(即dec_clk是灵敏度列表中的全部)-如果您需要检测其他信号上的“边缘”,请存储它们并比较下一个时钟周期以查看它们是否\已经改变了。 * _edge在整个设计中调用了多个信号,这会带来麻烦(作为新手)。那么gapen
可以是一个过程中的变量。并检查“已计时”部分中的gapen
。
使用如我所描述的那样计算的变量和整数类型-然后可以与数字比较:if gapcnt = bus_timeout then