📄 sobel.vhd
字号:
ram_radd<=ram_wadd1;
elsif ram_wren2='1' then
ram_radd<=ram_wadd2;
elsif ram_wren3='1' then
ram_radd<=ram_wadd3;
end if;
end if;
end process;
--从三个内部ram中读数据到模板寄存器中
--ram的读使能信号高电平有效,有~en控制
process(clk,en)
begin
if en='1' then
X11<=0;
X12<=0;
X13<=0;
elsif clk'event and clk='1' then
if ram_wren1='1' then
X11<=conv_integer(ram_q2);
X12<=conv_integer(ram_q3);
X13<=conv_integer(ram_q1);
elsif ram_wren2='1' then
X11<=conv_integer(ram_q3);
X12<=conv_integer(ram_q1);
X13<=conv_integer(ram_q2);
elsif ram_wren3='1' then
X11<=conv_integer(ram_q1);
X12<=conv_integer(ram_q2);
X13<=conv_integer(ram_q3);
end if;
end if;
end process;
--流水线方式替换模板寄存器中的数值
process(clk,en)
begin
if en='1' then
X21<=0;
X22<=0;
X23<=0;
elsif clk'event and clk='1' then
X21<=X11;
X22<=X12;
X23<=X13;
end if;
end process;
--流水线方式替换模板寄存器中的数值
process(clk,en)
begin
if en='1' then
X31<=0;
X32<=0;
X33<=0;
elsif clk'event and clk='1' then
X31<=X21;
X32<=X22;
X33<=X23;
end if;
end process;
--Y:(X11-X31) + 2(X12-X32) + (X13-X33) = (X11-X33) + 2(X12-X32) + (X13-X31)
--X:(X11-X13) + 2(X21-X23) + (X31-X33) = (X11-X33) + 2(X21-X23) + (X31-X13)
--比较
process(clk,en)
begin
if en='1' then
comp_tmp1<='0';
elsif clk'event and clk='1' then
if X11>X33 then
comp_tmp1<='1';
else comp_tmp1<='0';
end if;
end if;
end process;
--比较
process(clk,en)
begin
if en='1' then
comp_tmp2<='0';
elsif clk'event and clk='1' then
if X12>X32 then
comp_tmp2<='1';
else comp_tmp2<='0';
end if;
end if;
end process;
--比较
process(clk,en)
begin
if en='1' then
comp_tmp3<='0';
elsif clk'event and clk='1' then
if X13>X31 then
comp_tmp3<='1';
else comp_tmp3<='0';
end if;
end if;
end process;
--比较
process(clk,en)
begin
if en='1' then
comp_tmp4<='0';
elsif clk'event and clk='1' then
if X21>X23 then
comp_tmp4<='1';
else comp_tmp4<='0';
end if;
end if;
end process;
--比较部分加法运算结果
process(clk,en)
begin
if en='1' then
comp_tmp5<='0';
elsif clk'event and clk='1' then
if sum1>sum3 then
comp_tmp5<='1';
else comp_tmp5<='0';
end if;
end if;
end process;
--运行一次减法运算,将运算结果暂存到寄存器中
process(clk,en)
begin
if en='1' then
Sum1<=0;
elsif clk'event and clk='1' then
-- if comp_tmp1='1' then
Sum1<=X11-X33;
-- else Sum1<=X33-X11;
-- end if;
end if;
end process;
--运行一次减法运算,将运算结果暂存到寄存器中
process(clk,en)
begin
if en='1' then
Sum2<=0;
elsif clk'event and clk='1' then
-- if comp_tmp2='1' then
Sum2<=X12-X32;
-- else Sum2<=X32-X12;
-- end if;
end if;
end process;
--运行一次减法运算,将运算结果暂存到寄存器中
process(clk,en)
begin
if en='1' then
Sum3<=0;
elsif clk'event and clk='1' then
-- if comp_tmp3='1' then
Sum3<=X13-X31;
-- else Sum3<=X31-X13;
-- end if;
end if;
end process;
--运行一次减法运算,将运算结果暂存到寄存器中
process(clk,en)
begin
if en='1' then
Sum4<=0;
elsif clk'event and clk='1' then
-- if comp_tmp4='1' then
Sum4<=X21-X23;
-- else Sum4<=X23-X21;
-- end if;
end if;
end process;
--完成Y方向上的部分加法运算
process(clk,en)
begin
if en='1' then
Sum_SumX<=0;
elsif clk'event and clk='1' then
Sum_SumX<=Sum1+Sum3;
end if;
end process;
--完成X方向上的部分加法运算
process(clk,en)
begin
if en='1' then
Sum_SumY<=0;
elsif clk'event and clk='1' then
-- if comp_tmp5='1' then
Sum_SumY<=Sum1-Sum3;
-- else Sum_SumY<=Sum3-Sum1;
-- end if;
end if;
end process;
--两倍运算
process(clk,en)
begin
if en='1' then
Sum2x<=0;
elsif clk'event and clk='1' then
Sum2x<=Sum2+Sum2;
end if;
end process;
--两倍运算
process(clk,en)
begin
if en='1' then
Sum4x<=0;
elsif clk'event and clk='1' then
Sum4x<=Sum4+Sum4;
end if;
end process;
--完成Y方向上的模板运算
process(clk,en)
begin
if en='1' then
X<=(others=>'0');
elsif clk'event and clk='1' then
X<=conv_std_logic_vector(abs(Sum_SumX+Sum2x),8);
end if;
end process;
--完成X方向上的模板运算
process(clk,en)
begin
if en='1' then
Y<=(others=>'0');
elsif clk'event and clk='1' then
Y<=conv_std_logic_vector(abs(Sum_SumY+Sum4x),8);
end if;
end process;
--根据加法器进位标志输出结果
process(clk,en)
begin
if en='1' then
i_out_tmp<=(others=>'0');
elsif clk'event and clk='1' then
if add_cout='1'then
i_out_tmp<="11111111";
else
i_out_tmp<=add_result;
end if;
end if;
end process;
end behave;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -