Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog display moving object vertical and horizontal

Status
Not open for further replies.

guiaria

Newbie level 3
Joined
Apr 24, 2016
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
28
Hi All
am trying to write verilog code to create object that can move vertical and horizontal by pressing button on Xillinx Spatan3 board
I use code from https://www.fpga4fun.com/PongGame.html to create a ball but I can't make it move horizontal and vertical

my code for vertical moving that not working
PHP:
always @(posedge clk)
if(quadA)   // I NET quadA to one of button in board
ball_inY <= ball_inY +1 ;
else if(quadB)
ball_inY <= ball_inY -1;
and how to make it move horizontal ?
 

you should have shown in context what you are doing, that is probably why there have been no responses.

I did go to the 4fun site and took a look at the code. The following code adjusts the ball_inY signal:

Code Verilog - [expand]
1
2
always @(posedge clk)
if(ball_inY==0) ball_inY <= (CounterY==ballY); else ball_inY <= !(CounterY==ballY+16);


I don't know how you modified the code with your above code snippet, but unless you modified it in this block of code what ever you did will likely not work.
 

Right now I've change code to
Code:
reg [9:0] Xco = 100;
reg [9:0] Yco = 100;
reg [9:0] Xreg = 0;
reg [9:0] Yreg = 0;

reg tank;
always @(CounterX or CounterY)
begin
tank <= (CounterX>=Xco+20) &&  (CounterX<=Xco+36) && (CounterY>=Yco+20) && (CounterY<=Yco+40);
end

always @ (posedge clk)
begin

	if(!button)
	Xreg <= 1;
	else
	Xreg <= 0;
	if (!button2)
	Yreg <= 1;
	else 
	Yreg <= 0;
	if(!button3)
	Xreg <= -1;
	else
	Xreg <= 0;
	if(!button4)
	Yreg <= -1;
	else
	Yreg <= 0;
	
	end

always @(posedge clk)
begin
if(!button || !button3)
Xco <= Xco+Xreg;
if(!button2 || !button4)
Yco <= Yco+Yreg;
end



wire tank_W = tank;

but when i press button a red square box are disappear and randomly change it position
 

Hi
I did try the PongGame on an Altera board some years ago from the FPGA4Fun and it did work with 4 buttons, but the input does expect pulses from a quadratur encoder (rotary encoder)
So you have to use 2 buttons for X and 2 for Y and make a sequense on the button like s1 pressed hold it press s2 release s1 release s2 etc this will move the bar
in the original code.
if you reverse the sequense it moves the other direction, same for s3,s4 :)

Gues your code just inc to quickly and then you loose the bar
 

I have already changed line that use quadratur to normal button but what I don't understand is why when I plus Xco by 1 same as I plus Paddleposition my red square not moving like I plus Paddleposition
 

I made a RTL from your code, mayby it will be more clear on what happens?
tank.jpg
 

Sorry but I still don't get it. It there any problem with port ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top