-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGET_CENTER.v
61 lines (45 loc) · 926 Bytes
/
GET_CENTER.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
module GET_CENTER(clk,x_pos,y_pos,binary_pink,binary_green,new_frame,center,rst);
input clk;
input rst;
input new_frame;
input [15:0] x_pos ;
input [15:0] y_pos ;
input binary_pink;
input binary_green;
output center;
reg [31:0] x_acc ;
reg [31:0] y_acc ;
wire [31:0] result_x ;
wire [31:0] result_y ;
reg [31:0] center;
reg [31:0] pxl_count_pink;
always @ (posedge clk,posedge new_frame)
begin
if (new_frame == 1'b1 )
begin
pxl_count_pink <= 32'd1;
x_acc <=32'd0;
y_acc <=32'd0;
end
else if (binary_pink == 1'b1 )
begin
pxl_count_pink <= pxl_count_pink + 32'h00000001 ;
x_acc = x_acc + x_pos;
y_acc = y_acc + y_pos;
end
end
always @ (posedge new_frame)
begin
center <= result_y;
end
alt_div div_x(
.denom(pxl_count_pink),
.numer(x_acc),
.quotient(result_x),
.remain());
alt_div div_y(
.denom(pxl_count_pink),
.numer(y_acc),
.quotient(result_y),
.remain());
endmodule