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/] [PrewittFilter.vhd] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 muhammedko
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
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: 
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 work.OperatorOverloading_pkg.ALL;
23
USE work.EdgeDetection_pkg.ALL;
24
 
25
-- Uncomment the following library declaration if using
26
-- arithmetic functions with Signed or Unsigned values
27
use IEEE.NUMERIC_STD.ALL;
28
 
29
-- Uncomment the following library declaration if instantiating
30
-- any Xilinx leaf cells in this code.
31
--library UNISIM;
32
--use UNISIM.VComponents.all;
33
 
34
ENTITY PrewittFilter IS
35
    PORT (
36
        CLK                     : IN STD_LOGIC;
37
        EdgeDetection_Enable    : IN STD_LOGIC;
38
        EdgeDetection_Disable   : IN STD_LOGIC;
39
        EdgeDetection_Din       : IN array2D(0 TO 2)(7 DOWNTO 0);
40
        EdgeDetection_Dout      : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
41
        EdgeDetection_Ready     : OUT STD_LOGIC
42
    );
43
END PrewittFilter;
44
 
45
ARCHITECTURE Behavioral OF PrewittFilter IS
46
 
47
    signal Din_Buffer               : array3D(0 to 2)(0 to 2)(7 downto 0)   := (others => (others => (others => '0')));
48
 
49
    signal MultArray_Reg_x          : array3D(0 to 2)(0 to 2)(16 downto 0)  := (others => (others => (others => '0')));
50
    signal AddArray_Layer1_x        : array2D(0 to 2)(16 downto 0)          := (others => (others => '0'));
51
    signal AddArray_Layer2_x        : std_logic_vector(16 downto 0)         := (others => '0');
52
    signal Convolution_Res_x        : std_logic_vector(33 downto 0)         := (others => '0');
53
 
54
    signal MultArray_Reg_y          : array3D(0 to 2)(0 to 2)(16 downto 0)  := (others => (others => (others => '0')));
55
    signal AddArray_Layer1_y        : array2D(0 to 2)(16 downto 0)          := (others => (others => '0'));
56
    signal AddArray_Layer2_y        : std_logic_vector(16 downto 0)         := (others => '0');
57
    signal Convolution_Res_y        : std_logic_vector(33 downto 0)         := (others => '0');
58
 
59
    signal EdgeDetection_Dout_Reg   : STD_LOGIC_VECTOR(33 DOWNTO 0)         := (others => '0');
60
 
61
    TYPE states IS (
62
        S_IDLE,
63
        S_CONVOLVE
64
    );
65
    SIGNAL state : states := S_IDLE;
66
 
67
 
68
    constant Coeff_x : array3D(0 to 2)(0 to 2)(7 downto 0) := (
69
        (x"01", x"00", x"ff"),
70
        (x"01", x"00", x"ff"),
71
        (x"01", x"00", x"ff")
72
    );
73
    constant Coeff_y : array3D(0 to 2)(0 to 2)(7 downto 0) := (
74
        (x"01", x"01", x"01"),
75
        (x"00", x"00", x"00"),
76
        (x"ff", x"ff", x"ff")
77
    );
78
 
79
    signal cntr         : integer range 0 to 7 := 0;
80
    signal cntrDisable  : integer range 0 to 7 := 0;
81
 
82
BEGIN
83
 
84
    P_MAIN : PROCESS (CLK)
85
    BEGIN
86
        IF rising_edge(CLK) THEN
87
            CASE state IS
88
                WHEN S_IDLE =>
89
                    EdgeDetection_Ready <= '0';
90
                    IF EdgeDetection_Enable THEN
91
                        state <= S_CONVOLVE;
92
                        Din_Buffer(0)           <=  EdgeDetection_Din;
93
                        Din_Buffer(1 to 2)      <= Din_Buffer(0 to 1);
94
                        cntr                    <= 0;
95
                    END IF;
96
 
97
                WHEN S_CONVOLVE =>
98
                    Din_Buffer(0)               <=  EdgeDetection_Din;
99
                    Din_Buffer(1 to 2)          <= Din_Buffer(0 to 1);
100
 
101
                    MultArray_Reg_x             <= Coeff_x * ("0" & Din_Buffer);
102
                    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)));
103
                    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)));
104
                    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)));
105
                    AddArray_Layer2_x           <= std_logic_vector(signed(AddArray_Layer1_x(0)) + signed(AddArray_Layer1_x(1)) + signed(AddArray_Layer1_x(2)));
106
                    Convolution_Res_x           <= std_logic_vector(signed(AddArray_Layer2_x) * signed(AddArray_Layer2_x));
107
 
108
                    MultArray_Reg_y             <= Coeff_y * ("0" & Din_Buffer);
109
                    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)));
110
                    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)));
111
                    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)));
112
                    AddArray_Layer2_y           <= std_logic_vector(signed(AddArray_Layer1_y(0)) + signed(AddArray_Layer1_y(1)) + signed(AddArray_Layer1_y(2)));
113
                    Convolution_Res_y           <= std_logic_vector(signed(AddArray_Layer2_y) * signed(AddArray_Layer2_y));
114
 
115
                    EdgeDetection_Dout_Reg  <= std_logic_vector(unsigned(Convolution_Res_x) + unsigned(Convolution_Res_y));
116
 
117
                    if cntr = 5 then
118
                        cntr    <= 0;
119
                        EdgeDetection_Ready <= '1';
120
                    else
121
                        cntr    <= cntr + 1;
122
                    end if;
123
 
124
                    if EdgeDetection_Disable = '1' then
125
                        cntrDisable <= cntrDisable + 1;
126
                    end if;
127
 
128
                    if cntrDisable = 6 then
129
                        state   <= S_IDLE;
130
                        EdgeDetection_Ready <= '0';
131
                        cntr    <= 0;
132
                        cntrDisable <= 0;
133
                    end if;
134
            END CASE;
135
        END IF;
136
    END PROCESS;
137
    EdgeDetection_Dout  <= EdgeDetection_Dout_Reg(31 downto 0);
138
END Behavioral;

powered by: WebSVN 2.1.0

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