【发布时间】:2014-04-30 20:51:21
【问题描述】:
我对 VHDL 不是很好,我真的不明白为什么我的代码不能工作。我需要一个 NCO,找到一个可以工作的程序并重新设计它以满足我的需要,但我发现了一个错误:每个完整的周期都有一个空白周期。
程序将参数步骤(在下一个样本之间跳转)和时钟作为触发器。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL; --try to use this library as much as possible.
entity sinwave_new_01 is
port (clk :in std_logic;
step :in integer range 0 to 1000;
dataout : out integer range 0 to 1024
);
end sinwave_new_01;
architecture Behavioral of sinwave_new_01 is
signal i : integer range 0 to 1999:=0;
type memory_type is array (0 to 999) of integer range 0 to 1024;
--ROM for storing the sine values generated by MATLAB.
signal sine : memory_type :=(long and boring array of 1000 samples here);
begin
process(clk)
begin
--to check the rising edge of the clock signal
if(rising_edge(clk)) then
dataout <= sine(i);
i <= i+ step;
if(i > 999) then
i <= i-1000;
end if;
end if;
end process;
end Behavioral;
我该怎么做才能摆脱那个零?它出现在每个完整周期 - 每(1000/步)脉冲。它不应该在那里,它弄乱了我的 PWM ......
据我了解,当入口处应用时钟的正沿时,整个块(dataout 发生变化,增加,if i>999 then i<=i-1000)执行......
但它看起来需要一个额外的优势,我不知道,重新加载它?代码是按顺序执行的,还是在时钟到达时测试所有条件?我是否伸到桌子外面,这就是为什么我在那个特定的脉冲中得到零?程序/不应该/这样做,据我了解 if 语句,还是 VHDL 是 VHDL 并再次做奇怪的事情。
如何修复此错误?我想我可以每 1k/步脉冲添加一个额外的时钟滴答,但这是一种解决方法,而不是真正的解决方案。提前感谢您的帮助。
【问题讨论】:
标签: loops if-statement process vhdl