Figure 5. Pinout for the L293D.
shown in Figure 4. By switching on the transistors or FETs in opposite corners of the H-bridge, you can cause the motor to run. If you turn off those transistors or FETs and turn on the other two, the motor will start running in the opposite direction.
One additional thing that you can do is turn on the two top or two bottom transistors or FETs at the same time. This causes the motor's leads to be shorted together and will cause the motor to resist movement without your circuit having to provide any power to the motor. You can really see this with a geared motor. Try turning the output shaft with your fingers and then shorting the two motor leads together and turning it again. You should see a noticeable difference.
H-bridges are great little circuits, but they are not something that is easily designed. While this column treats them as digital circuits, they are definitely NOT digital and sit squarely in the realm of analog electronics. It can be a very frustrating experience to try to design your own H-bridge unless you have a solid foundation in analog electronics. Luckily for the robotics hobbyist and professional engineers alike, there are pre-made H-bridges on single chips or on circuit boards that you can buy. Some examples are the L293,
previously. Figure 5 shows the pinout for the L293D.
The L293D has three input lines for each H-bridge. There are two inputs that directly correspond to the two outputs. If one of these pins is set high, the corresponding pin will be set to your motor drive voltage. If you input a low signal, then the output pin will be set to ground. The third input line is the enable line. If this line is high, then the outputs will be as described above. If the enable pin is driven low, then the output pins will go high. In Figure 6, the L293D's enable lines are connected to the PIC16F873's PWM output lines. By using these peripherals, you will be able to control the speed of motors connected to the L293D chip.
Figure 7 shows a simple program that can control two motors for a robot that drives using tank-style steering. The program will cause the robot to slowly speed up until it reaches top speed, then slow back down to a stop, turn at full speed, and then go full speed backward before stopping. This program is made to compile in the CCS C compiler for a PIC16F873 with a 20 MHz crystal.
The way that the microprocessor is connected to the L293D in Figure 6 allows the motor to go in either direction or coast. This type of PWM is called "sign magnitude." This is not the only way to do PWM, though. There are two other types. One type is called "locked antiphase." This type of PWM keeps the enable line high and rapidly switches the direction that the circuit is trying to drive the motor. If you do this fast enough, the amount of time that you are driving it clockwise versus counter clockwise determines both the speed and direction of the motor.
There is one more way to control a motor through PWM. This method alternates between driving the motor and shorting the leads of the motor together to act as a brake.
Figures 8 and 9 show how the L293D could be set up to use these other two types of PWM. To drive the circuit in Figure 8, just send a PWM signal out to the H-bridge on the line corresponding to the motor that you want to control. To drive the circuit in Figure 9, you would have to do your PWM in software, since you would need to be able to hold one input for the H-bridge low and send a PWM signal to the other input. This would drive the motor in one direction. If you wanted
Was this article helpful?