Sunday 2 August 2009

Microprocessor Control

To use this h-bridge with a microprocessor, you must connect the three control lines to output pins on the microprocessor. Using the BasicStamp II as an example, consider the following hookup diagram.
As you can see three pins from the Basic Stamp are connected to each H-bridge board. In this example they are P0, P1, and P2 to the board controlling the left motor and P4, P5, and P6 to the board controlling the right motor. One of the advantages of using three pins that are both right next to each other, and in the same group of four bits (called nybbles) is that you can use a single variable (one of OUTA, OUTB, OUTC, or OUTD) to write to four pins at once.
This is really only important on chips like the BASIC Stamp where their can be a millisecond or more between the execution of one instruction and the next. By connecting them this way you can cause both motors to start turning with a single instruction such as this assignment:

OUTL = $33
Whereas if you did two instructions :
OUTA = $03 OUTB = $03

You would find that the left motor started turning first, then the right motor. So on a robot that steered with two motors the motor would make a slight turn to the right, then go straight. If you turned them off in the same sequence you would find that the robot corrected its heading back to the original heading but would not have traveled "straight" ahead. For systems that use gear motors such as the 12V Brevel motors or the Globe motors, this won't be a noticeable problem, but higher performance motors will definitely suffer.
Alternatively you could use something like my ServoGizmo project to drive one or two of these boards. The AntWeight ESC code could be easily modified to drive this bridge circuit rather than the 754410, however you could even drive two of these at the same time with some additional code. When the 754410 is not mounted on the Gizmo board you get 6 outputs from the PIC. If I have time I'll write a dual motor control with serial input so that you could connect the Gizmo to just one pin of the BASIC stamp and send it serial commands to control two motors.
The easiest way to use PWM on the motor is to start with the direction and enable bits "high" or at a logic 1 value. This turns on the high side (source) transistor and leaves the sink side transistor off. You can then send "low" pulses out the ENA* line to turn the motor on and off. This would allow you to use a single 'PWM' output, such as the one that is available on the PIC16F628, to control the PWM duty cycle in hardware while the PIC managed other aspects of controlling the motor. The most common use would be to provide encoder feedback into the PIC that would allow a simple PID algorithm to be implemented. With two bits of encoder input, three bits of motor control, and two bits for serial I/O the 16F628 would be well engaged.

Summary
The previous pages have gone through the design of simple H-bridge using bipolar junction transistors. If you read through this tutorial and build the H-bridge, you will be able to use this information in many future robots. The H-bridge that is presented is well suited to a wide variety of hobby motors and because you should understand it completely, it should be easily repaired should something fail. The next step in building H-bridges is to build them out of MOSFETs.

No comments:

Post a Comment