Experiment No.8: Aim: To Study Interfacing of DC Motor With PIC18 Microcontroller Theory: Description

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Experiment No.

 Aim: To study interfacing of DC motor with PIC18 microcontroller

 Theory:
Description

Perhaps one of the most entertaining things to do with an embedded microcontroller is to get
it to actually move something. Three very popular devices used to “make things move”
include dc motors, RC servos, and stepper motors. This lab session will look at how you can
interface a dc motor to a PIC microcontroller.

Required Theory

DC motors are simple two-lead, electrically controlled devices that convert electrical power
into mechanical power through the interaction of two magnetic fields. One field is usually
produced by a stationary permanent magnet (on the stator), and the other field is produced by
an electric current flowing in the motor coil (on the rotor). The interaction of the two fields
results in a torque that tends to rotate the rotor. For this experiment, a reversible, permanent
magnet, brushed DC motor is selected. The term ‘reversible’ means the rotation of the motor
can be reversed by simply flipping the terminals of the DC power supply. One such motor is
shown below. I got it from my old broken printer. The dc motors are found in CD players, toy
cars, cassette player, printers, etc.

Modes of a brushed dc motor


A brushed dc motor has four fundamental modes: clockwise mode, counter-clockwise
mode, coast mode, and brake mode. In clockwise mode, the motor rotates in the direction of
the clock, and the counter-clockwise mode is just the reverse of the clockwise mode.
Switching between clockwise and counter-clockwise rotation is very simple. It can be done
by simply flipping the terminals of either the power source or the motor itself.

The coast mode  refers to the free spinning mode of the motor. If you twist the motor shaft
with your fingers, leaving both the terminals of the motor open, you will see the shaft
continues to rotate for a short time, until the kinetic energy of the shaft is totally consumed
through friction. Therefore, in coast mode, the terminals of a motor are left floating and the
motor comes to stop slowly.

The brake mode is used to rapidly stop the motor, and is done by shorting both the terminals
of the motor. The motor behaves as a generator when it is rotating, and if the terminals of the
motor are shorted, it acts as an infinite load bringing the motor to a rapid stop. Now the
energy in the motor is decayed much faster as it is consumed not only through friction but
also in the motor’s coil.

You can do a simple experiment to distinguish between the coast and brake mode. Take a
brushed dc motor and try to spin the shaft with your fingers, leaving the leads floating. You
Department of Electrical Engineering, Viva tech Prof. Ashwini Haryan
Experiment No.8

will observe the shaft rotates freely (coast mode). Now try again with the leads shorted. You
will find the motor has become more sluggish than in the coast mode.

Motor Driver

Microcontrollers are designed for data processing, which requires millions of skinny
pathways and microscopic switches. On the other hand, motors are straight forward and
power hungry. Because of the internal structure of microcontrollers, they cannot supply
enough current needed to run a motor directly. Therefore, an external driver circuit is
required to deliver the electrical power to a motor under the control of the microcontroller.
Such a driver circuit can be as simple as a single transistor or as complicated as an integrated
chip with some additional components attached.

Single transistor motor driver

The most basic motor driver circuit is a single transistor switch that can only turn a motor on
or off. The single transistor can turn the motor on in one direction only, either clockwise or
counterclockwise, depending upon how the motor is connected in the circuit. It also doesn’t
permit the motor to be electronically braked. The circuit diagram of a single transistor motor
driver is shown below.

Department of Electrical Engineering, Viva tech Prof. Ashwini Haryan


Experiment No.8

The working principle of this circuit is very simple. The transistor acts as a power switch for
the motor. The switch can be controlled through the logic voltage applied at the On/Off
terminal (see figure above). When the On/Off pin is at logic 1 (+5 V), the transistor is turned
on and the motor is connected across Vcc and ground. The Vcc voltage could be greater than
5 V. Therefore, one benefit of this single transistor motor driver is that you can control a
higher voltage motor (> 5 V) with a 5 V logic output from a microcontroller. The logic 0 at
the On/Off terminal turns the transistor off and the motor is stopped. The 1K resistor
connected in series with the base of the transistor limits the base current to a safe level.

The diode connected across the motor terminals is for the protection of the transistor. When
the switch is turned off, the collapsing electromagnetic field inside the motor generates a high
voltage across the motor terminals with reverse polarity. This voltage could be high enough
to damage the transistor permanently. The diode provides a current path back through the
motor coil, and hence prevents any high voltage formation. During normal condition the
diode is reverse biased and doesn’t affect the switching operation of the transistor.

H-Bridge Motor Driver

The single transistor motor driver has limitations. It can control a motor in only one direction
and does not allow electronic braking too. A classic H-bridge motor driver provides all 4
operating modes of a dc motor. It is called H-bridge because its circuit looks like a capital
letter H.

A standard H-bridge circuit consists of four transistors (two PNPs on top and two NPNs on
the bottom as shown below). The left half of the circuit is mirrored form of the right half. The
four inputs of the driver circuit are named as A, B, C, and D. When the terminal B is
grounded and the terminal C is pulled high (+5 V), the transistors Q2 and Q3 conduct. This
provides a path for current to flow from Vcc (+5 V), through Q2, through the motor, through
Q3 to the ground. This turns the motor on in one direction. Next, if the terminals A and D are
connected to ground and +5 V, respectively, Q1 and Q4 are switched on, providing a current
path from Vcc (+5 V), through Q1, through the motor, through Q4, and to ground. This time
the current through the motor is flowing in other direction and so the motor spins in the
opposite direction.

Braking mode can be achieved either by applying logic 1 (+5 V) to pins C and D or by
grounding A and B. In both the cases, the motor terminals are effectively connected.

The cost mode corresponds to when all the four transistors are turned off. This happens when
A and B are at logic 1 (+5 V) while C and D are grounded. Then the motor can spin freely as
the motor leads are connected to nothing.

Department of Electrical Engineering, Viva tech Prof. Ashwini Haryan


Experiment No.8

Important note

While implementing the H-bridge circuit, you must be careful about switching on the right
transistors at right time. If you are not careful and switch on both Q1 and Q3 (or Q2 and Q4)
simultaneously, that will result in a short circuit and the transistors may burn out. Out of 16
possible combinations for A, B, C, and D inputs, 7 results in short circuits, which must be
avoided. You can also tie A with C (say, AC terminal), and B with D (BD terminal) so that
now you will have only two terminals to control the motor. If you apply 1 at AC and 0 at BD,
the motor runs in one direction, and switching the logic levels at AC and BD will turn the
motor on in reverse direction. Applying 0 or 1 to both AC and BD will brake the motor. The
important thing is you cannot leave any of the terminals AC and BD float. Let’s look at the
AC terminal in more detail. Since A and C are tied together, and if it is left float then there
will be a path for current through the collector of Q1, through its base, through the base  of
Q3, through its emitter to the ground. So, Q1 and Q3 are on resulting a short circuit. So, you

Department of Electrical Engineering, Viva tech Prof. Ashwini Haryan


Experiment No.8

must be careful if you are thinking about reducing the control pins by tying A with C and B
with D. You just can’t leave the tied terminals open or float. They should be either grounded
or pulled high.

Once again, this circuit is just for testing a small motor under no load. If you need a more
practical circuit for driving a motor with load then you should consider using transistors with
higher current rating. Replacing BC557 with 2907A and BC547 with 2222A transistors can
increase the driving capacity of the circuit up to 600 mA. If your requirement is still higher
than that, it is suggested to use the MOSFET instead of BJTs.

Reference:
Intermediate Robot Building by David Cook

Department of Electrical Engineering, Viva tech Prof. Ashwini Haryan

You might also like