问题描述
我需要在每个时钟周期增加我的计数器,我的第一个想法是在每个时钟周期设置一个标志 count
begin
count<='1';
wait for -- ns;
count<='0';
wait for -- ns;
end process;
有聪明的解决方案吗?
解决方法
您提供的代码不会通过综合。
如果这是用于模拟输入信号的测试平台,您可以执行以下操作
count <= not count after period ns;
其中“周期”代表内部时钟的上升沿
如果您尝试合成此代码,则需要为该过程包含一个时钟
process ( internal_clk )
begin
if ( rising_edge ( internal_clk ) ) then
count <= not count;
end if;
end process;
如果最终你只是想增加一个计数器,为什么不直接增加计数器呢?
process ( internal_clk )
begin
if ( rising_edge ( internal_clk ) ) then
counter <= counter + 1;
if ( counter = max_counter ) then
counter <= 0;
end if;
end if;
end process;
请记住,这样做会导致单个时钟周期的延迟,因为这些寄存器只会更新时钟的每个上升沿。