我正在研究 FIR 滤波器,特别是延迟线。x_delayed
被初始化为全零。
type slv32_array is array(natural range <>) of std_logic_vector(31 downto 0);
...
signal x_delayed : slv32_array(0 to NTAPS-1) := (others => (others => '0'));
这不起作用:
x_delayed(0) <= x; -- Continuous assignment
DELAYS : process(samp_clk)
begin
if rising_edge(samp_clk) then
for i in 1 to NTAPS-1 loop
x_delayed(i) <= x_delayed(i-1);
end loop;
end if; -- rising_edge(samp_clk)
end process;
但这确实:
DELAYS : process(samp_clk)
begin
if rising_edge(samp_clk) then
x_delayed(0) <= x; -- Registering input
for i in 1 to NTAPS-1 loop
x_delayed(i) <= x_delayed(i-1);
end loop;
end if; -- rising_edge(samp_clk)
end process;
这个“解决方案”的问题是第一个元素x_delayed
被一个样本延迟了,这是不应该的。(其余代码预计x_delayed(0)
是当前示例)。
我正在使用 Xilinx ISE 13.2,使用 ISim 进行仿真,但这也被证实使用 ModelSim 进行仿真。
是什么赋予了?
编辑:
问题本质上是,即使似乎x_delayed(0)
没有被驱动在里面process
,它是。
在实施了Brian Drummond 的想法后,它完美运行:
x_delayed(0) <= x;
-- Synchronous delay cycles.
DELAYS : process(samp_clk)
begin
-- Disable the clocked driver, allowing the continuous driver above to function correctly.
-- https://stackoverflow.com/questions/18247955/#comment26779546_18248941
x_delayed(0) <= (others => 'Z');
if rising_edge(samp_clk) then
for i in 1 to NTAPS-1 loop
x_delayed(i) <= x_delayed(i-1);
end loop;
end if; -- rising_edge(samp_clk)
end process;
编辑2:
我接受了OllieB 的建议来摆脱for
循环。我不得不改变它,因为我x_delayed
的索引来自(0 to NTAPS-1)
,但我们最终得到了这个漂亮的小过程:
x_delayed(0) <= x;
DELAYS : process(samp_clk)
begin
x_delayed(0) <= (others => 'Z');
if rising_edge(samp_clk) then
x_delayed(1 to x_delayed'high) <= x_delayed(0 to x_delayed'high-1);
end if; -- rising_edge(samp_clk)
end process;
编辑3:
在OllieB 的下一个建议之后,事实证明这x_delayed(0) <= (others => 'Z')
是不必要的,因为他之前的更改。以下工作正常:
x_delayed(0) <= x;
DELAYS : process(samp_clk)
begin
if rising_edge(samp_clk) then
x_delayed(1 to x_delayed'high) <= x_delayed(0 to x_delayed'high-1);
end if;
end process;