H-bridge for DC motor control Directional control Control algorithm for this h-bridge circuit A B 0 0 Stop 0 1 Forward 1 0 Reverse 1 1 Prohibited This circuit has the advantage of small voltage drop due to the transistors, however braking is not available as transistors Q 1 and Q 2 cannot be turned simultaneously, so as Q 3 and Q 4. Turning on transistors Q 1 and Q 2 at the same time (both input A and B are high), will turn on transistors Q 3 and Q 4 at the same time. And that means short-circuiting through transistors Q 1 and Q 3 as well as through transistorsq 2 and Q 4. This will damage all 4 transistors
Speed Control To control the speed of a d.c. motor we need a variable voltage d.c. power source. While a variable resistor can derive a variable d.c.voltage from a fixed d.c. source voltage it is not a efficient way of controlling d.c. voltage as a portion of the energy is converted to heat by the resistor. Pulse Width Modulation (PWM) If you take a 12v motor and switch on the power to it, the motor will start to speed up: motors do not respond immediately so it will take a small time to reach full speed. If we switch the power off sometime before the motor reaches full speed, then the motor will start to slow down. If we switch the power on and off quickly enough, the motor will run at some speed part way between zero and full speed. This is exactly what a p.w.m. controller does: it switches the motor on in a series of pulses. To control the motor speed it varies (modulates) the width of the pulses - hence Pulse Width Modulation. A pulse width modulator (PWM) is a device that may be used as an efficient light dimmer or DC motor speed controller. A PWM circuit works by making a square wave with a variable on-to-off ratio, the average on time may be varied from 0 to 100 percent. In this manner, a variable amount of power is transferred to the load. The main advantage of a PWM circuit over a resistive power controller is the efficiency, at a 50% level, the PWM will use about 50% of full power, almost all of which is transferred to the load, a resistive controller at 50% load power would consume about 71% of full power, 50% of the power goes to the load and the other 21% is wasted heating the series resistor The effective voltage developed depends on the time-on and time-off ratio.
Pulse Width Modulation is usually achieved by using electronic timing circuits or using in-built timing circuits of microprocessors. PWM Circuit Motor We can simulate a PWM operation by using the parallel port and the h-bridge circuit we have tried on. Control algorithm for this h-bridge circuit A B 0 0 Stop 0 1 Forward 1 0 Reverse 1 1 Prohibited By setting input A of the h-bridge at zero and switching input B on and off we can have PWM for the forward rotation of a motor. By setting input B of the h-bridge at zero and switching input A on and off we can have PWM for the reverse rotation of a motor. Pin 2 A Pin 3 Pin 18 ~ 25 B H-bridge Circuit Parallel port cable Use the data register (888) of the parallel port to set the inputs (A and B) of the h- bridge
To turn on and off the motor in the forward motion, the data of 0 and 2 have to be sent alternatively to the data register (888) To turn on and off the motor in the reverse motion, the data of 0 and 1 have to be sent alternatively to the data register (888). Qbasic program to Simulate PWM DIM direction AS STROMG DIM keypressed AS STRING DIM time_on AS INTEGER DIM time_off AS INTEGER DIM timecount AS INTEGER Direction = F time_on = 1000 time_off = 1000 Start: Keypressed = INKEY$ IF keypressed = + THEN time_on = time_on + 100 IF keypressed = - THEN Time_off = time_of + 100 IF keypressed = F OR keypress = R OR keypressed = H THEN direction = keypressed IF direction = F THEN gosub Forward IF direction = R THEN gosub Reverse OUT 888,0 Forward: OUT 888,2 gosub Ontime OUT 888,0 gosub Offtime Reverse: OUT 888,1 gosub Ontime OUT 888,0 gosub Offtime Ontime: FOR timecount = 1 TO time_on NEXT Offtime: FOR timecount = 1 TO time_off NEXT Remark this is not part of the program the codes underlined in the program is supposed to be on one line GOTO Start
Important points of the project 1. The h-bridge should have free-wheeling diode incorporated to protect the transistors from back emf of the motor during switching 2. Qbasic allows control in steps of integer seconds through the command SLEEP. The minimum time to turn on or turn off the motor would be 1 second if the SLEEP command is used. And this will cause the motor running intermittently. To use custom subroutines of delay can partly solve the problem but there are drawbacks: The delay routine will be dependent on the speed of the processor of the computer therefore there is no way of accurately controlling the on time and off time. The looping of the main program also add extra delay to the on and off times. 3. If the circuit does not wok properly, check that The ground of the h-bridge and the ground of the parallel port are connect. The 2 transistors connected to +5V are PNP transistors (e.g. BC327) and the other 4 transistors are NPN transistors (e.g. BC337) The pins of transistors are connected correctly. Remember the word CLER when you look down onto your circuit with the flat side of the transistor facing you. (Collector Left & Emitter-Right). This is true only for transistors with the TO-92 package. Check your program, particularly the spelling of the variables like direction, time_on, time_off, etc.