-
Notifications
You must be signed in to change notification settings - Fork 0
/
zone.v
executable file
·77 lines (67 loc) · 2.1 KB
/
zone.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 19:28:35 11/17/2016
// Design Name:
// Module Name: zone
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module zone #(parameter MAX_X = 800, MAX_Y = 600)
(hcount,vcount,left,right,top,bottom,
reset,cascade_in,cascade_out,clk,state);
input [10:0] hcount, vcount;
input clk;
input reset, cascade_in;
output reg [10:0] left, right;
output reg [10:0] top, bottom;
output reg cascade_out;
output reg [2:0] state;
// Parameters
parameter MARGIN = 7;
parameter INIT_SIZE = 10;
parameter INACTIVE = 0;
parameter ACTIVE = 1;
// State
// reg [2:0] state = INACTIVE;
always @(posedge clk) begin
// Reset zone to inactive at new frame
if (reset) state <= INACTIVE;
// If not checking current zone, don't check next zone
else if (!cascade_in) cascade_out <= 0;
else begin
cascade_out <= 1; // Default cascading to true
// Initialize zone bounds around pixel
if (state==INACTIVE) begin
left <= (hcount-INIT_SIZE>=0) ? hcount-INIT_SIZE : 0;
right <= (hcount+INIT_SIZE<=MAX_X) ? hcount+INIT_SIZE : MAX_X;
top <= (vcount-INIT_SIZE>=0) ? vcount-INIT_SIZE : 0;
bottom <= (vcount+INIT_SIZE<=MAX_Y) ? vcount+INIT_SIZE : MAX_Y;
state <= ACTIVE; // update state
cascade_out <= 0; // Don't cascade to next zone
end
// Update bounds if within pixel is within margins
else if (hcount>=(left-MARGIN) && hcount<=(right+MARGIN)
&& vcount>=(top-MARGIN) && vcount<=(bottom+MARGIN)) begin
// Update zone's horizontal bounds
if (hcount<left) left <= hcount;
else if (hcount>right) right <= hcount;
// Update zone's vertical bounds
if (vcount<top) top <= vcount;
else if (vcount>bottom) bottom <= vcount;
cascade_out <= 0; // Don't cascade to next zone
end
end
end
endmodule