Programming an H-bridge

useless

Senior Member
Ok, so I know what an h bridge is. if I use a simple rectangle with four resistors v+ at the top and v- at the bottom and the motor in the middle. how am I to go about connecting it to the picaxe 8 pin chip and programming it?? also where do I put the battery?
 

Rickharris

Senior Member
Ah, no actually, that will not work. For several reasons you need to use transistors as switches or a dedicated IC such as a L293.

The L293 is controlled by two outputs from the picaxe. One makes the motor turn one way and the other the opposit way.

As an alternative you could use two relays.

look at the interface PDF manual for more details.
 

ylp88

Senior Member
<code><pre><font size=2 face='Courier'>-------------------+------------------------+-----------&gt; +V
| |
B | C C | B
Fwd &gt;------+----|&lt; &gt;|----+
| | E E | |
| | + - | |
| +---------( M )----------+ |
| | | |
| B | C C | B |
| +--|&lt; &gt;|--+ |
| | | E E | | |
| | | | | |
+-c----c------------------------c----+ |
| | | |
| | | |
Rev &gt;--------+----c------------------------c------+
| |
| |
+------------------------+
|
|
--------------------------------------------+------------&gt; 0V
|
V
</font></pre></code>

This inputs from the PICAXE are from the left. The power supply (battery) is connected to the power rails running the top and bottom.

More info should be available from the 'net. Google is a friend here...

<b><i>ylp88 </b> </i>

Edited by - ylp88 on 22/05/2006 07:29:13
 

useless

Senior Member
Sweet, um so can you give a code example for making the motor go fwd two seconds? (using this circuit of course) also, am I no allowed to use a 9v battery? How do I run 9v motors?

Edited by - useless on 22/05/2006 22:39:51
 

manuka

Senior Member
Yet again (!) I no doubt echo a forum plea for help requests to tell us FULL details about your need. It- ahem- may be worth spilling the beans re a school project &amp; allowed outside assistance too! <b>Splutter- </b> confusing resistors &amp; transistors indicates you need industrial strength help!

Hence 9V motors - why those? Why the 2 seconds? Fwd only needed? More than 1 motor? Is this a working project or experimental insight? Considered low voltage solar motors? Maybe steppers ? Time frame? Budget? Programming background? Picaxe experience? Age? Skills? Resources? Where -ahem- are you living as well!

ylp88 - great ASCII artwork. Take the rest of the day off. Stan (NZ based but roving)



Edited by - stan. swan on 22/05/2006 23:45:01
 

wilf_nv

Senior Member
The ASCII h-bridge by ylp88 requires base resistors, at least for the bottom common emitter transistors. With the h-bridge using common collector transistors on top, the motor supply must be equal to the picaxe +V or the top transistors will overheat.

In fact, the motor supply can be LESS than the picaxe +V supply (ie 3V) if series base resistors also used for the top transistors. The added advantage of using a lower motor supply is that the top transistors can saturate (low ON voltage drop).

With a 3V motor supply, the top base resistor value might be 100ohm while the bottom base resistors are 430 ohm. That provides about 10ma of base current for each transistor and can drive motors with a winding resistance of 10 ohm (300mA stall current). Be carefull not to apply a high level to both H-bridge inputs simultaneously or the transistors will likely self- destuct.

wilf
 

hippy

Ex-Staff (retired)
Ylp88's diagram is probably best taken as a theoretical illustration of what a H-bridge looks like stripped down to its minimum, it shows the principle but not necessarily the practicality ... Google will give much more information.

Here's one particular example, as used in Real Robots' Cybot. The top of the circuit shows a H-Bridge for a single motor which is very similar to that described.

http://www.lpilsley.co.uk/cybot/driver.htm

To control a H-bridge like that illustrated ( with FWD and REV inputs ) to drive a motor forward for two seconds, one would simply raise the required output pin from the PICAXE, hold it for two seconds, then lower it.
 

useless

Senior Member
Ok. but for my project I need some high torque and need the power of the 12v motors run on a 9v battery. Is this actually possible? yes? or no?.
 

manuka

Senior Member
<BLOCKQUOTE><font size=1 face=arial>quote:<hr height=1 noshade>Ok. but for my project I need some high torque and need the power of the 12v motors run on a 9v battery. Is this actually possible? yes? or no?. <hr height=1 noshade></BLOCKQUOTE></font><font face='Verdana, Arial, Helvetica' size=2>

12V/high power/high torque = yikes!(what ARE you doing?) &amp; probably too much current for a classic H bridge L293 to handle, as they're only good for 1A. Consider Picaxe driven relays however <A href='http:// www.picaxe.orcon.net.nz/npnamp.gif ' Target=_Blank>External Web Link</a>

Grunty 12V motor(s) run off a (small?) 9V battery = miniscule battery life of course...


Edited by - stan. swan on 23/05/2006 03:53:52
 

wilf_nv

Senior Member
Thanks hippy but the circuit in

http://www.lpilsley.co.uk/cybot/driver.htm

also contains a fatal flaw, namely the 10uF polarized capacitors across the motor windings. Replace those with 0.1uf and this classic h-bridge will work ok. Still goes up in smoke when both inputs are high. Nor does it have a &quot;brake&quot; mode.

 

jodicalhon

New Member
Similar 6-transistor H-bridges omit the 100R on the input NPN's collector, but increase this transistor's base resistor from the 1k shown to 100k.

I'd never thought of it before, but I assume the larger base resistor is to avoid the input transistor going into saturation, so that the transistor itself does the job of the 100R in the cybug h-bridge.

Is this assumption correct?

Edited by - Jo C on 23/05/2006 13:25:46
 

ylp88

Senior Member
Well, I suppose that there is no point in saturating the first transistor (the one that drives the &quot;output&quot; transistor) if a smaller current to the base of the output transistor will still make it saturate. It would just increase the power dissipation of the transistors unnecessarily.

Oh, and yes, my &quot;schematic&quot; was more of an &quot;idea&quot; of an H-bridge - not to me taken directly to practice. I was hoing to mention it but got caught up in the diting and forgot... <i>Sorry. </i>

EDIT: Given another look at the schematic, Q4 is probably saturated, given a 5V input signal via the 1k resistor (R29) and an Q4 hFe of 100 and Vbe of 0.7V. The base current though Q12 and Q7 is probably around 70mA (9V supply - 2V across 3 transistors = 7V -&gt; 7V / 100R = 70mA). Given that the hFe of Q12 and Q7 is supposed to be at least 140, that is 9.8A. Doubtful that the motor has a resistance/impedance of less 1 ohm, I'm quite sure that the ouput stage is also saturated. Seems like a waste of power to me, especailly if you are runnign it from a 9V battery!

<b><i>ylp88 </b> [i/]

Edited by - ylp88 on 23/05/2006 17:53:57 </i>
 

ylp88

Senior Member
Can we have more details about what you are using as your power supply and what motor you are using, as well as perhaps what kind of load the motors will be driving. It is all good that we can show you what an H-bridge is but now I think we are moving to a stage where you are asking for a more application specific design, in which case we need any information releavnt to the H-bridge you are trying to build.

Stan:<BLOCKQUOTE><font size=1 face=arial>quote:<hr height=1 noshade>Grunty 12V motor(s) run off a (small?) 9V battery = miniscule battery life of course... <hr height=1 noshade></BLOCKQUOTE></font><font face='Verdana, Arial, Helvetica' size=2>
Chances are that the internal resistance of a 9V battery will prevent it from supplying enough current in the first place, especially at high load (ie. high current.

<b><i>ylp88 </b> </i>
 

useless

Senior Member
Ok Im doing a student project without the aid of teachers who know anything (unfortunately) I am building a caterpillar type mechanism which in a way is just a /\ hinge like that, so, the main motor a (4 speed) single gearbox Tamiya motor which I have geared down to 344.2:1 pulls up the back leg and then locks (it is positioned in the middle at the hinge) then the front leg has a motor at the bottom (jaycar 12v 70rpm CAT. NO. YG2732) which is connected to the foot wheel that drives the wheel foward then locks then the process is repeated. reversing: the front motor drives backwards pushing the hing together then the top motor lets go and slides down. I also have a turning mechanism but am not concerned about incorperating that in this chip/circuit (so ignore that.)
-----------------------------------------

So basically I need two H-bridges, one for each motor. For the power I am not concerned at all what I use just as long as there's enough for both motors. 5v - 6v should be fine. I planned to use an 8 pin (PICAXE-08M)

Edited by - useless on 25/05/2006 06:37:58
 

Rickharris

Senior Member
We have done this at school on a fairly small scale and used a simple worm gear and small model motor, a picaxe 08 ran both motors through an L293 H bridge this seemed to be the simplest route and worked.

The BBC robots web site has some details on this type of design.
 

jodicalhon

New Member
I have used the Jaycar motor you mention at 6V, and it works fine. Coincidentally, I 've been playing with this motor and an H-bridge similar to that referenced in Hippy's link , and the motor drew around 36mA unloaded at 6V. The winding resistance is around 27 ohms (measured with my ohmmeter), so in a stall situation at 6v you will be drawing a little over 200mA max.

You could either use the L293, or an h-bridge built with BC337's and BC327's would do fine.

<code><pre><font size=2 face='Courier'>

----------------o----------------o---------
e / \ e
/ \
o-[1k ]--| b BC327 b |-[1k]-o
| \ / |
| c \ / c |
| |-----[motor]-----| |
-| | | |-
| c / \ c |
| / \ |
o-[1k]--| b BC337 b |-[1k]-o
\ /
e \ / e
| |
| |
---------------o-----------------o-----------

</font></pre></code>

This h-bridge would do fine.

(I know the artwork's a bit dodgy, but can I have the rest of the day off too, Stan? The afternoon?)

Cheers,

Jo

 

jodicalhon

New Member
I wrote earlier:
<i>Similar 6-transistor H-bridges omit the 100R on the input NPN's collector, but increase this transistor's base resistor from the 1k shown to 100k.

I'd never thought of it before, but I assume the larger base resistor is to avoid the input transistor going into saturation, so that the transistor itself does the job of the 100R in the cybug h-bridge. </i>

Just to follow up on that, I set up half a 6-transistor h-bridge as I've described (not the one just above)and ran it from 6 volts. Input transistor was a BC 547 and the output transistors were a BC327 and a BC337.

With 43uA in through the 100k, the BC547 was providing base current of 16.6mA to both outputs transistors (hfe = 386). Voltage drop across the BC547 was 4.4V (6 volts less 2 x 0.8V base/emitter drops). So the effective resistance of the BC547, in this instance, was 265 ohms (4.4/0.0166).

Even with a stall current of around 210mA through the motor, Vce of each output transistor was around 130mV. Not bad performance from the 327/337 combination!

Just in case anyone was interested....

Cheers.

Edited by - Jo C on 25/05/2006 15:15:44
 

useless

Senior Member
Sweet so let me just check something.
-------------------------------------------
So the upper most line in your diagramme goes to the +v in the chip and the negative of the 6v battery and the bottom most line connects to the positive of the 6v battery and the 0v on the chip and the two center lines on either side go to seperate outputs. is that correct?
 

useless

Senior Member
actually. come to think of it. If the 2 center lines do go to the outputs shouldn't they connect to the transistors in diagonals?
 

ylp88

Senior Member
It is not the H-bridge configuration I am used to but remember that the top transistors are PNP while the lower two are NPN. This means that an input to, say, the left hand pair will turn the top one off while the bottom one turns on. The right hand side input will be kept low turning the top-right transistor on while turning the bottom-right off.

<b><i>ylp88 </b> </i>
 

useless

Senior Member
yeah, I just realised about 4 minutes ago.(good Im glad i got something right.) but my assumtions to the connections to the chip were correct yes?
 

jodicalhon

New Member
The top line in the diagram is the positive rail. This is connected to the positive of your battery and the +ve of your chip.

The bottom line is the negative rail. This is connected to the negative of your battery and the -ve of your chip.

As ylp88 has stated, the top two transistors are PNP, the bottom two are NPN. The emitters of the PNP's are connected to the positive rail, and the emitters of the NPN's are connected to the negative rail.

Sorry about the dodgy artwork! The two small lines on either side are connected to two outputs of the Picaxe. To drive the motor one way, make one picaxe output high and the other low. To drive the motor in the opposite direction, just reverse the output states.
By making both outputs the same, i.e. both high or both low, the motor is braked.

This H-bridge needs inputs to be driven at Vcc and GND. So run both the h-bridge and the picaxe at the same voltage. This will probably be 5v, which should still be alright for the Jaycar motor, it just runs a bit slower. I gather your application isn't about pure speed, more about motor control and a novel locomotion style.

Please breadboard first, and see how you go.

EDIT: I've just had a bit of a play on my trusty breadboard - just the h-bridge, not driven by the picaxe - and it works fine at 5V. The base current through the 1k input resistors will be slightly less than 5mA each side (~10mA in total) - well within the limitations of the picaxe. Have a play and report back!

Cheers.

Edited by - Jo C on 26/05/2006 12:37:24
 

jodicalhon

New Member
Is the 5V max a real problem?

I suppose you should check that the motor torque will still be enough for your requirements at 5V. These are pretty strong little motors for their size, so you should be right, but it'd be worth checking.

I've had another play, and can suggest a rough design that can have its inputs driven from 5V and have the motor powered from 9V but, unfortunately, it lacks a brake function. (When I say 'rough design' I mean 'nothing's blown up on my breadboard yet and it's been 3 minutes - fingers crossed'!).

Edited by - Jo C on 26/05/2006 13:53:18

Edited by - Jo C on 26/05/2006 13:59:53
 

wilf_nv

Senior Member
Remember that Jo's h-bridge requires that the inputs must be at 0V or at Vcc. If you let the inputs float, the h-bridge will blow up.

wilf
 

useless

Senior Member
.Is it possible to run two h-bridges from 1 battery if I just connect them in parallel?

also if I want to continue using my 9v battery I should put in a 5v voltage regulator? how do I put that in the circuit?
 

ylp88

Senior Member
Have you read the datsheets available from the website and from the Prog. Ed. software? The &quot;Getting Started&quot; PDF is of interest to you - page 16, in particular, regarding your power supply.

You can connect the H-bridges in parallel but if you need as much torque and power from the motors as you seem to be suggesting, you should really start looking at something a bit more hefty than a measly 9V battery. 9V battereies are not designed for high current applications. You will find that even shorting a 9V battery can result in less than 1A running though it! Have you considered using 4 x 1.5V AA batteries? This will give you a good current power supply for your motors and with a two series diodes (eg. 1N4004), will provide 4.8V for your PICAXE chip.

<b><i>ylp88 </b> </i>
 

useless

Senior Member
Hmmm ok so I guess I could use the 4x1.5v with a 5v regulator(?) or two diodes, yeah, I might just do that
 

ylp88

Senior Member
If you use 4 x 1.5V AA batteries, you will not be able to use any old 5V regulator, such as the standard 7805. If you want to use a voltage regulator, you will need to use a &quot;low drop-out&quot; (LDO) type with a minimum forward voltage of less than 1V. Normal regulators (such as the 78xx series) all require around 2V - 2.5V greater at their inputs than their outputs in order to regulate correctly.

Simply put, if you want to use the 4 x 1.5V AA batteries, just stick two 1N4004 (or similar, NOT 1N914/1N4148) in series with the batteries to power the PICAXE:

<code><pre><font size=2 face='Courier'>------------+-----------------------------------+-------+
| | | |
V 1N4004 |&lt; &gt;| |
- | | |
| | | |
V 1N4004 +-------(M)--------+ -----
- | | ---
| | | |
+------------+ |&lt; &gt;| -----
| +V | | | --- 4 x 1.5V
| | | | | AA
| | +------------------+ ----- battery
| PICAXE | | --- pack
| or | ^ | |
| other | | | -----
| uC | | | ---
| | simplified -* | |
| 0V | h-bridge | |
+------------+ | |
| | |
------------+-----------------------------------+-------+
|
V
GND </font></pre></code>

Remember to include power supply filtering for the PICAXE chip after the diodes - connect a 0.1uF capacitor between the PICAXE's +V and 0V pins.

<b><i>ylp88 </b> </i>
 

Mycroft2152

Senior Member
How about a link to the motor you are using? This will give all of us enough informtion to stop guessing and provide some real help.

TANSTAAFL!

Myc
 

useless

Senior Member
http://www.jaycar.co.nz/productView.asp?ID=YG2740&amp;CATID=&amp;keywords=gearbox&amp;SPECIAL=&amp;form=KEYWORD&amp;ProdCodeOnly=&amp;Keyword1=&amp;Keyword2=&amp;pageNumber=&amp;priceMin=&amp;priceMax=&amp;SUBCATID=

is motor1 (geared to 344.2:1)

and..

http://www.jaycar.co.nz/productView.asp?ID=YG2732&amp;CATID=&amp;keywords=70rpm&amp;SPECIAL=&amp;form=KEYWORD&amp;ProdCodeOnly=&amp;Keyword1=&amp;Keyword2=&amp;pageNumber=&amp;priceMin=&amp;priceMax=&amp;SUBCATID=

is motor 2

Edited by - useless on 27/05/2006 11:03:25
 

ylp88

Senior Member
One of the motors is rated at 390mA (not the Tamiya one) at full load. Have you considered using the L293 H-bdrige chip? It is rated at 600mA per channel with a peak output of 1.2A (non-continuous). I'm not sure about the other motor though, but given it is a small motor that is geared down, chances are that it's current draw should be relatively modest too - possibly low enough for you to use the other channel of the L293 to drive it.


If so, it would greatly simplify your design process as you can follow the PICAXE manuals and datasheets directly as this chip is widely used in the PICAXE system.

<b><i>ylp88 </b> </i>
 

Mycroft2152

Senior Member
What is that? A polite &quot;Start by reading the manual&quot;

Where have I heard that before?

And only 37 posts later.

I guess I shouldn't be so hard on the newbies, after all it is our responibility to ask the right questions before throwing out a storm of answers.

Myc

Edited by - mycroft2152 on 27/05/2006 11:48:14

Edited by - mycroft2152 on 27/05/2006 11:51:45
 

hippy

Ex-Staff (retired)
Without meaning any offence to 'usless' and everyone who has posted here, I think we've gone off at a tangent and are missing the big picture.

Useless has a rather ambitious project - a caterpiller thing with motors which need to be driven, locked and all controlled by a PICAXE - and all being done without the aid of teachers who understand the project.

We've got stuck in trying to solve one problem ( H-bridge drive ) and that's understandingly meandering all over the place ( and I don't mean that in a bad way ) but it's not really taking the project forward, and there are other issues as well; how are the motors locked and unlocked, can a PICAXE-08 control all this, how ?

I think we have a case of trying to run before being able to walk ( and advising on the best running technique ), and I think the best course of action is to step back a little or we'll be stuck in the H-bridge discussion forever.

To useless, I would recommend recognising that this is an ambitious project with a lot of complexity and detail. Accept that, at present, you probably don't have all the knowledge or experience you may need to pull this off, and build up that knowledge before going onwards.

I would recommend starting with just trying to control an L293D H-bridge from a PICAXE, using motors which it is capable of driving. That will give you a great base from which to move forward from.

I personally would say that building a robot/buggy would be a pre-requisite to building something which appears to me to be more complex.

One other thing; what timeframe were you hoping to get this project completed in ?
 

useless

Senior Member
I have had plenty of experince with structural design etc, positioning motors where they will work best and gearing them to whats needed its just the actual electronics/components etc that I am learning about. but I'm currently working on a programme for an H-bridge in a breadboard so i'll see how I go first before looking at purchasing anything else.
cheers though
 
Top