OpenCores
URL https://opencores.org/ocsvn/fully-pipelined-edge-detection-algorithms/fully-pipelined-edge-detection-algorithms/trunk

Subversion Repositories fully-pipelined-edge-detection-algorithms

[/] [fully-pipelined-edge-detection-algorithms/] [trunk/] [src/] [SobelFilter.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 muhammedko
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: MUHAMMED KOCAOGLU
4
-- 
5
-- Create Date: 01/13/2022 10:56:24 PM
6
-- Design Name: 
7
-- Module Name: EdgeDetection - Behavioral
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool Versions: 
11
-- Description: 
12
-- 
13
-- Dependencies: VHDL 2008
14
-- 
15
-- Revision:
16
-- Revision 0.01 - File Created
17
-- Additional Comments:
18
-- 
19
----------------------------------------------------------------------------------
20
LIBRARY IEEE;
21
USE IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.NUMERIC_STD.ALL;
23
USE work.OperatorOverloading_pkg.ALL;
24
USE work.EdgeDetection_pkg.ALL;
25
 
26
 
27
ENTITY SobelFilter IS
28
    PORT (
29
        CLK                     : IN STD_LOGIC;
30
        EdgeDetection_Enable    : IN STD_LOGIC;
31
        EdgeDetection_Disable   : IN STD_LOGIC;
32
        EdgeDetection_Din       : IN array2D(0 TO 2)(7 DOWNTO 0);
33
        EdgeDetection_Dout      : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
34
        EdgeDetection_Ready     : OUT STD_LOGIC
35
    );
36
END SobelFilter;
37
 
38
ARCHITECTURE Behavioral OF SobelFilter IS
39
 
40
    signal Din_Buffer               : array3D(0 to 2)(0 to 2)(7 downto 0)   := (others => (others => (others => '0')));
41
 
42
    signal MultArray_Reg_x          : array3D(0 to 2)(0 to 2)(16 downto 0)  := (others => (others => (others => '0')));
43
    signal AddArray_Layer1_x        : array2D(0 to 2)(16 downto 0)          := (others => (others => '0'));
44
    signal AddArray_Layer2_x        : std_logic_vector(16 downto 0)         := (others => '0');
45
    signal Convolution_Res_x        : std_logic_vector(33 downto 0)         := (others => '0');
46
 
47
    signal MultArray_Reg_y          : array3D(0 to 2)(0 to 2)(16 downto 0)  := (others => (others => (others => '0')));
48
    signal AddArray_Layer1_y        : array2D(0 to 2)(16 downto 0)          := (others => (others => '0'));
49
    signal AddArray_Layer2_y        : std_logic_vector(16 downto 0)         := (others => '0');
50
    signal Convolution_Res_y        : std_logic_vector(33 downto 0)         := (others => '0');
51
 
52
    signal EdgeDetection_Dout_Reg   : STD_LOGIC_VECTOR(33 DOWNTO 0)         := (others => '0');
53
 
54
    TYPE states IS (
55
        S_IDLE,
56
        S_CONVOLVE
57
    );
58
    SIGNAL state : states := S_IDLE;
59
 
60
 
61
    constant Coeff_x : array3D(0 to 2)(0 to 2)(7 downto 0) := (
62
        (x"01", x"00", x"ff"),
63
        (x"02", x"00", x"fe"),
64
        (x"01", x"00", x"ff")
65
    );
66
    constant Coeff_y : array3D(0 to 2)(0 to 2)(7 downto 0) := (
67
        (x"01", x"02", x"01"),
68
        (x"00", x"00", x"00"),
69
        (x"ff", x"fe", x"ff")
70
    );
71
 
72
    signal cntr : integer range 0 to 7 := 0;
73
    signal cntrDisable : integer range 0 to 7 := 0;
74
 
75
BEGIN
76
 
77
    P_MAIN : PROCESS (CLK)
78
    BEGIN
79
        IF rising_edge(CLK) THEN
80
            CASE state IS
81
                WHEN S_IDLE =>
82
                    EdgeDetection_Ready <= '0';
83
                    IF EdgeDetection_Enable THEN
84
                        state <= S_CONVOLVE;
85
                        Din_Buffer(0)           <=  EdgeDetection_Din;
86
                        Din_Buffer(1 to 2)      <= Din_Buffer(0 to 1);
87
                        cntr                    <= 0;
88
                    END IF;
89
 
90
                WHEN S_CONVOLVE =>
91
                    Din_Buffer(0)               <=  EdgeDetection_Din;
92
                    Din_Buffer(1 to 2)          <= Din_Buffer(0 to 1);
93
 
94
                    MultArray_Reg_x             <= Coeff_x * ("0" & Din_Buffer);
95
                    AddArray_Layer1_x(0)        <= std_logic_vector(signed(MultArray_Reg_x(0)(0)) + signed(MultArray_Reg_x(0)(1))  + signed(MultArray_Reg_x(0)(2)));
96
                    AddArray_Layer1_x(1)        <= std_logic_vector(signed(MultArray_Reg_x(1)(0)) + signed(MultArray_Reg_x(1)(1))  + signed(MultArray_Reg_x(1)(2)));
97
                    AddArray_Layer1_x(2)        <= std_logic_vector(signed(MultArray_Reg_x(2)(0)) + signed(MultArray_Reg_x(2)(1))  + signed(MultArray_Reg_x(2)(2)));
98
                    AddArray_Layer2_x           <= std_logic_vector(signed(AddArray_Layer1_x(0)) + signed(AddArray_Layer1_x(1)) + signed(AddArray_Layer1_x(2)));
99
                    Convolution_Res_x           <= std_logic_vector(signed(AddArray_Layer2_x) * signed(AddArray_Layer2_x));
100
 
101
                    MultArray_Reg_y             <= Coeff_y * ("0" & Din_Buffer);
102
                    AddArray_Layer1_y(0)        <= std_logic_vector(signed(MultArray_Reg_y(0)(0)) + signed(MultArray_Reg_y(0)(1))  + signed(MultArray_Reg_y(0)(2)));
103
                    AddArray_Layer1_y(1)        <= std_logic_vector(signed(MultArray_Reg_y(1)(0)) + signed(MultArray_Reg_y(1)(1))  + signed(MultArray_Reg_y(1)(2)));
104
                    AddArray_Layer1_y(2)        <= std_logic_vector(signed(MultArray_Reg_y(2)(0)) + signed(MultArray_Reg_y(2)(1))  + signed(MultArray_Reg_y(2)(2)));
105
                    AddArray_Layer2_y           <= std_logic_vector(signed(AddArray_Layer1_y(0)) + signed(AddArray_Layer1_y(1)) + signed(AddArray_Layer1_y(2)));
106
                    Convolution_Res_y           <= std_logic_vector(signed(AddArray_Layer2_y) * signed(AddArray_Layer2_y));
107
 
108
                    EdgeDetection_Dout_Reg      <= std_logic_vector(unsigned(Convolution_Res_x) + unsigned(Convolution_Res_y));
109
 
110
                    if cntr = 5 then
111
                        cntr    <= 0;
112
                        EdgeDetection_Ready <= '1';
113
                    else
114
                        cntr    <= cntr + 1;
115
                    end if;
116
 
117
                    if EdgeDetection_Disable = '1' then
118
                        cntrDisable <= cntrDisable + 1;
119
                    end if;
120
 
121
                    if cntrDisable = 6 then
122
                        state   <= S_IDLE;
123
                        EdgeDetection_Ready <= '0';
124
                        cntr    <= 0;
125
                        cntrDisable <= 0;
126
                    end if;
127
            END CASE;
128
        END IF;
129
    END PROCESS;
130
    EdgeDetection_Dout  <= EdgeDetection_Dout_Reg(31 downto 0);
131
END Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.