Paddle Control - Ece
Personal tools

Paddle Control

From Ece

Jump to: navigation, search

// paddle_bottom.v // Created by Justin Davis, Jan 2005 // Modified by Patrick Duckworth, April 2007 // Target board: Pegasus by Digilent, Inc. // // Moves the bottom paddle left and right // Controlled by Atari 2600 controller

module paddle_bottom (clk, opcode, paddleY); input clk; input [1:0] opcode; output [9:0] paddleY;

parameter NOP = 0; parameter UPARROW = 1; parameter DOWNARROW = 2; //parameter A_KEY = 3; //parameter Z_KEY = 4; //parameter ESCAPE = 5;

parameter PADDLELENGTH = 80; parameter TOTALROWS = 479; parameter TOTALCOLS = 639; parameter WALLWIDTH = 20;

reg [9:0] currentY, nextY; reg [16:0] timer;

reg [1:0] op;

assign paddleY = currentY;

// one process to determine next paddleY value // first move up or down or reset based on opcode // second check boundaries //always@(opcode or timer) //begin // if(timer == 17'b10000000000000000) // op = opcode; //end

always@(opcode or currentY or timer) begin op = opcode; nextY = currentY; if (timer == 0) // use a timer to slow down the movement rate case (op) DOWNARROW : if (currentY<(TOTALCOLS-PADDLELENGTH)-WALLWIDTH-1) nextY = currentY+1; UPARROW : if (currentY>WALLWIDTH+1) nextY = currentY-1; //ESCAPE : nextY = ((TOTALCOLS/2)-(PADDLELENGTH/2)); default : nextY = currentY; endcase end

// one process to define register for paddleY always@(posedge clk) begin

     currentY = nextY;
     timer = timer + 1;

end

endmodule