【发布时间】:2014-02-09 00:58:42
【问题描述】:
在一门关于可配置嵌入式系统的大学课程中(在 ZYNQ-7010 上),我们最近实现了一个(简单的)低通图像过滤器,它将一维高斯核 (0.25*[1 2 1]) 应用于数据来自块 RAM。
我们决定缓存(即排队)三个像素,然后在数据输出过程中对它们进行在线操作。我们的第一种方法是设置三个流程变量,并让它们在一个
pixel[k-2] := pixel[k-1];
pixel[k-1] := pixel[k];
pixel[k] := RAM(address);
时尚;以下为全流程:
process (clk25)
-- queue
variable pixelMinus2 : std_logic_vector(11 downto 0) := (others => '0');
variable pixelMinus1 : std_logic_vector(11 downto 0) := (others => '0');
variable pixelCurrent : std_logic_vector(11 downto 0) := (others => '0');
-- temporaries
variable r : unsigned(3 downto 0);
variable g : unsigned(3 downto 0);
variable b : unsigned(3 downto 0);
begin
if clk25'event and clk25 = '1' then
pixelMinus2 := pixelMinus1;
pixelMinus1 := pixelCurrent;
pixelCurrent := RAM(to_integer(UNSIGNED(addrb)));
IF slv_reg0(3) = '0' THEN
-- bypass filter for debugging
dob <= pixelCurrent;
ELSE
-- colors are 4 bit each in a 12 bit vector
-- division by 4 is done by right shifting by 2
r := (
("00" & unsigned(pixelMinus2(11 downto 10)))
+ ("00" & unsigned(pixelMinus1(11 downto 10)))
+ ("00" & unsigned(pixelMinus1(11 downto 10)))
+ ("00" & unsigned(pixelCurrent(11 downto 10)))
);
g := (
("00" & unsigned(pixelMinus2(7 downto 6)))
+ ("00" & unsigned(pixelMinus1(7 downto 6)))
+ ("00" & unsigned(pixelMinus1(7 downto 6)))
+ ("00" & unsigned(pixelCurrent(7 downto 6)))
);
b := (
("00" & unsigned(pixelMinus2(3 downto 2)))
+ ("00" & unsigned(pixelMinus1(3 downto 2)))
+ ("00" & unsigned(pixelMinus1(3 downto 2)))
+ ("00" & unsigned(pixelCurrent(3 downto 2)))
);
dob <= std_logic_vector(r) & std_logic_vector(g) & std_logic_vector(b);
END IF;
end if;
end process;
然而事实证明这是非常错误的;综合需要很长时间,并导致 LUT 使用量估计为设备能力的 130%。
我们后来将实现更改为使用信号而不是变量,这解决了所有问题;硬件表现符合预期,LUT 使用率下降到一定百分比。
我的问题是使用变量时出现问题的原因是什么,因为根据我们的理解,它应该是这样工作的。
【问题讨论】: