You are on page 1of 77

“P.C. Interfaced Speed Control of D.C.

Motor”

A PROJECT REPORT
SUBMITTED IN PARTIAL FULFILLMENT
OF THE REQUIREMENT FOR THE AWARD OF THE B.TECH DEGREE IN
ELECTRICAL & ELECTRONICS ENGINEERING

SUBMITTED BY:

KARAN KUMAR
MANSI AGGARWAL
PRANAV HALDAR

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING


COLLEGE OF ENGINEERING ROORKEE
ROORKEE -247667 (INDIA)
(AFFILIATED TO UTTRAKHAND TECHNICAL UNIVERSITY, DEHRADUN)
P.C. Interfaced Speed Control of D.C. Motor

SESSION: 2009-10

A PROJECT REPORT

ON

P.C. Interfaced Speed Control of D.C. Motor

Submitted in partial fulfillment of the requirement for


the award of degree of B.Tech in
ELECTRICAL & ELECTRONICS ENGINEERING

PROJECT GUIDE: SUBMITTED BY:

Mr. Ashish Pratap Singh Karan Kumar


Mansi Aggarwal
(Lecturer) Pranav Haldar

DEPARTMENT OF ELECTRICAL & ELECTRONICS ENGINEERING


COLLEGE OF ENGINEERING ROORKEE
ROORKEE – 247667 (INDIA)

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

2009-10

CERTIFICATE

This is to certify that the project entitled


“P.C. Interfaced Speed Control of D.C. Motor” submitted by:

i. Karan Kumar
ii. Mansi Aggarwal
iii. Pranav Haldar

has been done under my guidance and supervision, in partial fulfillment of the
requirement for the award of B.Tech Degree in Electrical and Electronics
Engineering by Uttrakhand Technical University, Dehradun for the session 2009-10.

This report had not been submitted for any other examination and does not form a
part of any other course undergone by the candidate.

Mr. Sanjay Sinha Mr. Ashish Pratap Singh


Head of Department Project Guide

DEPARTMENT OF ELECTRICAL & ELECTRONICS ENGINEERING


COLLEGE OF ENGINEERING ROORKEE
ROORKEE – 247667 (INDIA)

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

ACKNOWLEDGEMENT

We take this opportunity with much pleasure to thank all the people who have helped us through
the course of our journey towards making of this project. I sincerely thank my Project guide, Mr.
Ashsish Pratap Singh, for his guidance, help and motivation. Apart from the subject of our project,
we learnt a lot from him, which we’re sure will be useful in different stages of our lives. We
would like to express our gratitude to the other members of Electrical Department: Prof. Sanjay
Sinha for much help with the project selection and guidance, and Prof. J.K. Vaishishth for his
review and many helpful comments.

We are thankful to all the other Fellow students (past and present) of College Of Engineering
Roorkee (COER) with whom I share tons of fond memories.

We would also like to thank the lab assistants at Power Electronics and Electrical Machine Lab for
their continuous support and help in making the project a success.

Our sincere gratitude also goes to all those who instructed and taught us through the years.

Finally, this project would not have been possible without the confidence, endurance and support
of our family members. Our families have always been a source of inspiration and encouragement.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

CONTENTS

1. Introduction

2. Abstract

3. Block Diagram

3.1 DC Motors
3.2 Drive and Control Circuitry
3.3 Sensors
3.4 3.4 Parallel Port

4. Circuit Designing

5. Software & Flowchart

6. Program

7. Components used

8. Construction and working

9. Pulse Width Modulation

10. Feedback

11. Observations

12. Conclusion

13. Applications

14. References

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

ABSTRAC
T
By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

ABSTRACT

The aim of our project was to implement a complete automatic speed control system for a DC
motor. Usually, speed control of the DC motors in the industries is controlled by interfacing the
motor through a Micro-controller which is a costly affair. Thus our idea is to use the Computer’s
processor to control the D.C. motor. Thus interfacing the D.C. motor through the LPT port,
usually known as Printer Port, helps us control the motor through the “H Bridge Circuit”.

Also the project can be further extended for different electrical appliances and can on later stage
be controlled from anywhere in the world if the specified P.C. has an internet connection.

For our project, particularly, we’ve obtained a 0.5kW DC motor (considered to be a suitable
prototype for a typical industrial application) from the Market, the project was carried out with the
following objectives:

1. Implementation of PWM Signal Generator (using C++).


2. Implementation of the H-Bridge Drive (using Transistors).
3. Implementation of Speed and Current Feedback circuitry.
4. Software implementation of the closed loop controller.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

INTRODUCTION

Controlling any device while sitting at a PC terminal appears to be a very fascinating and
convenient job. The ideas and technology underlying our project is very simple. A simple
hardware interface circuit and its driver software enable the controlling of the DC motor. Often,
people attempt to control DC Motors with a variable resistor or variable resistor connected to a
transistor. While the latter approach works well, it generates heat and hence wastes power. Thus
simple Pulse Width Modulation DC motor control eliminates these problems. It controls the motor
speed by driving the motor with short pulses. These pulses vary in duration to change the speed of
the motor. The longer the pulses, the faster the motor turns, and vice versa.

The hardware consists of discrete elements such as transistors, resistors and DC motor of the
required specifications. The software comprises mainly the coding for a graphical user interface
(GUI) written in C++. The interfacing of the DC motor with the PC is done through the LPT port,
which is usually known as Printer Port.

Controller is actually a combination of two circuits:

Controller = Driver + Switching Circuit

Driver is the actual circuit that drives DC motor and switching circuit decides how DC motor
should be driven. Thus, switching circuit is the main circuit that controls the motor. Now there are
two parameters of DC motor that you can control:

1. Speed
2. Direction
Changing the direction of DC motor is very simple just reverse the supply given to DC motor. For
varying speed of motor you have to vary the applied DC voltage. One well known method to vary
voltage is to use resistance (rheostat or potentiometer) in series with DC supply. Another method

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

is to apply pulse width modulated (PWM) wave to DC motor. As the width of pulse varies average
voltage applied to motor varies and so the speed of motor also varies.

In this project we have used standard “H-Bridge circuit” as a DC motor driver and software
program (written in C++) as a PWM generator. Program generates PWM wave to vary the speed
of motor as well as change the direction of it depending upon user command.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

d. c.
Motor
By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

D.C. MOTORS

Introduction
The Direct Current (DC) motor is one of the first machines devised to
convert electrical power into mechanical power. Permanent Magnet
(PM) direct current converts electrical energy into mechanical energy
through the interaction of two magnetic fields. One field is produced
by a permanent magnet assembly; the other field is produced by an
electrical current flowing in the motor windings. These two fields result in a torque which tends to
rotate the rotor. As the rotor turns, the current in the windings is commutated to produce a
continuous torque output. The stationary electromagnetic field of the motor can also be wire-
wound like the armature (called a wound-field motor) or can be made up of permanent magnets
(called a permanent magnet motor).

In either style (wound-field or permanent magnet) the commutator acts as half of a mechanic
switch and rotates with the armature as it turns. The commutator is composed of conductive
segments called bars (usually made of copper) which represent the termination of individual coils
of wire distributed around the armature. The second half of the mechanical switch is completed by
the brushes. These brushes typically remain stationary with the motor’s housing but ride (or brush)
on the rotating commutator. As electrical energy is passed through the brushes and consequently
through the armature a torsional force is generated
as a reaction between the motor’s field and the
armature’s field causing the motor’s armature to
turn. As the armature turns, the brushes switch to
adjacent bars on the commutator. This switching
action transfers the electrical energy to an adjacent
winding on the armature which in turn perpetuates
the torsional motion of the armature.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Permanent Magnet DC Motor

Permanent Magnet (PM) motors are


probably the most commonly used DC
motors, but there are also some other type
of DC motors (types which use coils to
make the permanent magnetic field also).
DC motors operate from a direct current
power source. Movement of the magnetic
field is achieved by switching current
between coils within the motor. This action is called “commutation”. Many DC motors (brush-
type) have built in commutation; it means that as the motor rotates, mechanical brushes
automatically commutate coils on the rotor. You can use the brushless motors in a variety of
applications. A simple, permanent- magnet DC motor is an essential element in a variety of
products, such as toys, servo mechanisms, valve actuators, robots, and automotive electronics.
There are several typical advantages of a PM motor. When compared to AC or wound field DC
motors. PM motors are usually:
1. Physically smaller in overall size; and
2. Lighter for a given power rating.
Furthermore, since the motor’s field is created by the permanent magnet its relationship between
torque and speed is very linear. A PM motor can provide relatively high torque at low speeds and
PM Field provides some inherent self-breaking when power to the motor is shut off. There are
several disadvantages through those being mostly being high current during a stall condition and
during instantaneous reversal. Those can damage some motors or be problematic to control
circuitry. Furthermore, some magnet materials can be damaged when subjected to excessive heat
and some loose field strength if the motor is dissembled.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Inside DC Motor
Let’s start by looking at the overall plan of a simple two-pole DC electric motor. A simple motor
has six parts, as shown in the diagram below:

• Armature or rotor
• Commutator
• Brushes
• Axle
• Field magnet
• DC power supply of some sort

An electric motor is all about magnets and magnetism: A motor uses magnets to create motion. If
you have ever played with magnets you know about the fundamental law of all magnets:
Opposites attract and likes repel. So if you have two bar magnets with their ends marked “north”
and “south”, then the north end of one magnet will attract the south end of the other. On the other
hand, the north end of one magnet will repel the north end of the other (and similarly, south will
repel south). Inside an electric motor, these attracting and repelling forces create rotational motion.

In the above diagram, you can see two magnets in the motor. The armature (or rotor) is an
electromagnet, while the field magnet is a permanent magnet (the field magnet could be an
electromagnet as well, but in most small motors it isn’t in order to save power.

By understanding how a motor works you can learn a lot about magnets, electromagnets and
electricity in general. In this article, you will learn what makes electric motor tick.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

More Parts
The axle holds the armature and
the commutator. The armature is
a set of electromagnets, in this
case three. The armature in this
motor is a set of thin metal plates
stacked together, with thin
copper wire coiled around each
of the three poles of the
armature. The two ends of each wire (one wire for each pole) are soldered onto a terminal, and
then each of the three terminals is wired to one plate of the commutator. The figures below make it
easy to see the armature, terminals and commutator:

The final piece of any DC electric motor is the field magnet. The
field magnet in this motor is formed by the can itself plus two
curved permanent magnets:

One end of each magnet rests against a slot cut into the can, and then the
retaining clip presses against the other ends of both magnets.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Brushless DC Motor
A Brushless DC Motor operates much in the same way as a traditional
brush motor. However, as the name implies there are no brushes (and no
commutator). The mechanical switching function, implemented by the
brush and commutator in a brush-type motor, is replaced by electronic
switching in a brushless motor. In a typical brushless motor the
electromagnetic field, created by permanent magnets, is the rotating member of the motor and is
called a rotor. The rotating magnetic field is generated with a number of electromagnets
commuted with electronics switches (typically transistors of FETs) in a right order at right speed.
In a brushless motor, the trick becomes to know when to switch the electrical energy in the
windings to perpetuate the rotating motion. This is typically accomplished in a brushless-type
motor by some feedback means designed to provide an indication of the position of the magnet
poles on the rotor relative to the windings. A Hall Effect Device (HED) is a commonly used
means for providing this positional feedback. In some applications brushless motors are
commutated without sensors or with the use of an encoder for positional feedback. A brushless
motor is often used when:
i. High reliability,
ii. Long life and
iii. High speeds are required.
The bearings in a brushless motor usually become the only parts to wear out. In applications
where high speeds are required (usually above 30,000 rpm) a brushless motor is considered a
better choice (because as motor speed increases so does the wear of the brushes on traditional
motors). A brushless motor’s commutation control can easily be separated and integrated into
other required electronics, thereby improving the effective power-to-weight and / or power-to-
volume ratio. A brushless motor package (motor and commutation controller) will usually cost
more than a brush-type, yet the cost can often be made up in other advantages.
For example:
It is used in applications where sophisticated control of the motor’s operation is required.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Brushless motors are seen now days in many computer applications, they are usually used
to rotate normal PC fans, hard disks and disk drives.
Electronically commutated, brushless DC motor systems are widely used as drives for
blowers and fans used in electronics, telecommunications and industrial equipment applications.
There is wide variety of different brushless motors for various applications. Some are
designed to rotate at constant speed (those used in disk drives) and the speed of some can be
controlled by varying the voltage applied to them (usually the motors used in fans).
Some brushless DC motors have a built-in tachometer which gives out pulses as the motor
rotates (this applies to both disk drive motors and some computer fans).

In generally, users select brush-type DC motors when low system cost is priority, and brushless
motors to fulfill other requirements (such as maintenance-free operation, high speeds and
explosive environments where sparking could be hazardous). Brush type DC motors are used in
every battery powered appliances. Brushless DC motors are commonly used in applications like
DC powered fans and disk drive rotation motors

Reversing a DC Motor
Sometimes the rotation direction needs to be changed. In normal permanent magnet motors, this
rotation is changed by changing the polarity of operating power (for example by switching from
negative power supply to positive or by interchanging the power terminals going to power
supply). This direction changing is typically implemented using relay or a circuit called “H
Bridge”.

Starting a DC Motor
When a DC motor is connected straight to a battery (with no controller), it draws a large surge
current when connected. The surge is caused because the motor, when it is turning, acts as a
generator. The generated voltage is directly proportional to the speed of the motor. The current
through the motor is controlled by the difference between the battery voltage and the motor’s
generated voltage (otherwise called back EMF). When the motor is first connected up to the

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

battery (with no motor speed controller) there is no back EMF. So the current is controlled only by
the battery voltage, motor resistance (and inductance) and the battery leads. Without any back emf
the motor, before it starts to turn, therefore, draws the large surge current. When a motor speed
controller is used, it varies the voltage fed to the motor. Initially, at zero speed, the controller will
feed no voltage to the motor, so no current flows. As the motor speed controller’s output voltage
increases, the motor will start to turn. At first the voltage fed to the motor is small, so the current
is also small, and as the motor speed controller’s voltage rises, so too does the motor’s back EMF.
The result is that the initial current surge is removed, acceleration is smooth and fully under
control.

DC Motor Speed Control


Motor speed control of DC motor is nothing new. A simplest method to control the rotation speed
of a DC motor is to control its driving voltage. The higher the voltage is the higher speed the
motor tries to reach. In many applications a simple voltage regulation would cause lots of power
loss on control circuit, so a Pulse Width Modulation method (PWM) is used in many DC motor
controlling applications. In the basic Pulse Width Modulation (PWM) method, the operating
power to the motors is turned on and off to modulate the current to the motor. The ratio of “on”
time to “off” time is what determines the speed of the motor. When doing PWM controlling, keep
in mind that a motor is a low pass device. The reason is that a motor is mainly a large inductor. It
is no capable of passing high frequency energy, and hence will not perform well using high
frequencies. Reasonably low frequencies are generally better than higher frequencies, but PWM
stops being effective at too low a frequency. The idea that a lower frequency PWM works better
simply reflects that “on” cycle needs to be pretty wide before the motor will draw any current
(because of motor inductance). A higher PWM frequency will work fine if you hang a large
capacitor across the motor or short the motor out on the “off” cycle (e.g. power / brake PWM).
The reason for this is that short pulses will not allow much current to flow before being cut off.
Then the current that did flow is dissipated as an inductive kick – probably as heat through the fly
back diodes. The capacitor integrates the pulse and provides a longer, but lower, current flow
through the motor after the driver is cut off. There is no inductive kick either, since the current
flow isn’t being cut off. Knowing the low pass roll-off frequency of the motor helps to determine
an optimum frequency for operating PWM. Try testing your motor with a square duty cycle using

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

a variable frequency, and then observe the drop in torque as the frequency is increased. This
technique can help determine the roll off point as far as power efficiency is concerned.

There are also high frequency PWM systems that work. The low versus high frequency for PWM
for DC motors describes two totally different approaches. Both are valid. At low frequencies you
get a mechanical averaging. When the drive is turned off, there is a momentary spike of voltage
that the catch diodes clamp but after that transient dies out the motor is left to free wheel. You will
typically hear the motor buzzing. But this is usually pretty simple to implement with small motors
and low voltages (remember the motor must free wheel when the drive is off). At high frequencies
the inductance of the motor (armature) does the current averaging. This is similar to a switching
power supply (or a chopper drive). The catch diodes are more critical here because they carry full
motor current a substantial amount of time (not so if you are driving the motor locked anti-phase).
High frequency PWM is quite sensitive to the motor properties (inductance). For medium size
motors, usually, 20 kHz or higher frequency works.

There are also applications where you need PWM controlling for two directions. In those cases
you usually combine PWM controlling with H bride. There are many ways to do this in locked
anti-phase system the motor is always driven either forward to backwards, but always connected
to the power. 50% duty cycle has no net current flow and the motor doesn’t move. Because the
motor is always being driven, it always has low impedance across its terminals. A side effect of
this is that the motor, at 50% not only doesn’t turn, but it resists turning – it is in brake mode: low
impedance (e.g. a short) is across the terminals). No capacitors are needed. The one drawback is
intense inductive noise at the switching frequency.

Other Types of DC Motors

Toy Motor
You can see that this is a small motor, about as
big around as a dime. From the outside you can
see the steel can that forms the body of the
motor, an axle, a nylon end cap and two battery

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

leads. If you hook the battery leads of the motor up to a flashlight battery, the axle will spin. If you
reverse the leads, it will spin in the opposite direction. Here are two other views of the same
motor. (Note the two slots in the side of the steel can in the second shot – their purpose will
become more evident in a moment.)

The nylon end cap is held in place by two tabs that are part of the steel can. By bending the tabs
back, you can free the end cap and remove it. Inside the end cap are the motor’s bushes. These
brushes transfer power from the battery to the commutator as the motor spins:

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

PULSE
WIDTH

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

MODULATIO
N (pwm)

PULSE WIDTH MODULATION (PWM)

As discussed earlier, the speed of a permanent magnet DC motor can be altered by varying the
voltage applied to its terminal. One way of varying the applied voltage is by using the pulse-width
modulation (PWM) technique. Using this technique, a fixed frequency voltage signal with varying
pulse-width is applied to the motor terminal. Figure shows an example of a PWM signal where T
is the signal period, td is the pulse-width, and Vm is the signal amplitude. The average voltage can
be calculated from

Vavg = 1/T . 0 ∫T v(t) dt = td/T . Vm = k . Vm (7.1)

Where k is the duty cycle defined as:

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

k = td/T (7.2)

From equation (7.1) it can be seen that the average (DC component) of the voltage signal is
linearly related to the pulse-width of the signal, or the duty cycle of the signal since the period is
fixed. Therefore, varying the duty cycle of the signal can alter the voltage applied to the motor
terminal.

Figure: A PWM Signal

The PWM voltage wave forms for the motor can be obtained using a special power electronic
circuit called a DC chopper. A DC chopper basically uses power switching devices to switch a
constant DC voltage on and off according to a specified switching scheme in order to obtain the
required voltage and current wave forms. There are various types of DC chopper configurations,
which can be found in text books on power electronics.

In this project, we have taken one type of DC chopper configuration called bridge power converter
also known as “H-bridge converter”.

PWM Control

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Pulse-width modulation control works by switching the power supplied to the motor ON and OFF
very rapidly. The DC voltage is converted to a square-wave signal, alternating between fully ON
(nearly 5V) and zero, giving the motor a series of power “kicks”. By adjusting the duty cycle of
the signal (modulating the width of the pulse, hence the `PWM’) i.e., the time fraction it is “ON”,
the average power can be varied, and hence the motor speed.

Controlling the speed of a DC motor requires a variable voltage DC power source. Taking a 12V
motor and applying full power to it will cause the motor to rotate, gradually (relative) building up
speed. Since motors do not respond immediately, it will take a shot amount of time to reach full
speed. Likewise, there will be a time delay between when the power to the motor is removed and
when the motor armature stops revolving. Switching the power ON and OFF quickly enough will
enable the motor to run at some speed part way between zero and full speed. Pulse Width
Modulation (PWM) does exactly this, switching 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.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Principles:

To control the speed of a DC motor we need a variable voltage DC power source. However, 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.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

DRIVE &
CONTROL
CIRCUITR
Y
By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

DRIVE AND CONTROL CIRCUITRY

DC Motor-Driver H-Bridge Circuit:


It would be nice if a motor could be attached directly to a chip that controlled the movement. But,
most chips can’t pass enough current on voltage to spin a motor. Also, motors tend to be
electrically noisy (spikes) and can slam power back into the control lines when the motor direction
or speed is changed.

Specialized circuits (motor drivers) have been developed to supply motors with power and to
isolate the other ICs from electrical problems. These circuits can be designed such that they can be
completely separate boards, reusable from project to project.

A very popular circuit for driving DC motors (ordinary or gear head) is called an “H-bridge”. It is
called that because it looks like the capital letter `H’ on classic schematics. The great ability of an
H-bridge circuit is that the motor can be drive forward or backward at any speed, optionally using
a completely independent power source.

An H-bridge design can be really simple for prototyping or really extravagant for added protection
and isolation. An H-bridge can be implemented with various kinds of components (common
bipolar transistors, FET transistors, MOSFET transistors, power MOSFETs or even chips).

Basic Theory
Let’s start with the name, H-bridge. Sometimes
called a “full bridge” the H-bridge is so named
because it has four switching elements at the
“corners” of the H and the motor forms the cross
bar. The basic bridge is shown in the figure.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

The key fact to note is that there are, in theory, four switching elements within the bridge. These
four elements are often called, high side left, high side right, low side right, and low wide left
(when traversing in clock wise order).

The switches are turned on in pairs, either high left and lower right, or lower left and high right,
but never both switches on the same “side” of the bridge. If both switches on one side of a bride
are turned on it creates a short circuit between the battery plus and battery minus terminals. This
phenomenon is called “Shoot Through” in the Switch Mode Power Supply (SMPS) literature. If
the bride is sufficiently powerful it will absorb that load and your batteries will simply drain
quickly. Usually however, the switches in question melt.

To power the motor, you turn on two switches that are diagonally opposed. In the picture to the
right, imaging that the high side left and low side right switches are turned on. The current flow is
shown in green.

The current flows and the motor begins to turn in a “positive” direction. If you turn on the high
side right and low side left switches the current flows in the other direction through the motor and
the motor turns in the opposite direction.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

If each switch can be controlled independently then one can do some interesting things with the
bridge, called a “four quadrant device” (4QD). If you built it out of a single DPDT relay, you can
really only control forward or reverse. You can build a small truth table that tells you for each of
the switch’s states, what the bridge will do. As each switch has one of two states, and there are
four switches, there are 16 possible states. However, since any state that turns both switches on
one side on is “bad” there are in fact only four useful states (the four quadrants) where the
transistors are turned on.

High Side Lower Side


Quadrant Description
Left Right Left Right
On Off Off On Motor goes clockwise
Off On On Off Motor goes counter-clockwise
Motor “brakes” and
On On Off Off
decelerates
Motor “brakes” and
Off Off On On
decelerates

The last two rows described a maneuver where you “short circuit” the motor which causes the
motors generator effect to work against itself. The turning motor generates a voltage which tries to
force the motor to turn the opposite direction. This causes the motor to rapidly stop spinning and is
called “braking” on a lot of H-bridge designs.

Of course, there is also that state where all the transistors are turned off. In this case, the motor
coasts if it was spinning and does nothing if it was doing nothing.

Simplified model:
Consider an H-Bridge as an array of four switches, as shown below:

Figure 4.1: Simplified H-Bridge

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

On can alter the states of these four switches in order to manipulate the voltage across the motor,
and through that the direction of current flow and rotation of the motor. In Fig. 4.1, we can see
that all the switches are open and the motor terminals are disconnected from the circuit. This state
will allow the motor to spin freely.

Figure 2.2 – S1 and S4 closed

If we close two of the switches, S1 and S4 as shown in Fig. 2.2, the motor terminals are connected
to the voltage supply, and a potential difference across the motor is created, which will cause the
motor to begin rotating in one direction.

Figure 2.3 – S2 and S3 Open

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Now, if we open S1 and S4 and close S2 and S3, as in Figure 2.3, the voltage across the motor is
switched around, and this will cause the motor to rotate in the opposite direction.

Figure 2.4 – Active Braking

If we leave Switch S1 and S2 open while S3 and S4 are closed, the motor terminals will be short
circuited. This will cause the motor to brake, and rapidly slow down.

Figure 2.5 – Short Circuiting

If we close S1 and S3 at the same time, it will cause a short circuit from V+ to ground. This is
known as “Shoot Through”. The motor will not spin, and excessive current will flow through the
switches, wires, and power supply. In MOSFET H-Bridge, this can cause MOSFET and batteries
to overheat and free trapped smoke, or even explode!! This is dangerous and you should avoid
short circuiting your H-bridge like this at all costs.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

PC
Interfacing

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Interfacing to the PC using Parallel Printer Port

The original IBM-PC’s Parallel Printer Port had a total of 12 digital outputs and 5 digital inputs
accessed via 3 consecutive 8-bit ports in the processor’s I/O space.

• 8 output pins accessed via the DATA Port


• 5 input pins (one inverted) accessed via the STATUS Port
• The remaining 8 pins are grounded.

The Pins having a bar over them means that the signal is inverted by the parallel port’s hardware.
If a 1 were to appear on the 11 pin [S7], the PC would see a 0. The Status pins are mainly used by
the PC to know the status of the printer like if there is paper in the printer, end of paper etc.
Parallel Port Female Connector

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

The Data Port


Sending commands involves only the data pins [D0 to D7]. Though it is possible to use the some
other pins as input, we’ll stick to the basics.

NOTE : Data pins are from pin 2 to pin 9 and not from pin 1.

If you have good eyesight, check your parallel port connectors. Both the connectors [male /
female], have numbers etched next to their pints, so people like us don’t screw up our ports,
connecting them the wrong way. The word “Parallel” denotes sending an entire set of 8 bits at
once to the PC [Thus term ‘Parallel Port’]. However, we can use the individual pins of the port;
sending either a 1 to a 0 to a peripheral like a motor or LED.

Sending Commands to the Port:

- Open up your C compiler.


- Type the following program:

#include<stdio.h>
#include<dos.h>

void main ()
{
outportb(0x378,0xFF); //da line
}

//You just set all your data pins to 1.

If you take an LED and put one terminal at pin2 and the other to pin 18, it would glow [Use a 2K
resistor in series with the LED, otherwise u’ll end up ruining your Led, or source too much current
from the port pin].

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

If you wish to switch it OFF, type the code below instead:


outportb(0x378,0x00);

EXPLANATION:

0x378 is the parallel port address. Usually this is the default address. Sometimes it may be 0x278.
0x000 is the command appearing at the output pins. The format is in Hexadecimal.

For make pin no.2 high, that’s the first pin you type.

0x01: this would mean 0000 0001 for the data port.
0x04 : 0000 0100
0x55 : 0101 0101
0x0A : 0000 1010
And so on…

Material to control a Motor via a parallel port:

• 1 parallel port Male connector


• 1 DC Motor
• 1 Motor Driver [H-Bridge]
• 12 V Adapter

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Caution: Before trying out anything, please remember that your parallel port is not meant or
designed to handle more than 5 Volts. If possible, trying accessing your parallel port using
Windows-98, Windows XP does not allow access to the parallel port. You’ll need special drivers
for that.

Steps to Control a Motor:


Connect your parallel port pins to your Female connector [on your PC], through the male
connector as follows:

Short all Ground pins i.e. from 18 to 25


Command for the Motor

outportb(0x378,0x03): ----------- MOVE MOTOR (CCW)


outportb(0x378,0x0c): ----------- MOVE MOTOR (CW)

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

CIRCUIT
DESIGNIN
G
By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

CIRCUIT DESIGNING

In this DC motor controller, we have used the standard H-Bridge circuit as the DC motor driver
and a software program written in C++ as the pulse-width modulated (PWM) wave generator. The
program generates PWM signal to vary the speed of the motor as well as change the direction of
its rotation depending upon the user command.

In fact, a controller is the combination of drive and switching circuits. The driver is the actual
circuit that drives the Dc motor and the switching circuit decides how the DC motor should be
driven. So it is mainly the switching circuit that controls the motor.

Now, there are two parameters of the DC motor that you can control Speed and direction. You can
vary the speed as well as change the direction (either clockwise or anticlockwise) of a DC motor.
Changing the direction of the Dc motor is very simple as you just need to reverse the supply given
to the DC motor.

For varying the speed of the motor, you have to vary the applied Dc voltage. One well-known
method to vary the voltage is to use resistance (rheostat) in series with Dc supply. Another method
is to apply a PWM signal to the DC motor. As the width of the pulse varies, the average voltage
applied to the motor varies and therefore, the speed of motor also varies.

H-Bridge Driver:

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

H-Bridge is standard, well known circuit and widely used as DC motor driver. Its schematic is as
shown below. It’s bridge connection of four transistors. An H-bridge is used to control a DC
motor. It allows the motor to start and stop and most importantly to reverse direction. In order to
reverse the direction of a DC motor, the current through the DC motor must be reversed. A DC
motor can be run in either direction by simply changing the polarity applied to its two terminals.
In order to actuate this change a switching circuit is required. To control the DC motor in all four
quadrants a bi-directional current flow is required, this was achieved by using on H-bridge. To
control the speed of a d.c. motor we need a variable voltage d.c. power source. However if you
take a 12 V motor and switch on the power to it, the motor will start to speed up; motor 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 PWM 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.

CIRCUIT

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Connections:
Bases of all four transistors (all are of 2N222 type) are connected to data pins of the PC’s 25 pin
D-type female / male connector through 1K resistors. Transistors T1 to T4 are connected with pin
no.2 (Data line 0) to 4 (Data line 3) respectively. The DC motor terminals are connected as shown
5V DC supply is given to circuit. Circuit ground is shorted with pin no.18 to 25 of D-type
connector which are ground pins for all the data pins (D0-D7).

Operation:
Now, if we apply logic (3.49V) to pins 5 and 4 and low logic (0.09V) to pins 2 and 3 through the
program, transistors T1 and T4 will conduct and the current will flow from the +12V supply
terminal to transistor T1, positive terminal of the motor, negative terminal of the motor, transistor
T4 and then to ground. So motor will rotate in one.

Similarly, if we give high logic to pins 2 and 3, transistors T3 and T2 will conduct and the current
will flow from the +12V supply terminal to transistor T3, negative terminal of the motor, positive
terminal of the motor, transistor T2 and then to ground. So motor will rotate in another direction.
For this we have to apply HEX data word 03 (0000 011) on the LPT port.

Thus simply by switching the logic from high to low and low to high in between these four pins
(2, 3, 4 and 5) you can change the direction of motor.

Now, rather than directly giving high logic to pins if we apply PWM wave to it then during ON
period of wave both transistors are closed switch (conducts) and during OFF period they are open
switch (do not conduct) so every time average voltage is fed to motor. As you go on increase pulse
width (increasing ON period and decreasing OFF period) of PWM wave the avg. voltage given to
motor is increased and so the speed also increases. Same way if you decrease pulse width
(increase OFF period and decrease ON period) of PWM waves the avg. voltage decreases and so
the speed also decreases.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Here in this project, generating PWM wave on these pins (2, 3, 4 and 5) as well as switching the
transistors to change the direction of motor is done by software program which is written in C++
programming language.

CONSRUCTION
Construction of the hardware circuit is as shown in the circuit diagram. Circuit can be wired even
on a breadboard as it uses only eight components (four resistors and four transistors). Insert DB25
(25–pin, D-type male connector) into the PC’s LPT-port female connector. Apply 12V DC supply
to the circuit and connect the 12V DC motor with its terminals as `shown in Fig. 1. Now run the
program on a computer. You will see the control panel screen on your monitor. Switch on the 12V
supply and move the mouse pointer to any of the buttons.

To rotate the motor clockwise, press and hold `clockwise’ button with left mouse button on the
control panel. Similarly, for anticlockwise rotation, press and hold `anticlockwise’ button. The
motor will rotate in the desired direction along with the beep sound until the button is pressed.
When you release the button, the beep as well as the motor will stop. If the motor rotates anti
clockwise when you press `clockwise’ button, just reverse the terminals of the motor.

To increase / decrease the speed of the motor, click `speed increase’ / `speed decrease’ button.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Software

SOFTWARE

The Programming is done with the following objective:


1. Generation of the PWM output on port pins (2, 3, 4, 5), as well as
2. Switching of the transistors to change the direction of motor.

The program is written in C++ language and compiled using Turbo C++ Version 3. The complete
software (DCSPEED.CPP) is given at the end of the article along with necessary explanantion.

NOTE: We require the ‘EGAVGA.BGI’ graphic file to run the program.

The Software is mainly divided into 3 parts:-


1. Mouse interfacing

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

2. Graphics
3. PWM generation

Mouse interfacing
Mouse interfacing meanings, the user can do his / her all tasks by mouse click. To understand how
mouse is interfaced in this program you have to go through whole theory of hardware interfacing
using C++. We’ll am not discussing about whole theory here but giving you the reference. We
have referred the chapter “Mouse Interfacing” in book named “Let us C” by Mr. Kanitkar. In this
program there are four functions that handless mouse event:

1. intimouse()
2. resmptr(int p, int q, int r, int s)
3. showmptr()
4. getmpos(int *t, int *u, int *v)

initmouse() function loads mouse driver in to the program. In this function we are passing O
value through input union REGS to int86() function. This function will return some non zero value
through output union REGS to main program. If this function returns value zero (0), it means
mouse driver is not loaded. So program displays message “mouse driver is not loaded” and also it
shuts the program screen off using exit () function.

Resmptr(int p, int q, int r, int s) function restrict mouse movement within the boundary
specified by the four variables passed to it. We pass all these boundary limits through input union
REGS to int86() function so int86() function will restrict the mouse movement out of this
boundary.

Showmptr() function displays mouse pointer on program screen. For this just we have to pass the
value 1 through input union REGS to int86 () function. And int86 function will show mouse
pointer on screen.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Getmpos (int *t, int *u, int *v) performs two tasks. It determines whether mouse button is
pressed or not and it captures current mouse pointer position from screen. We have to pass the
value 3 through input union REGS to int86() function. This function will returns the x and y co-
ordinates of mouse pointer and also returns value 1 if mouse button (left) is pressed or 0 if button
is not pressed.

Graphics
This part generates complete view of control panel. It draws buttons like clockwise, anticlockwise,
speed increase / decrease, displays instructions, draws borderline, writes text like “Speed”, “Speed
factor”, displays speed factor etc. That means it prepares whole appearance of program screen.

PWM Generation

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Generating PWM on parallel (LPT) port data pins (D0 – D7) using C++ is very simple. For ON
period you have to apply high logic (1 means 3.49V) on that data pin and low logic (0 means
0.09V) for OFF period of pulse. The base frequency over which PWM is generated is 200Hz. So

the time period is 50 milli second (ms). First when speed factor (d) is zero, program generates
square wave of 50% duty cycle (25ms ON period and 25ms OFF period) on two parallel port pins
(either on pin no. 2 & 3 or on pin n.4 & 5). This speed factor is added to the ON time period (25 +
d) and subtracted from OFF time period (25 – d). So as you increase this factor the ON time
period will increase and with the same factor OFF time period will decrease (suppose d = 5 then
ON time is 30 and OFF time is 20) so the base frequency 20Hz will not change. Same manner
when you decrease speed factor ON time will decrease and OFF time will increase again
frequency remains same. This you can easily understood with these wave forms.
Output waveforms generated by software on D0-D3 pins of LPT port

Note: You can increase the speed factor till you reach to min limit of OFF time period (5 ms).
After that there won’t be any further increment in speed factor and program will display a message
“Maximum Speed”. In same manner you can’t further decrease speed factor when you reach min
limit of ON period (5 ms). When you reach this limit program will display message “Minimum
Speed”.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

How program works ?


Until and unless you press any key you can see the program screen displaying control panel for
DC-Motor speed and directions control. Program continuously checks for mouse clicks. Whenever
there is a mouse click instantly getmpos() function captures x and y co-ordinates of mouse point
and pass it to the main program. Main program decides on which position click event has
happened and if it happened on any button (clockwise, anticlockwise etc.) then performs the
desired task. For example, you click on speed increase button, program gets the co-ordinate and
directly switches to that ‘if’ loop, increase the speed factor and also displays it on screen.
How to rotate DC Motor:
To rotate motor clockwise / anticlockwise press and hold clockwise / anticlockwise button with
left mouse button. Motor will rotate in desired direction till the button is pressed and you will also
hear a sound. Motor will stop rotating when you release button. If you press clockwise button and
motor rotates anticlockwise then just reverse the terminals of motor.

To increase / decrease the speed of motor just press speed increase / decrease button with left
mouse button once. Sweet sound is generated and speed factor will be incremented / decremented
and displayed on screen. Pressing these buttons more than one time will increase / decrease the
speed factor by same amount.

Control Panel:

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

This is seen on the PC when the Program is executed.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Flow
Chart

Start

Define port
and activate
event handler

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Initialize the ports

Set
Count = 0
Time = 0

If
clockwise Y
Activate T1 and T4 and
button is
Motor rotates clockwise
pressed

If anti Activate T2 and T3 and


clockwise Motor rotates
button is anticlockwise
pressed By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

Pulse width is increased


If speed
and so the speed of
factor is
motor increases
increased

If speed Pulse width is decreased


factor is and so the speed of
pressed motor decreases

Count = Count + 1

If If Speed
acknowledged
By: Karan Kumar, Mansi Aggarwal,
Compute
Compute
Add <load
Pranav
theHaldar
the speed
number(COER)
andof
for rotation Display Desired
rotations
and click
speed
via IR
in sensor
Increase speed factor
and Speed
rotations
load perXminute
display
button speed
P.C. Interfaced Speed Control of D.C. Motor

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Program

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<time.h>
#include<process.h>
#include<stdarg.h>
#include<iostream.h>

union REGS in, out;


int e=0,d=0; //initialize speed Factor

int gprint(int *xloc, int *yloc, char *fmt);

void main()
{
clrscr();

int k=0,z=0,t;
int driver, mode, x,y,but; //initialization of all variables
int xp,yp;
driver=DETECT; //fn to load Mouse Drivers
int initmouse();
int resmptr(int p,int q,int r,int s);
int showmptr();
int getmpos(int *t, int *u, int *v);
int text(int e, int f);
initgraph(&driver,&mode,"c:\\tc\\bgi");
setcolor(13);
outtextxy(55,55,"DC_MOTOR_SPEED_CONTROL_C++ : Designed & Developed by:-");

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

setcolor(4);
outtextxy(250,100,"Karan_Kumar");
outtextxy(250,120,"Mansi_Aggarwal");
outtextxy(250,140,"Pranav_Haldar");
setcolor(13);
outtextxy(220,200,"Under the able Gauidance of:-");
setcolor(10);
outtextxy(240,230,"Mr. Asish_Pratap_Singh");
delay(1500);
closegraph();
initgraph(&driver,&mode,"c:\\tc\\bgi");
outport(0x0378,0x00);
if(initmouse()==0)
{
closegraph();
restorecrtmode();
cout<<"mouse driver not loaded"<<endl;
exit(1);
}
gotoxy(14,11);
cout<<d;
showmptr();
resmptr(0,0,635,460);
setcolor(LIGHTRED);
rectangle(30,30,635,460);
rectangle(70,155,160,180);
setfillstyle(SOLID_FILL, YELLOW);
rectangle(180,130,320,170); // clockwise button
floodfill(202,132,LIGHTRED);
rectangle(180,240,320,280); //anti-clockwise button
floodfill(202,132,LIGHTRED);

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

rectangle(180,240,320,280);
floodfill(202,242,LIGHTRED);
rectangle(350,130,490,170); //speed inc.
floodfill(352,132,LIGHTRED);
rectangle(350,240,490,280);
floodfill(352,242,LIGHTRED);
rectangle(180,380,320,420);
floodfill(202,400,LIGHTRED);
floodfill(202,132,LIGHTRED);
rectangle(520,130,600,170);
line(250,220,420,220);
line(335,220,335,210);
line(250,220,250,240);
line(420,220,420,240);
text(8,13);
outtextxy(255,60,"-:Control Panel:-");
text(6,4);
outtextxy(85,300,"Intruction;-");
outtextxy(210,140,"Clockwise");
outtextxy(360,140,"Anticlockwise");
outtextxy(210,250,"Increase");
outtextxy(380,250,"Decrease");
outtextxy(182,400,"speed computation");
setcolor(10);
outtextxy(310,185,"Speed");
outtextxy(60,130,"Speed Factor");
text(5,10);
outtextxy(100,320,"#Press & Hold 'Clockwise'button to rotate DC Motor clockwise.");
outtextxy(100,340,"#Press & Hold 'Anticlockwise'button to rotate DC Motor anticlockwise.");
outtextxy(100,360,"#Press 'increase'/'decrease'button to change the speed");
setcolor(19);

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

outtextxy(540,145,"LOAD"); //load
xp=355;
yp=400;
setcolor(LIGHTRED);
rectangle(350,380,550,420);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(352,412,LIGHTRED);
setcolor(YELLOW);
outtextxy(225,450,"Press any key to exit program");
//getch();
while(!kbhit()) //loop untill any key is pressed
{
getmpos(&but,&x,&y);
if(x>=200 && x<=300 && y>=300&& y<=170 && (but&1)==1)
{
text(6,13);
outtextxy(210,140,"Clockwise");
do
{
getmpos(&but,&x,&y); //rotate the motor clockwise
outport(0x0378,0x0c); //till button is pressed
sound(500);
delay(25+d); //genrate PWM with
nosound(); //200Hz (50ms)as
outport(0x0378,0x00); //centre frequency
delay(25-d);
}while((but & 1)==1);
text(6,4);
outtextxy(210,140,"Clockwise");
} //first if ends
else

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

if(x>=350 && x<=490 && y>=130 && y<=170 && (but & 1)==1)
{
text(6,13);
outtextxy(360,140,"Anticlockwise");
do
{
getmpos(&but,&x,&y); //rotate the motor anticlockwise
outport(0x0378,0x03); //till button is pressed
sound(750); //genrate PWM with
delay(25+d); //200Hz (50ms) as
outport(0x0378,0x00); //centre frequency
delay(25-d);
nosound();
}while((but & 1)==1);

text(6,4);
outtextxy(360,140,"Anticlockwise");
} //second if ends

else
if(x>=180 && x<=320 && y>=240 && y<=280 && (but&1)==1)
{
gotoxy(10,11);
cout<<" ";
text(6,2);
outtextxy(210,250,"Increase");
sound(1000);
delay(200);
nosound();
if(d<20)
{

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

k=k+6;
d++; //increase speed factor till
gotoxy(14,11); //d<20 if d>20 stop increasing
cout<<d;
e=d;
}
else
{
gotoxy(10,11); //and display message
cout<<"Max Speed";
}

text(6,4);
outtextxy(210,250,"Increase");
} //third if ends

else
if(x>=350 && x<=490 && y>=240 && y<=280 && (but&1)==1)
{
gotoxy(10,11);
cout<<" ";
text(6,2);
outtextxy(380,250,"Decrease");
sound(1000);
delay(200);
nosound();
if(d>(-20))
{
k=k-6;
d--; //decrease speed factor till
gotoxy(14,11);

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

cout<<d; //d>-20 if d<-20 stop decreasing


e=d;
}
else
{
gotoxy(10,11);
cout<<"Minimum Speed"; //and display message
}
text(6,4);
outtextxy(380,250,"Decrease");
} //last if ends

/*if(x>=500 && x<=600 && y>=130 && y<=170 && (but&1)==1) //my load box button
{
text(12,5);
outtextxy(540,145,"LOAD"); //load
z=1;
}

if(x>=180 && x<=320 && y>=380 && y<=420 && (but&1)==1)


{
if(d<-20)
{
gotoxy(45,25);
cout<<"Increase Speed Factor";
}
else
{
text(6,13);
outtextxy(182,400,"speed computation");
long int t,ti,d;

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

int read,count=1050,x1,x2;
float p1=290.0,p2=300.0;
t=time(NULL);
ti=t;
d=(t+5);
while(ti<d)
{
ti=time(NULL);
read=inportb(0x379);
if(read==10)
{
count++;
}
x1=p1;
x2=p2;
setcolor(3);
// line(x1,445,x2,445);
p1=p1+.06;
p2=p2+.06;
setcolor(12);
sound(1000);
for(int v=1;v<5;v++)
{
gotoxy(30,7);
cout<<"ANALYZING DATA";
for(int u=1;u<=5;u++)
{
printf(".");
delay(200);
}
gotoxy(30,7);

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

cout<<" ";
}

//outtextxy(270,428,"Analyzing Please wait...");


//printf("hi");
} //timer while ends

setcolor(LIGHTRED);
text(6,4);
count=count+k;
nosound();
if(z!=1)
{
gotoxy(45,25);
cout<<"speed of motor:"<<count<<"rpm";
//gprintf(&xp,&xyp,"speed of motor:%d rpm",count);
}
if(z==1)
{
count=count-9;//load//
gotoxy(45,25);
cout<<"speed of motor:"<<count<<"rpm";
//gprintf(&xp,&yp,"speed of motor: %d rpm",count);
sound(500);
// delay(5000);
count=count+9; //load//
for(int v=1;v<=5;v++)
{
gotoxy(34,7);
cout<<"ANALYZING DATA";
for(int u=1;u<=5;u++)

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

{
printf(".");
delay(200);
}
gotoxy(30,7);
cout<<" ";
}
nosound();
gotoxy(45,25);
cout<<"speed of motor:"<<count<<"rpm";
//gprintf(&xp,&yp,"speed of motor: 1150 rpm");
gotoxy(10,11);
cout<<" ";
gotoxy(14,11);
e=e+2;
if(e>=20)
{
gotoxy(10,11);
cout<<"Max Speed";
e=20;
}
else
{
cout<<e;
d=e;
z=0;
setcolor(19);
outtextxy(540,145,"LOAD"); //load
} //end else
} //if ends
} */ //while loop ends

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

closegraph();
initgraph(&driver,&mode,"C://tc//bgi"); ///start lines:initiasize graphics mode
setcolor(13);
outtextxy(140,220,"We Thank Lect. J.K. Vaishishth for his valuable guidance");
//outtextxy(240,230,"Prof. BAL GOPAL");
delay(5000);
closegraph(); /////////////end lines
} // main ends

/*int gprintf(int*x,int*y,char*fmt)
{
va_list ptr
char str[140];
va_str(ptr,fmt);
vsprintf(str,fmt,ptr);
outtextxy(*x,*y,str);
*y=*y+textheight("h")+2;
va_end(ptr);
} */

getmpos(int *but, int *x, int *y)


{
in.x.ax=3;
int86(0x33,&in,&out);
*but=out.x.bx;
*y=out.x.dx;
}

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

//function to check mouse drivers


initmouse()
{
in.x.ax=3;
int86(0x33,&in,&out);
return(out.x.ax);
}

showmptr()
{
in.x.ax=1;
int86(0x33,&in,&out);
}

resmptr(int a, int b,int c, int d)


{
in.x.ax=7;
in.x.cx=a;
in.x.dx=c;
int86(0x33,&in,&out);
in.x.cx=b;
in.x.dx=d;
int86(0x33,&in,&out);
}

text(int e, int f)
{
setcolor(f);
settextstyle(SMALL_FONT,HORIZ_DIR,e);
}

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Feedback
By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)
P.C. Interfaced Speed Control of D.C. Motor

FEEDBACK

Speed Feedback:
An IR sensor is used as the key element in detecting the speed. The number of rotations that falls
within a period of high state of IR receiver output is fed to a PC via parallel port and is converted
to the corresponding rpm value by the program running on the PC.

DC motors will almost certainly give you the best combination of power to weight ratio and top
speed. A DC motor is intended to work for a direct current supply. Voltage is applied to the motor
terminals and the motor begins to rotate. As the armature picks up speed, a voltage is induced in
the winding that tries to oppose the current flowing in them. Quite quickly, a speed is reached
where a balance is established and the motor speed stabilizes. The speed at which this occurs is a
function of the applied voltage and the motor characteristics. The amount of turning force, torque
that the motor can produce is a function of the current through the windings. As a load is applied
to the motor, the speed drops and the current increases. A load just sufficient to stop the motor is
the stall torque and will correspond to some particular (and fairly high) current through the
windings. We didn’t want to do that to our motor, the energy can only appear as heat.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

While these motors are expecting a direct current to drive them. It is much more efficient to use a
supply that is switched on and off repeatedly. The width of the on pulses is varied so that the
motor sees the average amount of energy flowing. Pulse with modulation (PWM) of the motors is
not too complicated to achieve. The section of processors has more on this. You will need to select
a pulse repetition rate that is quite high. A few hundred Hz is just not going to do it. However, a
rate that is too high will be less efficient because of the inductance of the motor windings. Should
you pick a frequency in the audible range, you will have to live with the motors whining at you
(and every else) all the time. Somewhere in the range 20 kHz – 40 kHz will probably be fine. It
should be ensured that the rate does not cause trouble by interfering or beating with other events.
For example, we would expect trouble if the motor PWM repletion frequency was 20 kHz and you
had IR sensors modulated at 40 kHz. Noise from the motors might find its way to the IR detectors.
Change the frequency to, say, 23 kHz where there are no simple common factors.

There will have to be some way to measure the speed of your motors. This may be the same as
measuring the speed of the wheels but need not be. The wheel speed is really needed for working
out position – absolute measures of speed are not really important except to tell if you can stop
before some point. Some motors are available with incremental encoders or other feedback
devices built in. These tend to be more expensive. While running, our motor speed will be
controlled in a software feedback control loop. Regular measurements of wheel speed are taken
and used to calculate a new value for the PWM pulse width.

Rotary Encoder Sensing:


Rotary encoders are typically used to provide direct physical feedback of motor position, and / or
speed. A rotary encoder consists of a rotary element attached to the motor that has a physical
feature, measured by a stationary component. The measurements can yield motor speed and
sometimes they can provide a motor position. Rotary encoders are built using many different
technologies. The most common type is an IR rotary encoder. The optical or an IR encoder is used
in the computer mouse that has a ball. It is built with an encoder disc that is attached to the motor.
The encoder disc has many radical slots cut into the disc at a specific interval. An IR transmitter
and a IR detector are used to count the slots as they go by. By timing the rate that the slots go by,
the speed of rotation can be determined.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

In our Project for speed measurement on the shaft of the motor we have fixed one sheet metal strip
with equal length from the center. When it passes through the sensor IR ray is obstructed and a 5V
signal is sent to the Pin number 12 of the LPT (Parallel port). This sensing is done for a second
and accordingly the program computes and displays the speed in RPM (Revolutions Per Minute).
Since two rotations of the strip equals one revolution of the motor, so we have according done the
appropriate programming to give the speed in RPM.

Connections:
For the connections part, we have taken the computers Mouse and removed its cover. It is
connected to the PC via serial port. Also from the IR receiver we have connected two wires one to
the pin number 12 of the LPT port for feedback and another to the ground of the LPT port to
provide proper ground.

Speed Control:
If a load is attached to the shaft of the motor the speed obviously decreases we measure this speed.
In the software a loop is taken if the speed is reduced from the desired speed then the speed factor
is increased and accordingly the motor speed is increased. So again the motor reaches the desired
speed in load conditions. This is speed controlling of the DC motor that is taking place.

SENSORS
Sensors are a critical component in a motor control system. They are used to sense the current,
position, speed and direction of the rotating motor. Recent advancements in sensor technology
have improved the accuracy and reliability of sensors, while reducing the cost. Many sensors are
now available that integrate the sensor and signal-conditioning circuitry into a single package.

In most motor control systems, several sensors are used to provide feedback information on the
motor. These sensors are used in the control loop and to improve the reliability by detecting fault
conditions that may damage the motor. We have made a DC motor control system to show the
sensor feedback provided for a typical motor control.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

Sensors are of various types and we have used IR sensors.

IR (Infrared)
Infrared proximity sensors work by sending out a beam of IR light, and then computing the
distance to any nearby objects from characteristics of the returned (reflected) signal. There are a
number of ways to do this, each with its own advantages and disadvantages:

Reflected IR strength
We could build a simple IR proximity sensor out of essentially just an IR LED and IR photodiode.
This simple sensor, though, would be prey to background light (i.e. your IR “receiver” would be
responding to naturally present IR as well as reflected IR).

Modulated IR signal
A better solution would be to modulate your transmitted IR (i.e. to send out a rapidly-varying IR
signal), and then have the receive circuitry only respond to the level of the received, matching,
modulated IR signal (i.e. to ignore the DC component of the received signal, and only trigger off
the AC component). This method, though, is still at the mercy of the characteristics (in particular,
IR reflectance) of the obstacle we’re trying to sense.

Triangulation
The best way to use IR to sense an obstacle is to sense the angle at which the reflected IR is
returned to your sensor. By use of a bit of trigonometry, you can then compute distance, knowing
the location of your transmit and receive elements. Needless to say, this isn’t a simple sensor to
build ourselves.

Acoustic proximity sensors


One oft-used method (at least on larger, pricier bots) of avoiding hazards is via sonar ranging.
Here, acoustic signals (“pings”) are sent out, with the time of echo return being a measure of
distance to an obstacle. This does, unfortunately, require fairly accurate timing circuitry – so
acoustic sensors really require a processor of some sort to drive them. Also note that acoustic

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

sensing essentially requires the use of commercial sensors, there’s no real way to “homebrew”
something from scratch.

The most common acoustic proximity sensor is the kind used in polaroid cameras. For example
the “Polaroid Sonar Ranging Primer.”

There’s now also a new one on the block – the Devantech SRF04 Ultra Sonic Ranger. It costs
about twice what the Sharp IR sensors cost, but has a much wider range of sensing; it costs far less
than the Polaroid acoustic rangers, is easier to interface and draws less power.

Capacitive sensors
We can also sense its distance to objects by detecting changes in capacitance around it. When
power is applied to the sensor, an electrostatic field is generated and reacts to changes in
capacitance cause by the presence of a target. The main disadvantage to this sensor (often called a
capacitor) is that its usefulness is dependent on properties of the obstacles it is sensing (namely,
their dielectric constant). The higher the dielectric constant (say, water), the more sensitive a
capacitive sensor is to that target. The sensing distance depends on the dielectric constant of the
target and the surface areas of the probe and the target.

Inductive proximity sensors


Another method for sensing distance to objects is through the use of induced magnetic fields. The
primary problem with this method is that it is largely confined to sensing metallic objects.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

CONCLUSIO
N

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

CONCLUSION

We could conclude that :-

• The motor can be started / stopped and made to retain a set speed irrespective of the load.

• The motor can be run as low as 100 rpm and as high as 1200 rpm.

• Program interface is user-friendly enabling flexible and simple operation.

• H-bride controller drives the motor to reach the speed smoothly and within an acceptable
period of time.

• Since we control the average armature voltage, speed could be controlled only below the
rated speed.

• Though PC was used in controlling due to ease of programming and simplicity, in


particular as a demonstrative prototype, the program is used to generate the signal.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

To control higher rating DC motors like those used in industries or tread mill machines, use IGBT,
Power MOSFETs or SCRs instead of transistors. Switching voltages of these devices are much
higher than for the standard transistor. So you have to design an amplifying circuit using an
operational amplifier. Also, to protect the LPT parallel port, use opto-isolators (MCT2E) to isolate
the higher voltage (DC driver) and lower voltage (PC’s LPT port) sides.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

APPLICATION
&
SCOPE

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

APPLICATION & SCOPE

This project is hardware cum software application, which controls the speed and direction of a DC
motor through mouse click. Thus this project helps in many real life applications where variable
speeds may be required like, drives for blowers and DC powered fans used in electronics,
telecommunications and industrial equipment applications. The most recent application of this
project was in mars rover (spirit, opportunity) in this application the movement of vehicle and also
the camera provided was controlled by same type of speed control concept in wireless mode. We
can also design a GPS (Global Positioning System) for unmanned spaced vehicle and Robots by
utilizing the similar principle.

We can also apply this DC motor that we have used is 12V DC cannon printer’s motor with
maximum RPM of 1200. Also any other small DC motor of tape-recorder with desired
specifications. To control higher HP DC motors (like used in industries or used in treadmill
machine) then instead of using transistor you have to use IGBT, power MOSFET or SCR. The
switching voltages of such devices are to much higher then the standard transistor. So for this we
have to design an amplifying circuit using OP – AMP. Also to protect LPT (parallel) port we have
to use opto-isolators (MCT2E) that can isolate the higher voltage (DC driver) side and lower
voltage (computer LPT port) side.

Other applications of this project can be in Internet Rovers, Personal Mobility, Submersible
ROVs, Unmanned Aerial Vehicles (UAV), Machine Control, Animatronics Props, Force-
Feedback Systems.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

References

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)


P.C. Interfaced Speed Control of D.C. Motor

[1] Allen J. Wood and Bruce F.


Wollenberg, “Power Generation,
Operation and Control.” John
Wiley and sons; New York 1984.

By: Karan Kumar, Mansi Aggarwal, Pranav Haldar (COER)

You might also like