【发布时间】:2013-08-15 07:16:58
【问题描述】:
我正在研究 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、it was 内部驱动。
在实现Brian Drummond's idea 后,它可以完美运行:
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's suggestion 来摆脱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's next suggestion 之后,事实证明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;
【问题讨论】:
-
x_delayed 是一个寄存器库(或者看起来如此)。您打算如何在没有进程的情况下将值输入寄存器?顺便说一句,在 std_logic 中使用 std_logic_vector(x 是 std_logic_vector 还是整数?所有负值是什么?)不是给你一些警告吗?
-
您能指定 x 和 x_delayed 的类型吗?从您粘贴的内容来看,您似乎正在将 x(31 downto 0) 分配给 x_delayed(0)。 x 是如何定义的?
-
啊,我明白了:x_delayed 是一个 x 类型的数组。从代码中问题并没有立即显现出来。您能否具体说明您正在使用哪些工具?
-
抱歉,我试图精简问题,但遗漏了一些重要部分。这里的一切都是
std_logic_vector(31 downto 0)。我正在使用赛灵思 ISE。 -
再一次,我手头没有标准,但我相信这是因为 x_delayed 的移位版本是本地静态切片名称,而索引版本使用变量作为其索引,所以不是本地静态的。
标签: vhdl