1 |
9 |
joaocarlos |
/* --------------------------------------------------------------------------------
|
2 |
|
|
This file is part of FPGA Median Filter.
|
3 |
|
|
|
4 |
|
|
FPGA Median Filter is free software: you can redistribute it and/or modify
|
5 |
|
|
it under the terms of the GNU General Public License as published by
|
6 |
|
|
the Free Software Foundation, either version 3 of the License, or
|
7 |
|
|
(at your option) any later version.
|
8 |
|
|
|
9 |
|
|
FPGA Median Filter is distributed in the hope that it will be useful,
|
10 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
GNU General Public License for more details.
|
13 |
|
|
|
14 |
|
|
You should have received a copy of the GNU General Public License
|
15 |
|
|
along with FPGA Median Filter. If not, see <http://www.gnu.org/licenses/>.
|
16 |
|
|
-------------------------------------------------------------------------------- */
|
17 |
|
|
/* +----------------------------------------------------------------------------
|
18 |
|
|
Universidade Federal da Bahia
|
19 |
|
|
------------------------------------------------------------------------------
|
20 |
|
|
PROJECT: FPGA Median Filter
|
21 |
|
|
------------------------------------------------------------------------------
|
22 |
|
|
FILE NAME : median.v
|
23 |
|
|
AUTHOR : Joo Carlos Bittencourt
|
24 |
|
|
AUTHOR'S E-MAIL : joaocarlos@ieee.org
|
25 |
|
|
-----------------------------------------------------------------------------
|
26 |
|
|
RELEASE HISTORY
|
27 |
|
|
VERSION DATE AUTHOR DESCRIPTION
|
28 |
|
|
1.0 2013-08-13 joao.nunes initial version
|
29 |
|
|
2.0 2013-09-06 laur.rami fix minnor issues on memory address
|
30 |
|
|
-----------------------------------------------------------------------------
|
31 |
|
|
KEYWORDS: median, filter, image processing, state machine
|
32 |
|
|
-----------------------------------------------------------------------------
|
33 |
|
|
PURPOSE: Windowing Memory Address Controller.
|
34 |
|
|
----------------------------------------------------------------------------- */
|
35 |
2 |
joaocarlos |
module state_machine
|
36 |
|
|
#(
|
37 |
|
|
parameter LUT_ADDR_WIDTH = 10,
|
38 |
|
|
parameter IMG_WIDTH = 234,
|
39 |
|
|
parameter IMG_HEIGHT = 234
|
40 |
|
|
)(
|
41 |
|
|
input clk, // Clock
|
42 |
|
|
input rst_n, // Asynchronous reset active low
|
43 |
|
|
|
44 |
|
|
output reg [LUT_ADDR_WIDTH-1:0] raddr_a,
|
45 |
|
|
output reg [LUT_ADDR_WIDTH-1:0] raddr_b,
|
46 |
|
|
output reg [LUT_ADDR_WIDTH-1:0] raddr_c,
|
47 |
|
|
output reg [LUT_ADDR_WIDTH-1:0] waddr,
|
48 |
|
|
output reg [1:0] window_line_counter,
|
49 |
|
|
output reg [9:0] window_column_counter,
|
50 |
|
|
output reg [9:0] memory_shift
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
reg valid;
|
54 |
|
|
|
55 |
|
|
always @(posedge clk or negedge rst_n)
|
56 |
|
|
begin : out_memory_counter
|
57 |
|
|
if(~rst_n) begin
|
58 |
|
|
waddr <= {LUT_ADDR_WIDTH{1'b0}};
|
59 |
|
|
end else if(valid) begin
|
60 |
|
|
waddr <= waddr + 1'b1;
|
61 |
|
|
end
|
62 |
|
|
end
|
63 |
|
|
|
64 |
|
|
always @(posedge clk or negedge rst_n)
|
65 |
|
|
begin : addr_counter
|
66 |
|
|
if(~rst_n) begin
|
67 |
|
|
window_column_counter <= 10'd0;
|
68 |
|
|
window_line_counter <= 2'b00;
|
69 |
|
|
raddr_a <= {LUT_ADDR_WIDTH{1'b0}};
|
70 |
|
|
raddr_b <= {LUT_ADDR_WIDTH{1'b0}};
|
71 |
|
|
raddr_c <= {LUT_ADDR_WIDTH{1'b0}};
|
72 |
|
|
end else begin
|
73 |
|
|
if(window_column_counter != ((IMG_WIDTH/4)-1)) begin
|
74 |
|
|
window_column_counter <= window_column_counter + 1'b1;
|
75 |
|
|
valid <= 1'b1;
|
76 |
|
|
raddr_a <= raddr_a + 1'b1;
|
77 |
|
|
raddr_b <= raddr_b + 1'b1;
|
78 |
|
|
raddr_c <= raddr_c + 1'b1;
|
79 |
|
|
end else begin
|
80 |
|
|
window_column_counter <= 10'd0;
|
81 |
|
|
case (window_line_counter)
|
82 |
|
|
2'b00 :
|
83 |
|
|
begin
|
84 |
|
|
raddr_a <= raddr_a + 1'b1;
|
85 |
|
|
raddr_b <= raddr_b - window_column_counter;
|
86 |
|
|
raddr_c <= raddr_c - window_column_counter;
|
87 |
|
|
window_line_counter = window_line_counter + 1'b1;
|
88 |
|
|
end
|
89 |
|
|
2'b01 :
|
90 |
|
|
begin
|
91 |
|
|
raddr_b <= raddr_b + 1'b1;
|
92 |
|
|
raddr_a <= raddr_a - window_column_counter;
|
93 |
|
|
raddr_c <= raddr_c - window_column_counter;
|
94 |
|
|
window_line_counter = window_line_counter + 1'b1;
|
95 |
|
|
end
|
96 |
|
|
2'b10 :
|
97 |
|
|
begin
|
98 |
|
|
raddr_b <= raddr_b - window_column_counter;
|
99 |
|
|
raddr_a <= raddr_a - window_column_counter;
|
100 |
|
|
raddr_c <= raddr_c + 1'b1;
|
101 |
|
|
window_line_counter = 2'b00;
|
102 |
|
|
end
|
103 |
|
|
default :
|
104 |
|
|
begin
|
105 |
|
|
raddr_a <= {LUT_ADDR_WIDTH{1'b0}};
|
106 |
|
|
raddr_b <= {LUT_ADDR_WIDTH{1'b0}};
|
107 |
|
|
raddr_c <= {LUT_ADDR_WIDTH{1'b0}};
|
108 |
|
|
end
|
109 |
|
|
endcase
|
110 |
|
|
end
|
111 |
|
|
end
|
112 |
|
|
end
|
113 |
|
|
|
114 |
|
|
endmodule
|