Magical Toast
Newbie level 1
- Joined
- May 2, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,293
Okay So I am working on a project and I need some major help, i've looked at online tutorials and such and they haven't helped much. At the moment this is what I have.
I am using the Baysys 2 Board.
(Borderd is boarder detection and it works fine with this code and the tank moves fine and as needed)
This code here is for the motors of a tank and I have a to just press a button to start up the motors. However, my conundrum now is that I need to create a module for the turret to run along side this. The inputs for the turret are left and right as it detects an audio signal and just turns to face the target depending on which is higher. (mostly done in hardware) All that I need is to make it so that when the Left and right are roughly equal, that the motors stop and the turret sits and fires for about 3 seconds. (obviously a clock will be needed) after the turret has fired, the tank will move again and after a couple seconds, the turret detecting will start up again. (the module) how can I implement this? I'm very much confused how to create a clock and have 2 modules interact with each other in such a way. Thank you, I'll be looking at more tutorial stuffs in the mean time.
I am using the Baysys 2 Board.
Code:
module Test(
input [0:3] buttons,
input [0:3] boarderd,
output [0:3] motors,
input mclk
);
reg start = 0;
reg [0:3] reg_motor;
assign motors = reg_motor;
always @(posedge mclk) begin
if(buttons[0])
start <= 1;
if(buttons[1]) begin
start <= 0;
reg_motor[0] = 0;
reg_motor[1] = 0;
reg_motor[2] = 0;
reg_motor[3] = 0;
end
if(start == 1) begin
if (boarderd[1])
begin
reg_motor[0] = 1;
reg_motor[1] = 0;
reg_motor[2] = 1;
reg_motor[3] = 0;
end
if (boarderd[0])
begin
reg_motor[0] = 0;
reg_motor[1] = 1;
reg_motor[2] = 0;
reg_motor[3] = 1;
end
end
end
endmodule
(Borderd is boarder detection and it works fine with this code and the tank moves fine and as needed)
This code here is for the motors of a tank and I have a to just press a button to start up the motors. However, my conundrum now is that I need to create a module for the turret to run along side this. The inputs for the turret are left and right as it detects an audio signal and just turns to face the target depending on which is higher. (mostly done in hardware) All that I need is to make it so that when the Left and right are roughly equal, that the motors stop and the turret sits and fires for about 3 seconds. (obviously a clock will be needed) after the turret has fired, the tank will move again and after a couple seconds, the turret detecting will start up again. (the module) how can I implement this? I'm very much confused how to create a clock and have 2 modules interact with each other in such a way. Thank you, I'll be looking at more tutorial stuffs in the mean time.