PDA

View Full Version : [Question(s)] A Motor Controlled By Two Pins



Megasundato
08-30-2011, 07:41 PM
Hello my robot is essentially a circle controlled by two motors. One on its right, the other on its left .Forward motion of the right motor corresponds to i/o pin 3, while reverse is i/o pin 4. Left motor is 5 and 6 respectively. My troubles come with writing my program for the BS2.
Here's the link to the plans I'm using.


Main Site: http://tinyurl.com/smallbotemily

Programing: http://www.reconnsworld.com/programming_sb.html

I can't get the programing on this site to work, and it seems as if it is written to incorporate one motor per pin.

I'm very much a beginner, so my BASIC isn't complete. I believe that I need to write something which defines forward, left, right, and reverse movement so I can incorporate that with the sensors.

So how would one write something like that? Would you start off with defining lables such as...

Right CON pin 5, 1
etc.

I know you have to tell it to pulsout and stuff. So how could this all fit in together to make her move in a controllable way?

thanks

Quantum
08-30-2011, 08:33 PM
The basic program snipet would work for a servo only. Your feeding a pwm out on pins 0 and 1. If you have two motors then you either need to build a h-bridge circuit or purchase one. You wont be able to drive a motor off a stamp, you could actually damage it in the process.

Check this out:
http://www.reconnsworld.com/interface_sb.html

Megasundato
08-30-2011, 10:25 PM
Thanks for your reply. I forgot to mention some important details. The motor is powered by a different power source than the stamp-- 4 c batteries. I have built two circuits (one for each motor) found here http://www.reconnsworld.com/motorcontrol.gif
Supposedly, this circuit is to make the motors act like servos. My motors are not servos. They are just some motors I scrapped from an RC plane. They're similar to gearheads. They have two poles which are not polarity specific. I know little else about them.

Quantum. I believe I've done what you've suggested in your last post. Would you say that the program linked previously will not work for this design? If so, would you know anyway to get desired response? Right now, I can get the motor to spin by typing PULSOUT followed by the pin number comma millisecond duration of puls. Do you know of any other way to interface the motor with the software? Is there anything else that I may be missing?

p.s. I'm using BS2 version 1

thanks for the help

Quantum
08-31-2011, 12:39 AM
The circuit will work but your motors won't act like a servo. Its one way or the other. You cant control the motors like a servo. You could if you get creative with your software by a pulsing loop. But it still going to be a mess without encoders.

If you built the H-bridge correctly, when you drive one pin high and the other low you get motor movement.

Motor 1 are pins 3 & 4. Make pin 3 high and pin 4 low (forward). Or Pin 3 low and pin 4 high(reverse). This will give you forward and reverse. The same applies to the other motor.

Sample code:

High 3
Low 4
Pause 1000 (motor will move for 1 sec)
Low 3
High 4
Pause 1000(motor will move in reverse direction for 1 sec)

If you change the pause value, the greater it is the longer your motor runs.

One side note make sure you have common grounds in your circuit/curcuits.

Megasundato
08-31-2011, 12:39 PM
Ok great I'll try that. Before I've read this post, I was able to attain motion for one motor by just telling one pin to pulsout of a fairly long time, but I had to start the rotation by hand! With this said, I know there could definitely be some hardware problems, but Those may be fixed.
I see how your code will work. Thanks. I can't wait to try it.