Motors

Started by sawtape December 26, 2004

I am interested in using my bx 24 to control a little robot that moves
forward until an infrared sensor sees something within 6 inches or so
and then turns so it never runs into anything.

But before I fry my controller, I was wondering how I should go about
powering the motors. Should I just turn a pin on and off? Will the
motor draw too much current and fry the chip? Could I make a
connecdtion from the battery to the motor interrupted by a transistor
and use that to control the motor? It would be a great help if you
would let me know! Thanks.




Your question might have saved you a microcontroller - glad you asked first.
A microcontroller cannot power a motor, but it can control another device that powers a motor. These devices, called "H-bridges" are designed for this purpose. They take a small signal(s) from a microcontroller and thereby control a motor with greater current requirements.

You were on the right track when you mentioned the transistor controlling the motor. An H Bridge takes this principal a bit further. A transistor only allows forward movement and an H-Bridge allows forward an reverse - handy when you go to make your turn.

The SN754110 and L293 are rather popular - others exist as well. Besides the power conversion, H Bridges make provisions for speed control, protection diodes, and logic circuitry to protect from all the transistors being active at once - causing a battery short circuit. If you choose to use a transistor & resistor, make sure to add a diode. The motor's inductance will want to continue to drive current after it is turned off.

The following circuit will turn a small motor on and off. Choose the diode & transistor based on your voltage and motor current. Resistor in the 1k - 10k range.

V+
I
----------
I I
M _
I ^
I I
-----------
I
/
---\/\/\/--- \
_GND

For your distance sensor, you may want to consider the Sharp GP2 Series. There is a application note for the GP2Y0A02YK that came with the BX24 documentation. The GP2D15 looked like something you might be looking for - goes HIGH when object is at 24cm. If you go this route, be sure to get a connecting cable.

Thad

sawtape <> wrote:

I am interested in using my bx 24 to control a little robot that moves
forward until an infrared sensor sees something within 6 inches or so
and then turns so it never runs into anything.

But before I fry my controller, I was wondering how I should go about
powering the motors. Should I just turn a pin on and off? Will the
motor draw too much current and fry the chip? Could I make a
connecdtion from the battery to the motor interrupted by a transistor
and use that to control the motor? It would be a great help if you
would let me know! Thanks.
---------------------------------




Thanks for the help. I did some late night browsing last night and
found out the info i needed though. I assembled a circuit today (a 1
transistor job, still need to get a diode for it so I don't fry the
dumb thing) but am having trouble getting the circuit to work. When I
manually supply power to the base lead of the transistor the motor
buzzes away but if i try to write a byte of 1 from the microcontroller
to the pin connected to the base lead nothing happens. Examination
with a multimeter (I finally learned to use one of them) revealed that
when by bit was being written there was actually a negative current on
the circuit! How do I get the bx24 to send out a positive voltage so
the motor will turn?

--- In , Thad Larson <highwayman_33402@y...> wrote:
> Your question might have saved you a microcontroller - glad you
asked first.
> A microcontroller cannot power a motor, but it can control another
device that powers a motor. These devices, called "H-bridges" are
designed for this purpose. They take a small signal(s) from a
microcontroller and thereby control a motor with greater current
requirements.
>
> You were on the right track when you mentioned the transistor
controlling the motor. An H Bridge takes this principal a bit
further. A transistor only allows forward movement and an H-Bridge
allows forward an reverse - handy when you go to make your turn.
>
> The SN754110 and L293 are rather popular - others exist as well.
Besides the power conversion, H Bridges make provisions for speed
control, protection diodes, and logic circuitry to protect from all
the transistors being active at once - causing a battery short
circuit. If you choose to use a transistor & resistor, make sure to
add a diode. The motor's inductance will want to continue to drive
current after it is turned off.
>
> The following circuit will turn a small motor on and off. Choose
the diode & transistor based on your voltage and motor current.
Resistor in the 1k - 10k range.
>
> V+
> I
> ----------
> I I
> M _
> I ^
> I I
> -----------
> I
> /
> ---\/\/\/--- \
> _GND
>
> For your distance sensor, you may want to consider the Sharp GP2
Series. There is a application note for the GP2Y0A02YK that came with
the BX24 documentation. The GP2D15 looked like something you might be
looking for - goes HIGH when object is at 24cm. If you go this route,
be sure to get a connecting cable.
>
> Thad
>
> sawtape <menuet@g...> wrote:
>
> I am interested in using my bx 24 to control a little robot that moves
> forward until an infrared sensor sees something within 6 inches or so
> and then turns so it never runs into anything.
>
> But before I fry my controller, I was wondering how I should go about
> powering the motors. Should I just turn a pin on and off? Will the
> motor draw too much current and fry the chip? Could I make a
> connecdtion from the battery to the motor interrupted by a transistor
> and use that to control the motor? It would be a great help if you
> would let me know! Thanks. >
> ---------------------------------
>




Ok friend here is a new concept for you. Most likely you are not reading the right signal some how, pin high is pin high...

The new concept is pull up resistors... I won't go into much details but here is how it works... I will try to explane it simple..

between the out pin on the bx24 and the base of the transistor put a 1k resistor (quick guess of value), that goes one end in between bx pin and base and the other end to vcc or +5 volts, when you send a high it will make sure you get a real positive voltage and prevent it from floating... You can experiment ether with a pull up or pull down, the resister goes to ground in the pulldown.. Also check is bx has a built in pullup or tri state. I am guessing that it should. But for now try the pullup with the resistor. Just don't do pullup and down at the same time cause it will divide the incomming voltage to the transistor.. I,l explain this next time...

For now hook one leg of the resistor between the bx pin controlling the transistor and the transistor base, kind of hooking three things togheter... The other leg of the resistor goes to voltage or , +5volt or vcc or whatever you call the positive supply..

After this work try using a pull down by hooking the voltage or vcc leg of the resistor to ground and see how it works... This configuration is better because it will drive the motor off while the bx boots and the pull up willl make the motor turn on while booting or until you send a negative or low bit.

Ohh don't worry the resistor will prevent a short ciurcuit if you hook vcc to ground or vice versa thru the resistor...

I hope this helps....



In a message dated 12/27/2004 11:18:35 PM Eastern Standard Time,
writes:
How do I get the bx24 to send out a positive voltage so
the motor will turn?
Try using a PNP transistor, they are activated by low rather than high
signals to the base

Randy




I think I may have a hint as to the problem. I am using the junky
little test board that came with the bx 24 and it has a 9volt AC
adaptor. Could the motor/transistor/negative current problem have
anything to do with the fact that I'm powering it this way instead of
by using 5 volt power??




Hi sawtape,

Actually, the Basicx-24 Chip, BasicX-24 Development board rev2, BasicX-24 CD, Serial Download Cable, and the Power Transformer is a pretty nice complete microcontroller system that assures you start with a known good working system of hardware and software. As you develop software programs and test them you'll find that having a known good working hardware platform to test on is very important.
When you add hardware (like external batteries, D.C. Motors, Sensors, etc.) it is actually adding additional electronic circuitry to the system schematic. Design rules and limitations must be followed if you are to achieve a successful design.
In your question, I don't think the problem is with the BX-24 hardware setup. The first thing that would be good to do is to characterize the motors and external battery. If the D.C. voltage rating of the motor is not listed in the documentation, then fully charge the robots batteries and measure the D.C. voltage (set multimeter on approx 20 VDC scale) that is at the 2 motor terminals when it is running at full speed. That's probably pretty close to the motor design voltage. Depending on which is easier, open the circuit at the negative (probably black) terminal of the motor or the battery, (set multimeter for DC Amps, highest scale) and insert the meter in series with the motor circuit. Run the motor at full speed, apply a little load to the wheel and measure the current. If you multimeter has a lower scale that is in that range, use it to get more resolution. This is the nominal motor current. The motor voltage multiplied by the motor current is the motor power in watts. E*I=P. E in volts, I in amps, P in watts. Now you have a general idea how much load the motor is. There are many ways to control robot motors. In your simple ON/OFF example, you would use a silicon NPN transistor for a switch. The minimum specs for the transistor would be Vce > 5 * motor voltage, Ic > 5 * Motor current and a "gain" Hfe > 2 * motor current in mA / 5 mA. You will need a silicon power diode (typ. 1N1004) wired in parallel with the motor leads. You will need a 1/8 or 1/4 watt carbon resistor ( approx 1K to 5.1K) to series limit base current (conventional flow) from the BX-24 output pin connection to the transistor base terminal. Depending on the transistor and motor load you may have to use a heat sink on the transistor. Now you have 6 new electronic components to add to the system schematic, i.e. battery, motor, diode, transistor, base resistor and insulated conductors (wires).
For example, one robot motor is wired as follows, a wire circuit connects the negative terminal of the battery, emitter of the transistor and the "GND" of the working BX-24 system. A wire circuit connects the positive terminal of the battery, the cathode (stripe) of the silicon diode and the positive terminal of the motor. A wire circuit connects the negative terminal of the motor, anode of the silicon diode and the collector of the transistor. A wire connects one end of the base resistor to the base of the transistor, a wire connects the other end of the resistor to the selected output pin on the BX-24 chip.
Code for the BX-24 should configure the selected pin as OUTPUT. "Writing" a "0" to the pin will cause that pin to go to +0 VDC relative to GND and the transistor will be OFF."Writing" a "1" to the pin will cause that pin to go to +5 VDC relative to GND and "turn ON" the transistor.
There a lot of details that can be fine tuned and adjusted, this is just the basic idea. Search Google for "motor controllers" and "motor circuits", etc. There are many good books and magazines for robotics, that cover everything from basic electronics theory to advanced sensor algorithms. Understand Ohm's Law, see
http://www.the12volt.com/ohm/ohmslaw.asp
Find out what Kirkoff's Law says.

Best Regards, Eric
----- Original Message -----
From: sawtape
To:
Sent: Tuesday, December 28, 2004 6:57 PM
Subject: [BasicX] Re: Motors
I think I may have a hint as to the problem. I am using the junky
little test board that came with the bx 24 and it has a 9volt AC
adaptor. Could the motor/transistor/negative current problem have
anything to do with the fact that I'm powering it this way instead of
by using 5 volt power??


Do you have a separate regulator or are you using the on-board regulator?

When you say negative current, does that mean that the base of your transistor has a greater voltage than your BX24 ?

BX24--- ~0V ---\/\/\/\------ ~5V ---- transistor

or is this the case ??
BX24--- ~5V ---\/\/\/\------ ~9V ---- transistor

or is it possible that you were measuring current with the wires switched around? -I've done that all too often...

Thad
sawtape <> wrote:

I think I may have a hint as to the problem. I am using the junky
little test board that came with the bx 24 and it has a 9volt AC
adaptor. Could the motor/transistor/negative current problem have
anything to do with the fact that I'm powering it this way instead of
by using 5 volt power??

---------------------------------
Yahoo! Groups Links

To
---------------------------------



It sounds like you aren't understanding the transistor you are
trying to use.

There are two basic transistor flavours, NPN and PNP:

NPN transistors need to go AFTER the load (between motor and ground)
and you turn them on with a positive voltage. I remember this goes
on the "negative" side of the motor because NpN has two Ns. Remember
that the positive voltage must be positive in relation to the supply
voltage! If its getting 9V then your signal must be higher. This is
why the are used after the load - voltage is usually just the
forward voltage of the transistor itself and 5V is more than enough.

PNP goes BEFORE the load and is turned on by connecting the base to
ground. Since PnP has two Ps, I remember it as going on the positive
side of the load.

The letter in between tells you the signal you need to apply to turn
it on. pNp requires ground, nPn requires a positive voltage.

Another thing you have to realize about transistors is that current
also flows through the base. For NPN, current will flow from your
microcontroller pin through the transistor and to ground. For PNP,
current flows from the motor supply to your microcontroller. This is
what "HFE" refers to. If you look at the 2N3906 datasheet "On
Characteristics" you'll see the HFE is somewhere between 30 and 100
depending on total current - call it 60 for simplicity. If you let 1
mA flow through the base then 60 mA can flow through the transistor.

CAUTION! With a PNP, since current is flowing to your MCU, the
supply VOLTAGE is also applied to your MCU. In your case, 9 volts
would be applied to the pin - which could fry it. If it doesnt fry,
you would be getting reverse current (9V->5V). The motor would only
get 4V - whatever the voltage drop across the transistor is.

To use PNP on the high side, add another NPN transistor. Run the PNP
base through the NPN to ground, then you can turn on the NPN with a
MCU pin and allow the PNP base to drain to ground regardless of the
motor supply voltage.

Just dont forget your base resistors! Read the datasheet, get the
HFE and select the appropriate resistor. --- In , "sawtape" <menuet@g...> wrote:
>
> Thanks for the help. I did some late night browsing last night and
> found out the info i needed though. I assembled a circuit today
(a 1
> transistor job, still need to get a diode for it so I don't fry the
> dumb thing) but am having trouble getting the circuit to work.
When I
> manually supply power to the base lead of the transistor the motor
> buzzes away but if i try to write a byte of 1 from the
microcontroller
> to the pin connected to the base lead nothing happens. Examination
> with a multimeter (I finally learned to use one of them) revealed
that
> when by bit was being written there was actually a negative
current on
> the circuit! How do I get the bx24 to send out a positive voltage
so
> the motor will turn?
>





OK. I realize I need to be a LOT more specific in order to get a
helpful answer. Sorry guys.

I'm gonna make a lame attempt at a schematic diagram for the circuit.

Transistor 1 is NPN

BX-24(Pin 1)-----------------Transistor 1 (Base Lead)

+3 Volts DC------------------Transistor 1 (Collector Lead)

Transistor 1 (Emitter Lead)
|
Diode 1
|
|
DC Motor
|
DC Ground--------------------------------|

OK. Hopefully that is understandable.

Here is my code:

public ButtonPin As Byte = 6

sub main()
Call PutPin(ButtonPin,bxInputPullup)
do
If (GetPin(ButtonPin) = 0) Then
call putpin(1,1)
Else
call putpin(1,0)
End If
Call Delay(0.1)
loop
end sub

What's Wrong?