OpenCores
URL https://opencores.org/ocsvn/canny_edge_detector/canny_edge_detector/trunk

Subversion Repositories canny_edge_detector

[/] [canny_edge_detector/] [trunk/] [vhdl_src/] [wrapper.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 angelobacc
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
USE IEEE.NUMERIC_STD.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5
 
6
entity edge_sobel_wrapper is
7
  generic (
8
    data_width : integer := 8
9
  );
10
  Port ( clk  : in  STD_LOGIC;
11
    rstn      : in  STD_LOGIC;
12
         fsync_in  : in  STD_LOGIC;
13
         pdata_in  : in  STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0);
14
         fsync_out : out  STD_LOGIC;
15
         pdata_out : out  STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0)
16
  );
17
end entity edge_sobel_wrapper;
18
 
19
architecture Structural of edge_sobel_wrapper is
20
 
21
constant GRAD_WIDTH : integer := 32;
22
constant GDIR_WIDTH : integer := 2;
23
constant NO_OF_COLS : integer := 640;
24
constant NO_OF_ROWS : integer := 480;
25
constant ROW_BITS   : integer := 9;
26
constant COL_BITS   : integer := 10;
27
 
28
signal RowsCounter_r, RowsCounter_x : STD_LOGIC_VECTOR(ROW_BITS-1 downto 0);
29
signal ColsCounter_r, ColsCounter_x : STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
30
 
31
signal pdata_1_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
32
signal pdata_2_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
33
signal pdata_3_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
34
signal pdata_4_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
35
signal pdata_5_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
36
signal pdata_6_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
37
signal pdata_7_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
38
signal pdata_8_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
39
signal pdata_9_1   :  std_logic_vector(DATA_WIDTH-1 downto 0);
40
signal fsync_o_1   :  std_logic;
41
--
42
signal Xdata_o_2   :  std_logic_vector(GRAD_WIDTH-1 downto 0);
43
signal Ydata_o_2   :  std_logic_vector(GRAD_WIDTH-1 downto 0);
44
signal fsync_o_2   :  std_logic;
45
--
46
signal pdata_1_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
47
signal pdata_2_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
48
signal pdata_3_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
49
signal pdata_4_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
50
signal pdata_5_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
51
signal pdata_6_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
52
signal pdata_7_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
53
signal pdata_8_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
54
signal pdata_9_3x  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
55
--
56
signal pdata_1_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
57
signal pdata_2_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
58
signal pdata_3_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
59
signal pdata_4_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
60
signal pdata_5_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
61
signal pdata_6_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
62
signal pdata_7_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
63
signal pdata_8_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
64
signal pdata_9_3y  :  std_logic_vector(GRAD_WIDTH-1 downto 0);
65
signal fsync_o_3   :  std_logic;
66
--
67
signal Mdata_o_4   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
68
signal Ddata_o_4   :  std_logic_vector(1 downto 0);
69
signal fsync_o_4   :  std_logic;
70
--
71
signal pdata_1_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
72
signal pdata_2_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
73
signal pdata_3_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
74
signal pdata_4_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
75
signal pdata_5_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
76
signal pdata_6_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
77
signal pdata_7_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
78
signal pdata_8_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
79
signal pdata_9_5   :  std_logic_vector(GRAD_WIDTH-1-16 downto 0);
80
signal dData_o_5   :  std_logic_vector(1 downto 0);
81
signal fsync_o_5   :  std_logic;
82
--
83
signal fsync_o_6   :  std_logic;
84
signal pdata_o_6   :  std_logic_vector(DATA_WIDTH-1 downto 0);
85
--
86
signal counter_x   :  std_logic_vector(18 downto 0);
87
signal counter_r   :  std_logic_vector(18 downto 0);
88
signal counter1_x  :  std_logic_vector(15 downto 0);
89
signal counter1_r  :  std_logic_vector(15 downto 0);
90
signal fsync_temp  :  std_logic;
91
signal fsync_out_a :  std_logic;
92
signal tail_x      :  std_logic;
93
signal tail_r      :  std_logic;
94
--
95
constant LATENCY : integer := 5+5+5+3+(5*NO_OF_COLS)+7+2;
96
signal fsync_store : std_logic_vector(LATENCY - 1 downto 0); -- clock cycles delay to compensate for latency
97
 
98
begin
99
 
100
  CacheSystem : entity work.CacheSystem
101
        generic map (
102
          DATA_WIDTH => DATA_WIDTH,
103
          WINDOW_SIZE => 9,
104
          ROW_BITS => 9,
105
          COL_BITS => 10,
106
          NO_OF_ROWS => NO_OF_ROWS,
107
     NO_OF_COLS => NO_OF_COLS
108
          )
109
        port map(
110
          clk => clk,
111
          fsync_in => fsync_out_a,
112
          pdata_in => pdata_in,
113
          --fsync_out => fsync_o_1,
114
          pdata_out1 => pdata_1_1,
115
          pdata_out2 => pdata_2_1,
116
          pdata_out3 => pdata_3_1,
117
          pdata_out4 => pdata_4_1,
118
          pdata_out5 => pdata_5_1,
119
          pdata_out6 => pdata_6_1,
120
          pdata_out7 => pdata_7_1,
121
          pdata_out8 => pdata_8_1,
122
          pdata_out9 => pdata_9_1
123
          );
124
 
125
  filterH: entity work.filterH
126
        generic map (
127
          DATA_WIDTH => DATA_WIDTH,
128
          GRAD_WIDTH => GRAD_WIDTH
129
          )
130
        port map(
131
          clk => clk,
132
          fsync => fsync_out_a,
133
          pData1  => pData_1_1,
134
          pData2  => pData_2_1,
135
          pData3  => pData_3_1,
136
          pData4  => pData_4_1,
137
          pData5  => pData_5_1,
138
          pData6  => pData_6_1,
139
          pData7  => pData_7_1,
140
          pData8  => pData_8_1,
141
          pData9  => pData_9_1,
142
          --fsync_o => fsync_o_2,
143
          Xdata_o => Xdata_o_2, -- x gradient partial filtering product
144
          Ydata_o => Ydata_o_2  -- y gradient partial filtering product
145
          );
146
 
147
  -- rowbuffer            
148
  CacheSystem2 : entity work.CacheSystem2
149
        generic map (
150
          DATA_WIDTH => GRAD_WIDTH,
151
          WINDOW_SIZE =>9,
152
          ROW_BITS => ROW_BITS,
153
          COL_BITS => COL_BITS,
154
          NO_OF_ROWS => NO_OF_ROWS,
155
     NO_OF_COLS => NO_OF_COLS
156
          )
157
        port map(
158
          clk => clk,
159
          fsync_in => fsync_out_a,
160
          Xdata_in => Xdata_o_2,
161
          Ydata_in => Ydata_o_2,
162
          --fsync_out => fsync_o_3,
163
          --
164
          pdata_out1x => pdata_1_3x,
165
          pdata_out2x => pdata_2_3x,
166
          pdata_out3x => pdata_3_3x,
167
          pdata_out4x => pdata_4_3x,
168
          pdata_out5x => pdata_5_3x,
169
          pdata_out6x => pdata_6_3x,
170
          pdata_out7x => pdata_7_3x,
171
          pdata_out8x => pdata_8_3x,
172
          pdata_out9x => pdata_9_3x,
173
          --      
174
          pdata_out1y => pdata_1_3y,
175
          pdata_out2y => pdata_2_3y,
176
          pdata_out3y => pdata_3_3y,
177
          pdata_out4y => pdata_4_3y,
178
          pdata_out5y => pdata_5_3y,
179
          pdata_out6y => pdata_6_3y,
180
          pdata_out7y => pdata_7_3y,
181
          pdata_out8y => pdata_8_3y,
182
          pdata_out9y => pdata_9_3y
183
          );
184
 
185
 
186
  filterV: entity work.filterV
187
        generic map (
188
          DATA_WIDTH => GRAD_WIDTH,
189
          GRAD_WIDTH => GRAD_WIDTH
190
          )
191
        port map(
192
          clk => clk,
193
          fsync => fsync_out_a,
194
          pData1x  => pData_1_3x,
195
          pData2x  => pData_2_3x,
196
          pData3x  => pData_3_3x,
197
          pData4x  => pData_4_3x,
198
          pData5x  => pData_5_3x,
199
          pData6x  => pData_6_3x,
200
          pData7x  => pData_7_3x,
201
          pData8x  => pData_8_3x,
202
          pData9x  => pData_9_3x,
203
          --
204
          pData1y  => pData_1_3y,
205
          pData2y  => pData_2_3y,
206
          pData3y  => pData_3_3y,
207
          pData4y  => pData_4_3y,
208
          pData5y  => pData_5_3y,
209
          pData6y  => pData_6_3y,
210
          pData7y  => pData_7_3y,
211
          pData8y  => pData_8_3y,
212
          pData9y  => pData_9_3y,
213
          --fsync_o => fsync_o_4,
214
          Mdata_o  => Mdata_o_4,
215
          Ddata_o  => Ddata_o_4
216
          );
217
 
218
  CacheSystem3 : entity work.CacheSystem3
219
        generic map (
220
          DATA_WIDTH => GRAD_WIDTH-16,
221
          WINDOW_SIZE => 3,
222
          ROW_BITS => ROW_BITS,
223
          COL_BITS => COL_BITS,
224
          NO_OF_ROWS => NO_OF_ROWS,
225
     NO_OF_COLS => NO_OF_COLS
226
          )
227
        port map(
228
          clk => clk,
229
          fsync_in => fsync_out_a,
230
          mdata_in => mdata_o_4,
231
          dData_in => Ddata_o_4,
232
          --fsync_out => fsync_o_5,
233
          pdata_out1 => pdata_1_5,
234
          pdata_out2 => pdata_2_5,
235
          pdata_out3 => pdata_3_5,
236
          pdata_out4 => pdata_4_5,
237
          pdata_out5 => pdata_5_5,
238
          pdata_out6 => pdata_6_5,
239
          pdata_out7 => pdata_7_5,
240
          pdata_out8 => pdata_8_5,
241
          pdata_out9 => pdata_9_5,
242
          dData_out => dData_o_5
243
          );
244
 
245
  krnl2: entity work.nmax_supp
246
        generic map (
247
          DATA_WIDTH => DATA_WIDTH,
248
          GRAD_WIDTH => GRAD_WIDTH-16
249
          )
250
        port map(
251
          clk => clk,
252
          fsync => fsync_out_a,
253
          mData1 => pData_1_5,
254
          mData2 => pData_2_5,
255
          mData3 => pData_3_5,
256
          mData4 => pData_4_5,
257
          mData5 => pData_5_5,
258
          mData6 => pData_6_5,
259
          mData7 => pData_7_5,
260
          mData8 => pData_8_5,
261
          mData9 => pData_9_5,
262
          dData  => dData_o_5,
263
          --fsync_o => fsync_o_6,
264
          pdata_o => pdata_o_6
265
          );
266
 
267
  --fsync_out <= fsync_o_4;       
268
  --pdata_out <= mdata_o_4(7 downto 0);
269
  pdata_out <= pdata_o_6;-- when RowsCounter_r > std_logic_vector(to_unsigned(3, RowsCounter_r'length)) AND
270
--                                                        ColsCounter_r > std_logic_vector(to_unsigned(3, ColsCounter_r'length)) AND
271
--                                                        RowsCounter_r < std_logic_vector(to_unsigned(NO_OF_ROWS-4, RowsCounter_r'length)) AND
272
--                                                        ColsCounter_r < std_logic_vector(to_unsigned(NO_OF_COLS-4, ColsCounter_r'length)) ELSE
273
--                                                        (others => '0');
274
 
275
--  fsync_out <= fsync_temp;
276
  fsync_out_a <= fsync_temp OR fsync_in;
277
  fsync_out     <= fsync_temp;
278
 
279
 
280
---- fsync_temp is the delayed version (LATENCY) of fsync_out
281
--  fsync_delayer : process (clk)
282
--  begin
283
--      if rising_edge(clk) then
284
--        fsync_store <= fsync_store(LATENCY-2 downto 0) & fsync_in;
285
--        fsync_temp <= fsync_store(LATENCY-1);
286
--      end if;
287
--  end process fsync_delayer;
288
 
289
--      if (fsync_in) = '1' AND counter_r /= std_logic_vector(to_unsigned(5+5+5+3+(5*NO_OF_COLS)+7+2, counter_r'length)) then
290
 
291
  f_sync_delayer1: process (counter_r, counter1_r, fsync_in, tail_r) -- nmaxsupp
292
  begin
293
    counter_x  <= counter_r;
294
    counter1_x <= counter1_r;
295
         tail_x     <= tail_r;
296
 
297
         if fsync_in = '1' then
298
      if counter_r /= std_logic_vector(to_unsigned(NO_OF_ROWS*NO_OF_COLS-1, counter_r'length)) then
299
        counter_x <= counter_r + 1;
300
           else
301
             counter_x <= (others => '0');
302
                  tail_x <= '1';
303
           end if;
304
        end if;
305
 
306
        if tail_r = '0' then
307
          if counter_r < std_logic_vector(to_unsigned(5+5+5+4+(5*NO_OF_COLS)+7+2, counter_r'length)) then
308
            fsync_temp <= '0';
309
          else
310
            fsync_temp <= fsync_in;
311
          end if;
312
        else
313
          fsync_temp <= '1';
314
        end if;
315
 
316
        if tail_r ='1' then
317
          if counter1_r < std_logic_vector(to_unsigned(5+5+5+3+(5*NO_OF_COLS)+7+2, counter_r'length)) then
318
            counter1_x <= counter1_r + 1;
319
          else
320
            counter1_x <= (others => '0');
321
            tail_x <= '0';
322
          end if;
323
        end if;
324
  end process f_sync_delayer1;
325
 
326
  update_reg : process (clk)
327
  begin
328
    if rising_edge(clk) then
329
          if rstn = '0' then
330
            RowsCounter_r <= (others => '0');
331
       ColsCounter_r <= (others => '0');
332
            counter_r     <= (others => '0');
333
       counter1_r    <= (others => '0');
334
            tail_r        <= '0';
335
          else
336
            RowsCounter_r <= RowsCounter_x;
337
       ColsCounter_r <= ColsCounter_x;
338
            counter_r     <= counter_x;
339
       counter1_r    <= counter1_x;
340
            tail_r        <= tail_x;
341
          end if;
342
        end if;
343
  end process update_reg;
344
 
345
  counter : process (fsync_o_6,  ColsCounter_r, RowsCounter_r, fsync_in)
346
  begin
347
    RowsCounter_x <= RowsCounter_r;
348
    ColsCounter_x <= ColsCounter_r;
349
        --if rising_edge(clk) then
350
        if(fsync_in = '1') then
351
          if RowsCounter_r = std_logic_vector(to_unsigned(NO_OF_ROWS-1, ROW_BITS)) AND
352
            ColsCounter_r = std_logic_vector(to_unsigned(NO_OF_COLS-1, COL_BITS)) then
353
            ColsCounter_x <= (others => '0');
354
                 RowsCounter_x <= (others => '0');
355
          elsif RowsCounter_r /= std_logic_vector(to_unsigned(NO_OF_ROWS-1, ROW_BITS)) AND
356
            ColsCounter_r = std_logic_vector(to_unsigned(NO_OF_COLS-1, COL_BITS)) then
357
            ColsCounter_x <= ColsCounter_r + 1;
358
                 RowsCounter_x <= RowsCounter_r;
359
          else
360
                 ColsCounter_x <= ColsCounter_r + 1;
361
                 RowsCounter_x <= RowsCounter_r;
362
          end if;
363
        end if;
364
    --end if;
365
  end process counter;
366
 
367
end Structural;

powered by: WebSVN 2.1.0

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