?? 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 + -