reg [10:0] x_location_reg,y_location_reg;
reg [10:0] next_x_location , next_y_location;
localparam sq_y_t = 200;
localparam sq_y_b = 220;
always @(posedge clk,posedge reset)
if(reset)
begin
x_location_reg <= 0; // registers to store the current position
y_location_reg <= 0;
end
else
begin
x_location_reg <= next_x_location;
y_location_reg <= next_y_location;
end
// counter to count upto 100000 to get time delay of 2ms
reg [18:0] tick_tock;
wire click;
always @(posedge clk or posedge reset)
begin
if(reset)
tick_tock <= 0;
else if ( tick_tock==99999)
tick_tock <= 0;
else
tick_tock <= tick_tock+1;
end
assign click = (tick_tock == 99999)?1'b1 : 1'b0; //click every 2ms
always @(posedge click or posedge reset)
begin
if(reset)
next_x_location <= 0;
else
next_x_location <= next_x_location +1;
end
end
always @(posedge clk , posedge reset)
if((pixel_x >= x_location_reg && pixel_x <= x_location_reg + 5 ) && (pixel_y >= sq_y_t && pixel_y < sq_y_b))
box_on <= 1'b1;
else
box_on <= 1'b0;