You are on page 1of 123

THE UNIVERSITY OF THE WEST INDIES

ST. AUGUSTINE, TRINIDAD & TOBAGO, WEST INDIES


FACULTY OF ENGINEERING
Department of Electrical & Computer Engineering
BSc. in Electrical & Computer Engineering

ECNG 2005
Laboratory and Project Design 3

DESIGN PROJECT REPORT


Remote PI Control of a DC Motor Using a PIC

Marlon Boucaud
1

808011031
Group G

Course Lecturer: Dr. Ronald De Four

Date Submitted: April 23, 2010

Table of Contents

Table of Contents............................................................................................................................iv
List of Figures................................................................................................................................vii
List of Tables................................................................................................................................viii
Abstract...........................................................................................................................................ix
INTRODUCTION.........................................................................................................................10
THEORY.......................................................................................................................................12
DC Motor Operation..................................................................................................................12
Importance of Control................................................................................................................13
Control Schemes that exist for DC Motor.................................................................................15
Requirement Specification.........................................................................................................17
Motor Specifications..............................................................................................................17
Transistor Driver Specifications............................................................................................17
PIC Specifications.................................................................................................................18
Transmitter / Receiver Specifications....................................................................................19
Existing Approaches to the Implementation of Control Algorithm...........................................19
Remote analog communication techniques...............................................................................21
Velocity measurement................................................................................................................22
Block Diagram of System showing Major subsystems.............................................................24
STANDARDS AND PROTOCOLS..............................................................................................25
Laboratory Protocol...................................................................................................................25
Industrial Standard for Safety Protocol.....................................................................................27
General Duties.......................................................................................................................27
Code of Practice.........................................................................................................................29
Risk Assessment........................................................................................................................30
Evaluation the risks....................................................................................................................31
4

DETAILED DESIGN AND APPROACH METHODOLOGY.....................................................33


Design Brief...............................................................................................................................33
Time Management Schedule/Project Direction.........................................................................34
Product Design Specification....................................................................................................34
Detailed Design Problem...........................................................................................................37
Project Plan................................................................................................................................38
Concept Design and Evaluation.................................................................................................39
Evaluation of Conceptual Design..........................................................................................40
Detail design of the motor.........................................................................................................43
Mathematical Model..............................................................................................................43
Determination of key motor parameters and justification of design.....................................48
Design Consideration.................................................................................................................49
Control, Measurement and display of the measured speed...................................................49
Choice and use of micro-processor peripheral......................................................................55
Position / Speed of the Motor................................................................................................60
Display of the Speed..................................................................................................................61
Techniques for driving the Motor..........................................................................................62
Units and the Nature of Set Point..........................................................................................64
RESULTS AND ANALYSIS.........................................................................................................66
Communications Section...........................................................................................................66
Analog Section...........................................................................................................................66
Motor.....................................................................................................................................66
Driver Circuit and Current Sensing.......................................................................................66
Display Unit...........................................................................................................................66
Controls......................................................................................................................................67
DISCUSSION................................................................................................................................68
CONCLUSION..............................................................................................................................72
REFERENCES..............................................................................................................................73
Books and publications:.............................................................................................................73
Websites:....................................................................................................................................74
5

APPENDIX 1.................................................................................................................................75
Code for the PI control, Display unit and the speed control......................................................75
Nichibo DC Motor.....................................................................................................................87
Datasheet for Phototransistor Optical Switch..........................................................88

List of Figures
Figure 1:Block Diagram of system being controlled.....................................................................13
Figure 2: Block Diagram of Major Subsystems of Design............................................................23
Figure 3: Shows the General Block Diagram Conceptually Designed..........................................38
Figure 4: Shows a 3-dimensional diagram for real world application...........................................39
Figure 5: Conceptual Design of the Control Algorithm................................................................41
Figure 6: Shows the Mathematical Model of the DC motor.........................................................42
Figure 7: Actual Motor Root Locus...............................................................................................46
Figure 8: Step Response for Actual Motor....................................................................................47
Figure 9: Shows the block diagram for the PI control specifications............................................49
Figure 10: Shows the In depth Block diagram of the PI controller with the motor......................49
Figure 11: Root Locus for Motor with PI control..........................................................................51
Figure 12: Step Response for motor with PI Control....................................................................52
Figure 13: Motor rot locus with proportional on PV Control Topology.......................................53
Figure 14: Motor step response with proportional on PV control topology..................................54
Figure 15: PWM for the PIC 16F877 chip....................................................................................56
Figure 16: Shows the PWM output from any device....................................................................57
Figure 17: Show the diagram of the motor with the controller used for position / speed of the
motor..............................................................................................................................................59
Figure 18: Shows the LED display unit used................................................................................60

List of Tables
Table 1: Shows the required Specification of the Motor...............................................................17
Table 2: Shows the PIC specification of the Design......................................................................18
Table 4: Shows the values characters that could be displayed on the LED display unit...............62

Abstract

The main objective of this design project exercise was to conceptually design, construct,
and test/troubleshoot a remote Proportional Integral (PI) control Direct Current (DC) motor using
a Peripheral Interface Controller (PIC) to meet the design specification. The specified motor to
be used was the Nichibo model PC 280-20215 which has an operating voltage range of 3-9.0 for
maximum operation of the motor and must be driven by a dc voltage from a standard laboratory
power supply. The PI control strategy must be programmed on the PIC16F877 chip. The motor
must be designed to drive a toy car model with wireless communication range of at least 1m so
that it would not interfere with other transmitting and receiving signals from other devices and
the motor must not turn in event of the communication loss. For circuit protection, the circuit
must employ current sensing to limit any current exceeding 1A from passing through the circuit.
The speed of the motor was measured using a Photo transistor Interrupter switch and interrupter
disc and the speed was displayed on the LED seven segments, in such a way as to suppress the
leading zero when displaying values. All circuits were constructed on Multisim7.0 and simulated
to ensure that each of the designed part was functioning as inspected. The design fabricated in
parts and was then mounted together to get the full system. The system was then tested with all
system features fully upgrade from the original specification. The motor operated in the range of
3-12V with a maximum current of 2.48 and when the current breached 1A the current cut off
limited the current. The receiver system outputted a square wave of 8V peak to peak and was
able to establish a wireless communication range of at least 1m. The display unit was tested
without the PIC16F877 chip in the presence of the laboratory technician and each LED bar
lighted up by testing each segment. The number 5 was then demonstrated and multiplexing of the
LEDs was also shown. The PIC16F877 chip was programmed with a combination PI control,
speed control and display code. The entire system was not tested when integrated due to erros as
well as time constraints and work load .Standards and laboratory protocols were followed
10

throughout the design and any discrepancies encountered were elaborated on in the discussion of
this report.

11

INTRODUCTION

This report dealt with the design, and construction of a remote PI controlled DC motor which is
implemented on a PIC16F877. This project incorporates the use of wireless communications of
the transmitter and the receiver, control algorithm of the motor implanted on the PIC16F877
chip, a photo transistor for sampling the position of the shaft to determine the speed, uses
feedback of the controller to determine the error between the set-point and the algorithm is
correct, if correct the PIC manipulates the code and takes the sample speed into consideration in
order to display the speed on the display unit.
Controlling the speed of dc motors with different loads is becoming very important for industrial
companies in Trinidad and Tobago. The technologies that exists for the speed control of a DC
motor are improving every year and field study of speed control for DC motors are becoming
more interesting and applicable to industrial sites. Engineers at universitys all over the world are
now using wireless control for Dc motors as it provides devices such as robots with FOM
(freedom of motion) which is very important in society today.
Also devices which were controlled using analog techniques are now being replaced by digital
system since they tend to offer a much more flexibility and are easier to use than the analog
systems. However for the purposes of this design project we will implement an analog
communication system which will achieve a 1m wireless control range. Depending on the type
of control used the main aim of industrial companies is to ensure that the system is able to
maintain a desired output. There are two types of control system; open loop control system and
closed loop controls such a Proportional control, Proportional-Integral Control, ProportionalIntegral-Derivative control and fuzzy logic control. The rate at which these different methods can
react to changes and precision at which they are able to maintain set point control is beyond the
scope of this project.

12

Circuit protection is necessary when designing any product. Limiting the current and thus the
dissipative power in the circuit protects circuit elements by ensuring that the power dissipated in
the circuit does not exceed the maximum power rating. At the end of this project the design must
be able to:

Output Voltage Varying from 3.0 9.0 V


Maximum output Current of 1A
Adjustable Speed from 0 10000 rpm at no load
Turn the motor in one direction only i.e. uni-directional
Wireless Communication Range of at Least 1m
Motor PI control Algorithm must be programmed on the PIC16F877 Chip for speed, PI
control and display unit.
Current sensing and current limitation of currents exceeding 1A from passing through the
circuit
Measure the position of the shaft to determine the speed of the motor
Display the speed of the motor on the four 7-segment LEDs
Suppress the leading zero on the Display when displaying the speed

All the specifications for this design were not indicated, so students were allowed to
choose their own specification for the design taking the load into consideration. For design
purposes, values for determination of the PI controller was selected a 5% overshoot and 2%
setting time of two seconds and based on these values scaling was assessed. The load
specifications of the motor were not provided in this project.

13

THEORY
DC Motor Operation

DC motors operate by transforming electrical energy which is in the form of a DC


voltage into mechanical energy usually in the form of either a rotational or linear motion. The
change from one form to another is due to the magnetic interaction between the armature and the
stator windings in the motor. The armature core of the motor encompasses basically of a winding
on a soft iron core which is coupled to the shaft within the motor. The windings reduce eddy
currents. Slots are stamped on the periphery of laminations to provide mechanical security to the
armature winding and to create a shorter air gap for the magnetic flux to cross between the face
and the armature teeth. The function of the shaft is to support the armature core within the stator
shell so that magnetic field interaction would occur. The shaft also allows the motor to drive a
load since the useful power output of the motor is the turning effect due to the shaft rotation. The
stator produces a fixed magnetic field which is the result of an induced voltage in the rotor
conductors and therefore results in the cutting of the rotating magnetic fields of the stator. The
fixed magnetic field can be achieved by a permanent magnet or an electromagnet which
comprises of a stator field winding which is wound on a piece of magnetic material. If we apply
a voltage to the motor the armature windings would set up an isolated magnetic field which
works together with the field generated in the stator to produce the rotation of the armature and
the shaft. In order that we maintain armature excitation, we would have to let the shaft rotate to a
steady state position. If however we want to achieve a continuous rotation in the motor, by
changing the armature excitation this can be achieved. In industry most of the DC motors are
used for either armature control or Field control. In armature controlled systems, the field current
is kept steady and the speed of the motor is altered by varying the armature current. In this case a
steady field current implies that the motor is operating at a constant magnetic field. There the
permanent magnet DC motors are thus armature controlled. For field controlled systems, the
armature current is kept steady and the motor speed is changed by varying the field current. The
more efficient method of DC motor control is the second since field controlled systems generally
14

require less power and they have under-damped speed characteristics which are preferred in most
industries.
There are several types of self excited DC motors which include:
i.) The Series Motor For the series motor, the flux varies directly with an increase in current
and the graph becomes less proportional. This is due mainly to magnetic saturation and current
decreases within the motor. The speed is inversely proportional to the current flowing in this
machine. Therefore, small loads are likely to cause a greater increase in the speed. This is an
undesirable effect, and care must be taken when coupling the load with the motor.
ii.) The Shunt Motor - In this motor the shunt field winding is connected in parallel with the
armature terminals to self-excite the motor. The value of I aRa when the motor is at full load, does
not exceed 5 percentage of the voltage value. The variation of speed with the input current can be
represented as constant horizontal line. For this arrangement of the motor, the flux may cause the
armature current to change by a small value. Since the speed does not vary with applied load,
this motor is most useful where the speed is required to be constant for a wide load range.
iii.) The Compound Motor- This motor is a combination of both a shunt resistor and series
resistor. At no load, the armature current is low and the magnetic motive force (mmf) is
negligible. At this point, the shunt field is fully excited and causes the motor to behave similar to
that of a shunt motor.

Importance of Control
Control systems are very important in both industrial and manufacturing environments.
Control system analysis and design are used to determine how a system is manipulated so that be
behaves in the way we want it to work. According to the control systems engineer at ISPL, a
control system is an interconnection of components connected or related in such a manner as to
command, direct, or regulate itself or another system. As defined in a book, a control system
is a device or set of devices that manage the behaviour of other devices. Surely there are many
definitions of what is a control system, all of which portray the importance of control systems in
15

industry. Some devices or systems are not controllable i.e. they cannot be controlled manually
or automatically. A Controller is used to implement a control strategy on a target system. The role
of the controller can be played by a human or a device. A system that is controlled by a human
operator is said to be under manual control. The diagram below shows a block diagram a system
to be controlled.

Figure 1:Block Diagram of system being controlled

From the above diagram the definitions of each is defined below:

Controlled System A controlled system is a system designed to effect control on another


(target) system

16

Plant - the system to be controlled


Outputs - A variable that is to be controlled. Outputs are also called controlled variables.
Inputs - Variables that cause changes in the system to be controlled, including the system
output. Manipulated Variables: Inputs that an engineer can access to effect control
Disturbances/Disturbance inputs: Inputs that an engineer cannot access to effect
control. Disturbances tend to affect the outputs adversely.
Source: Professor Brian Copeland lecture 1.1

Long time ago, instead of controlling the pressure values of different substations with
computers, engineers would be on the plant controlling the valves manually. Now that all the
controls can be monitored on computers there is no need to be on the plant. In a matter of a few
minutes they can adjust the valves and have the situation under control without having to leave
the room. Such systems that is controlled by a device is said to be under Automatic control.
Taking into account the environment at the ISPL plant, control is very essential as it:
Monitor the control processes within the company premises
Control the operation of the various plants associated with ISPL
Production of the companys products can be controlled via control stations
Enhance the overall performance of the plant
Makes the workers job at the plant very simple.
Schemes can be varied to operate in the manner which is most efficient to the company
Now that control rooms are made, plant controllers control situation without leaving the
room. They could also use automatic control which is very simple to control.
17

Control Schemes that exist for DC Motor


Nr

For the D.C. motor, the effective relationship

holds. Thus varying the voltage

across the armature or altering the flux can cause speed variations within the DC motor. In the

expression Nr = Speed of motor; V = Armature voltage; and

= Flux. There are several methods

of speed control schemes that exist for DC motors.


The first method of speed control is shunt and compound motors. A variable resistor may
be placed in series with the shunt winding. In this method of speed control there is an increase in
field resistance, a decrease in flux, field current and generated electro motive force is
experienced. As a result, the armature has a big current flowing through it and this increased
torque accelerates the armature until the generated electro motive force is equivalent to the
applied voltage. This method does not support speed decrease. The speed may also be increased
to up to four times the speed at full excitation.
Advantage : The speed of the motor can be increased up to three to four times that rated
at full excitation
Disadvantage the speed cannot be reduced below the full excitation speed and with any
regulator device the speed remains approximately constant between no load and full load

The second method of speed control is Armature-voltage DC Motor Control. In this


method, shunt-field current is maintained constant from a separate source while the voltage
applied to the armature is varied. Dc motors feature a speed, which is proportional to the counter
emf. This is equal to the applied voltage minus the armature circuit IR drop. At rated current, the

18

torque remains constant regardless of the dc motor speed (since the magnetic flux is constant)
and, therefore, the dc motor has constant torque capability over its speed range.
Advantage:
Speeds increases from zero to infinity
Used to control the speed of equipment such as cranes and trains where motor are
often switched on and off
Disadvantages:
The controller is very costly
Most of the energy which is put into the system is dissipated in the controller
Efficiency of the motor is reduced
Variation of the speed due to variation of the load which causes a change in the
potential difference across the controller which causes a change in the potential
difference across the motor. This property is not wanted in motor systems.
The third method of control is by supplying the motor with an ac supply controlled by
thyristors. This is a rectifier that is non-conducting in both the forward and reverse directions.
This device has an electrode (the gate) that causes it to be fired when a pulse of current is
introduced. A fired conductor means it conducts in the forward direction until the current falls
below a holding value.
Advantage
Fluctuation of currents can be controlled by:
1. Using two thyristors to give full wave rectification for a single phase
system
2. Using a combination of three or even six thyristors when the system is
three phase
Disadvantage: large loads cause the speed of the motor to decrease, thereby allowing
large currents to flow
The final method of speed control involves the connection of a resistor in series with the
armature, called a controller. This resistor is connected in a similar manner to a starter, however
it is designed to differ from the starter in that in can carry the armature current indefinitely
without getting dangerously hot. This controller works in the manner that the higher the resistor
value, the lower the potential across the armature and thus the lower the motor speed.
19

Advantage: The motor configuration can withstand large currents without becoming hot
Disadvantage: Resistors adversely affect the performance of the machine

Requirement Specification
The proposed design for the remote PI controlled DC motor should be able to meet the
specifications of the customer, cost management practices, quality and shell life durability and
OSHA safety protocols. The requirement specifications for the design are determined and stated
in a point format below.
The remote PI control of the DC motor using a PIC16F877 should conform to the following
requirement specifications:
Motor Specifications

Model

PC-280-20125

Operating Voltage Range

3.0 - 9.0 V

Nominal Voltage

6.0 V constant

No load Speed

10,000 rpm

No load Current

0.14 A

Maximum Efficiency speed

7560 rpm

Maximum Efficiency Current

0.57 A

Maximum Efficiency Torque

21.08 gcm

Maximum Efficiency

48.55%

Stall Current

2.48 A

Stall Torque

117.00 gcm
20

Table 1: Shows the required Specification of the Motor

Transistor Driver Specifications


Motor control system must operate in a switching speed range from 1KHz to 20KHz
To switch the device quickly the gate driver must be able to rapidly sink and source
currents of up to 1A.
Simple Gate requirements
A Resistor and transistor 2N2222 to ensure that the circuit has an excellent drive
performance.
PIC Specifications
Model
PIC16F877
Operating Frequency

DC - 20 MHz

RESETS (and Delays)

POR, BOR, (PWRT,OST)

FLASH Program Memory

8K

(14-bit words)
Data Memory (bytes)

368

EEPROM Data Memory

256

Interrupts

14

I/O Ports

Ports A, B, C, D, E

Timers

TMR

Capture/ Compare/ PWM modules

PWM max. resolution is 10-bit

Serial Communication

MSSP, USART

Parallel Communications

Parallel Slave Port (PSP) 8-bits wide, with


21

external RD, WR and CS controls (40/44-pin


only)
10 bit ADC Module

8 channel Inputs

Instruction Set

35 Instructions

Table 2: Shows the PIC specification of the Design

Transmitter / Receiver Specifications


USB Bluetooth Module this is used to bridge the Gap between the PIC16F877 and the
Transmitter and the Receiver. The signals will then be received and manipulated from the
motor control software.

Bluetooth Module - This is the other end of the Bluetooth wireless connection, it is the
module that will receive the wireless signals from the USB transmitter and send them to
the PIC16F877 chip which has the control unit. It is capable of communication via UART
(serial) communication. The control signals will be received by the receiver via the USB
Bluetooth transmitter and sent to the PIC16F877 microcontroller via TX / RX serial
communication which are pins 10 and 11 on the module.
Provide Wireless Communication range of at least 1m.

22

Must inhibit good interference Rejection This is important so that the receiver does not
detect other unwanted frequencies within its range. It must also have good sensitive
characteristic.

Existing Approaches to the Implementation of Control Algorithm

There

are

many

methods

which

exist

with

regards

to

the

implementation control algorithms. Control algorithm can be implemented


based on the control technique which is employed. There control algorithms
that exist which include open loop control and closed loop controls such as P,
PI PID control algorithm and in some cases fuzzy logic. The main closed loop
control technique is Proportional Integral derivative or PID control. The term PID
stands for Proportional, integral and derivative controls. PID can be described as a set of rules
with which precise regulation of a closed-loop control system is obtained. Closed loop control
means a method in which a real-time measurement of the process being controlled is constantly
fed back to the controlling device to ensure that the value which is desired is, in fact, being
realized. The mission of the controlling device is to make the measured value, usually known as
the Process Variable, equal to the desired value, usually known as the set-point. The very best
way of accomplishing this task is with the use of the control algorithm we know as PID.
This principle mode of action of the PID controller can be explained by the parallel
connection of the P, I and D. The most important of these, Proportional Control, determines the
magnitude of the difference between the Set-point and the Process Variable. Proportional
feedback control can reduce error responses but that it still allows a non-zero steady-state error
for a proportional system. In addition, proportional feedback increases the speed of response but
has a much larger transient overshoot. When the controller includes a term proportional to the
integral of the error, then the steady-state error can be eliminated. Since Integral Control
examines the off-set of Set-point, it introduces a pole s = 0 in the forward loop. But this comes at
the expense of further deterioration in the dynamic response. Addition of a term proportional to
the derivative of the error can damp the dynamic response. Derivative Control monitors the rate
23

of change of the process variable and consequently makes changes to the output variable to
accommodate unusual changes. Combined, these three kinds of actions form the classical PID
controller, which is widely used in industry. Each of the three control functions is governed by a
user-defined parameter. These parameters vary immensely from one control system to another,
and, as such, need to be adjusted to optimize the precision of control.
The other two control algorithms that exists stems out from the PID
control. PI control as PID is a very popular control algorithm. It can give close
to optimal performance for low order systems and fairly good performance
for more complicated systems, provided that the specifications are not too
demanding. PI control strategy demands that there be at least one pole at
the origin in the cascade of the controller and plant or an integrator in the
forward loop. This control algorithm can only provide perfect set point control
if the system is stable. If a stable system is achieved however there is no
guarantee that the system would inhibit a good transient response. P control
however is not as effective as the other two algorithms. This algorithm can
achieve stability of the system and help to improve the transient response of
the system. This is very important in controlling systems but engineers
discovered that system performed better when we integrated the separate
control algorithms together.
Fuzzy logic is used in many different industries for the speed control of a DC motor.
They can determine the rate at which the DC motor can spin. If the motor is spinning to fast
fuzzy logic action is taken from the manual control to adjust the speed of the motor. Therefore
the speed can be decreased to obtain the required value. If the speed of the motor is too slow
fuzzy logic action would taken and based on the value which the motor is programmed to operate
at the manually, the speed can be adjusted to compensated for the decrease in speed.
The other method of control implantation is by the use of Feed-forward or open loop
controller. Open Loop controllers control the motor input in a predetermined fashion based on
the knowledge of the system model i.e. the output has no effect on the control action. In open
24

loop control systems the output is not compared with the reference input. Thus to every reference
input there is a corresponding fixed operating condition and as a result the accuracy of the
system depends on the calibration. In the presence of disturbances, an open loop will not perform
the desired task. Open loop controls can be used in practice only if the relationship between the
input and the output is known and if there are either internal or external disturbances. These
systems are time based systems such as sequential and continuous control.
The main advantage of the closed loop over open loop control system is that for closed
loop control feedback makes the system respond accurately to systems and the fact that they
improve the overall performance of the system. However closed loop systems which implement
P, PI, PID or Fuzzy logic controls is very costly and requires more power consumption than the
open loop system. By combining the two types of controls algorithm we can achieve a good
performance of the motor at a reasonable cost. For design purposes of this project, we used PI
control to control the speed of the DC motor.

Remote analog communication techniques


Remote analog Communication techniques are being replaced today with highly computerized
remote digital analog communications techniques. Since the early 1900s, remote analog
communications were developed so that people could communicate with each other without
leaving the comfort of their homes. The analog system consists basically of a simple transmitter
and receiver system. The transmitter is an electronic device which uses an antenna system to
transmit radio, television as well as other telecommunication signals. At the other end is the
receivers which are another electronic circuit which receives the output from the transmitter,
filters out the signal wanted from the unwanted signal, then amplifies the signal to the desired
level required and then demodulate the signal into the sound or the signal that is desired. The
inter-connection between the receiver and the transmitter provides the wireless communication.

25

Proper design of any antenna system could be accounted for by maximum range, selectivity,
good interface rejection and low noise in the system.

Velocity measurement
Angular velocity sensors, or tachometers, are devices that give an output
proportional
to angular velocity. These sensors find wide application in motor-speed
control systems.
They are also used in position systems to improve their performance
(Delmar)

Optical encoder An optical rotary encoder produces angular position data


directly in digital form, the encoder uses a slotted disk attached to a shaft, A
light source (usually a LED) and photocell (usually photo transistor) are then
place on opposite side of the disk so that as the disk rotates the light beam
from the source is interrupted to produce a train of pulse. The angle of the
shaft can then be obtained
from the output of the photocell. There are two types of optical rotary
encoders: the absolute encoder and the incremental encoder.

26

Absolute optical encoders use a glass disk marked off with a pattern of
concentric tracks with a separate light source / photo sensors pair for each
track. Hence each photo sensor contributes 1 bit to the output digital word.

The absolute encoder shown in figure 1 above outputs a 4-bit word with the
LSB coming from the outer track. To improve the resolution more track could
be added

Incremental optical encoder has only one track of equally spaced slots,
where each slot represents a known angle. The Position is determined by
counting the number of slots that pass by a photo sensor and the velocity by
measuring the time between pulses generated by the rotation of the slotted
disk.

Velocity =

i.e. the rate of change in angle


27

Velocity data can be derived from an optical rotary encoder by counting the
amount of pulse for a set period time for example if the encoder has 8 slots
and the sample period is for 1 minute then the speed would be
N pulse / minute or N/8 revolution per minute (rpm)

The speed could also be calculated by measuring the time between pulse for
example using the same encoder above but with the time between each
pulse being 1 second
8 slot would correspond to 360/8 = 45 degree

rad / sec
4
1
Velocity =

The absolute encoder has an advantage over the incremental encoder base
on the fact that it out is a digital signal while the incremental encoder
velocity has to be calculated, absolute encoder however requires more
hardware in the form of light source and photo cell.
Another method for measuring the velocity of the motor is the use of a small
motor configured as a generator and connected by gears to the motor
velocity being measured. This method was not practical for this project as
the DC motor used was a small DC motor.

28

29

Block Diagram of System showing Major subsystems

Figure 2: Block Diagram of Major Subsystems of Design

The concept design is showed in figure 2. it comprises of several subsystems namely,


Communications Controls Electromechanical Micro processing and Electronics. The system
operation would follow the trace on figure 2. The output would then be sent to the seven segment
displays.

30

STANDARDS AND PROTOCOLS


Laboratory Protocol
It was essential that we follow standard laboratory protocol when working in the laboratory.
The year two lab and the microprocessor lab were the labs that were most frequently used.
Therefore the following laboratory protocols and practices which may reduce risk of injury when
working with electrical equipment in the lab:
Stay away from energized electrical circuits.
Ensure that all power supplies are disconnected before adjusting parameters on electrical
circuits or change components on the electrical circuit.
Electrical machinery around work stations should be elevated from the floor to avoid
injuries to tripping over the equipment.
When handling equipment that has to be plugged e.g. Soldering iron and power supplies,
make sure that your hands are dry. If required and available it is standard that nonconductive gloves be used to handle electrical equipment.
When it is necessary to handle equipment that is plugged in, be sure hands are dry and,
when possible, wear nonconductive gloves and shoes with insulated soles.
No eating should be allowed around the work stations.
Dress code conduct should be adhered to by users of the laboratory. Girls should be fully
clothed at all times. Girls with long hair should tie it up properly to avoid any contact
with electrical machines. No slippers should be allowed in the laboratory however a steel
tip boot or pair of sneakers should be worn at all times.

31

Electrical equipment should be minimally used in air conditioned room or any area where
there is condensation taking place. If electrical equipment is used in air conditioned
rooms, all equipment should be mounted to the wall or a vertical panel.
Make sure that all circuits are checked by the laboratory technician before powering up
If any form of liquid falls on electrical circuit, unplug the equipment and then make sure
to mention to the laboratory technician so that he can shut the power at the main switch
and circuit breaker off.
All switches by the work station should be readable and correctly labelled so that there
would be no misinterpretation of the use of the switches on the devices.
The medical kit present in the laboratory should be restocked on a regular basis.
The laboratory technician should ensure that all workspace provided is well kept and not
cluttered. All apparatus which are not used should be stored in an area which does not
obstruct individuals from working. Cupboard and shelves away from workstations should
be used to store this equipment.
A list of the safety standards and the laboratory protocols should be posted up in the
laboratory to make users aware of the rules conduct and safety standards.
In case of emergency students should remain calm and leave the laboratory in an orderly
fashion, to avoid collisions with persons or equipment and injuries.

According to the Occupational Safety and Health Act of Trinidad and Tobago 2004, some of
the standard laboratory protocols were not practiced in the laboratory.

32

1. Workspace area- the workspace area which was assigned to each student was 3.5 feet
from the ground and approximately 30 inches wide. According to the OSHA of Trinidad
and Tobago it is required that

A minimum working space of 40 inches wide is provided in front of electrical


equipment.2

The depth of the workspace should be clear to the floor and the depth should be
3ft, 3.5ft of 4ft depending on the existing conditions.2

2. Emergency exits- The emergency exit door is the same door which is used by all
individuals in and out of the laboratory on a daily basis. The door is approximately 11ft
high and is locked from the inside. OSHA standards require that

An exit door must be able to be readily opened from the inside without keys, tools,
or special knowledge. A device that locks only from the outside, such as a panic
bar, is permitted. The exit door must be free of any device or alarm, if fail could
restrict emergency use of an exit.2

3. Identification of switches in the panels The switches in the sub-panel, service panel and
other electrical equipment were not labelled properly. According to the OSHA of Trinidad
and Tobago standards require that

All switches and circuit breakers should be labelled and trace to appropriate
drawings.2
All switches and circuit breakers be allocated for easy access and permanently
marked to show disconnections.2

33

4. Fire Extinguishers-In the entire laboratory only one fire extinguisher was allocated to the
laboratory. According to the OSHA of Trinidad and Tobago standards require that

The laboratory technician shall assure that portable fire extinguishers are
subjected to an annual maintenance check. Stored pressure extinguishers do not
require an internal examination. The laboratory technician shall record the
annual maintenance date and retain this record for one year after the last entry or
the life of the shell, whichever is less. The record shall be available to the
Assistant Secretary upon request.2

(Occupational Safety and Health Act of Trinidad and Tobago, 2004 Accessed April 19th, 2009).

Industrial Standard for Safety Protocol

According to the Occupational Safety and Health Act of Trinidad and Tobago, 2004 it
is stated that an employee is any person who has entered into or works under a contract with
an employer to do any skilled, unskilled, manual, clerical or other work for hire or reward,
whether the contract is expressed or implied, oral or in writing or partly oral and partly in
writing, and includes public officers, the protective services and teachers. The employer is a
person who employs persons for the purpose of carrying out any trade, business, profession,
office, vocation or apprenticeship;
(Occupational Safety and Health Act of Trinidad and Tobago, 2004 Accessed April 19th,
2009).2
General Duties
Part II

34

1. It shall be the duty of every employer to ensure, so far as is reasonably practicable, the
safety, health and welfare at work of all his employees.
2. Without prejudice to the generality of an employers duty under subsection (1), the
matters to which that duty extends include in particular
a) the provision and maintenance of plant and systems of work that are, so far as is
reasonably practicable, safe and without risks to health;
b) the provisions of such information, instruction, training and supervision as is
necessary to ensure, so far as is reasonably practicable, the safety and health at work
of his employees;
c) the provision of adequate and suitable protective clothing or devices of an approved
standard to employees who in the course of employment are likely to be exposed to
the risk of head, eye, ear, hand or foot injury, injury from air contaminant or any
other bodily injury and the provision of adequate instructions in the use of such
protective clothing or devices;
d) so far as is reasonably practicable as regards any place of work under the
employers control, the maintenance of it in a condition that is safe and without risks
to health and the provision and maintenance of means of access to and egress from it
that are safe and without such risks;
e) provision and maintenance of a working environment for his employees that is, so far
as is reasonably practicable, safe, without risks to health, and adequate as regards
amenities and arrangements for their welfare at work;
f) arrangements for ensuring, so far as is reasonably practicable, safety and absence of
risks to health in connection with the use, handling, storage and transport of
equipment, machinery, articles and substances;
(Occupational Safety and Health Act of Trinidad and Tobago, 2004 Accessed April 19th,
2009).2
Safety Protocol is essential in every industrial work place. On industrial sites it is proper
procedure to follow Industrial safety standards and protocols. The main reason for adhering to
these protocols is to ensure that there is minimal injury of any employer or employee on the
industrial site. According to the Occupational Safety and Health Act of Trinidad and Tobago,
2004)2 a critical injury is defined as that which:
35

a)
b)
c)
d)
e)
f)
g)

produces unconsciousness ;
places a persons life at risk ;
Results in substantial loss of blood;
involves the fracture of a leg or arm, but not a finger or toe;
involves the amputation of a leg, arm, hand or foot, but not a finger or toe;
consists of burns to a major portion of the body; or
causes the loss of sight in an eye ;

The employer of every industrial company should adhere to the rules and regulations of the
OSHA Trinidad and Tobago 2004, to seek the best interest of his employer and prevent injuries
where possible. (Copeland 2009)

Code of Practice
According to the ANSI / NEMA ICS 61800-1 standards for Adjustable Speed Electrical Power
Drive Systems 2002 3 the following codes of practice for the design of the remote PI control dc
motor on the PIC 16F877 are:
1. Speed Range - The speed shall be capable of being adjusted over a range of not less than
eight to one by the armature voltage control. This speed range may be extended by the
motor field weakening to a maximum speed depending on the motor rating.
2. Over-current protection devices - the current setting of over current protection devices
shall not exceed the service limit output current rating of the Basic Drive Module.
3. Acceleration control Drives shall be provided with either current limit or timed
acceleration
4. Dynamic braking Dynamic breaking is the addition of dissipative elements to allow
faster electrical breaking of the machine. When dynamic breaking is provided:
a) The converter shall be capable of braking a load at a current of 110%, 125% or
150% of the rate current, depending on the converter rating;
b) The dynamic breaking resistor shall be capable of absorbing two times the
rotational energy of the motor at maximum speed;
c) Drive systems with large variable inertia of the driven equipment shall be capable
of breaking the maximum stored energy;
5. Dynamic Slowdown - when dynamic braking is provided, the resistors shall be capable of
absorbing the total stored rotational energy of the armature and the driven equipment
under two consecutive braking sequences from maximum to minimum speed, with the
resistor initially at ambient temperature.
36

6. Marketing the following shall be supplied on the rating plate of the Basic Driver Motor
a) The manufacturers name
b) Equipment identification (model number, serial number, and year of
manufacture).
c) Input ratings voltage; rated current; frequency; number of phases; minimum
impedance
d) Output ratings rated output voltage; rated continuous current; overload
capability; rated power;
e) Output rating field
7. Storage of Equipment the equipment shall be placed under adequate cover immediately
upon receipt if packing coverings are generally not suitable for outdoor or unprotected
storage.
8. Transportation Equipment shall be capable of transportation in the suppliers standard
package under environmental conditions specified in class 2k3 of IEC 60721-3-2.3

Risk Assessment
A risk assessment of the standard laboratory protocols was done for the microprocessor
laboratory to ensure that the laboratory adhered to safe working conditions and complied with
the practices of the Occupational Safety and Health Act of Trinidad and Tobago 2004. As define
in the dictionary a hazard is anything which can cause harm to an individual e.g. electricity, fires,
chemicals, etc. As defined in the dictionary a risk may be classified as the likelihood of any harm
occurring and the possible severity of the effects. As stated in section 5a of the Occupational
Safety and Health Act ("OSHA") of Trinidad & Tobago employers are required to

provide workplaces free of recognized safety hazards that are likely to cause
death or serious physical harm
tell you if you are working with hazardous materials
give you any special training necessary to do your job safely
keep records of all workplace injuries, deaths and any exposures to toxic or
hazardous materials2

Some of the hazard and risks that were found in the laboratory were:
37

Cluttered area around work station- This applies to any individual/s working at a work
station. Working space around electrical equipment should be adequate for conducting
all design operations safely. The work area should be cleared from all unnecessary
equipment that might be taking up space. Individuals may unconsciously forget the
presence of the machine allocated close to them or machinery not within the persons
scope of view. As a result they may come into contact with such equipment and sustain
some injury.
Laboratory equipment not kept in the appropriate location when unused- Some heavy
machinery and discarded projects were left carelessly by workstations. Individuals may
trip over exposed equipment or even become electrocuted due to high voltage flowing
through the equipment.
Insufficient workstations and laboratory space- The laboratory was found to be too
small to accommodate the total number of individuals present. This congestion creates
the possibility of people colliding with each other and with equipment.
No fire extinguisher- The laboratory under inspection was large and contained a
number of high powered computers and other electrical devices. There was no fire
extinguisher available. In the event of a fire, due to electrical calamities there should be
a number of extinguishers should be available to quickly put out the fire and reduce any
damage and injury possible.
High powered machine left exposed- Heavy machinery which is left the walking path of
individuals creates the possibility of people tripping over the equipment. This could result
in severe injury to the individual and to the equipment itself.
Absence of Safety signs- This prompts individuals to thinking that any attire can be worn
in the laboratory. However proper clothing and other attires are needed to be worn by
any individual who intend to use the lab to ensure safety.
Medical supplies were insufficient- The medical supplies in the laboratory were found to
be inappropriate in that it lacked the supplies needed to take care of medical
emergencies.

38

No equipment to detect possible hazard, alarms etc- In the event that an emergency
occurs; there are no devices to detect or warn lab users of potential danger were found.
Consider for example, in the event of a fire, a smoke detector should have been installed
to warn individuals of a possible fire.5

Evaluation the risks


This is a consideration of how likely each hazard identified could cause harm. As defined
by the Canadian Centre for Occupational Health & Safety, the definitions for the potential
severity of harm are shown below.
Potential severity of harm - When establishing potential severity of harm, information about
the relevant work activity should be considered, together with:
a) part(s) of the body likely to be affected;
b) nature of the harm, ranging from slight to extremely harmful:
1. slightly harmful (e.g., superficial injuries; minor cuts and bruises; eye irritation from dust;
nuisance and irritation; ill-health leading to temporary discomfort)
2. harmful (e.g., lacerations; burns; concussion; serious sprains; minor fractures; deafness;
dermatitis; asthma; work-related upper limb disorders; ill-health)
3. extremely harmful (e.g., amputations; major fractures; poisonings; multiple injuries; fatal
injuries; occupational cancer; other severely life shortening diseases; acute fatal diseases)
(Canadian Centre for Occupational Health and Safety 2004, Accessed 19th April,2009)4

39

DETAILED DESIGN AND APPROACH METHODOLOGY

Design Brief

The project entailed the conceptual design; construction and testing/ troubleshooting of a
remote PI control DC motor using a PIC16F877 chip for implementation from discrete electronic
parts. The design was assembled and tested/ troubleshoot using basic laboratory and specification
protocols. The standards that were available to us were provided by the University of the West
Indies. They included both the NEMA 250 (Enclosures for electrical equipment (1000V
maximum)and ANSI / NEMA 61800-1 (Adjustable Speed Electrical Power Drive Systems).
The Occupational Safety and Health Authority standards 2004 were also used for safety
protocols in the design project. These standards were used to design the remote controlled DC
motor since they were most applicable due to several factors which are:
The standards complied with the requirement specifications of the design
The standards accounted for the performance level as well as the quality of the product
being designed.
The standards adhered to the operation of product in environmental conditions
The standards also accounted for the storage conditions of the designed product
The standards adhered to safety standards and laboratory protocols required to reduce
and eliminate risks associated with the design project.
The standards also emphasized the functionalities of the produce to be designed.
The Standards complied with test specifications that were used to test the design. Time
Management Practices

40

Time Management Schedule/Project Direction


Objective

Time Duration

Research into Standards, recognize

March 25th March 30th

laboratory protocol , industrial standards,


codes of practice and occupational safety
protocols, business practices
Modeling of Nichibo Motor control

April 1st April 5th

parameters
Design and Construction of current sensing

April 5th April 6th

circuit
Design and construction of

April 6th April 20th

communications system (receiver and


transmitter)
Construction of LED segments to PIC and

April 10th April 20th

motor
Writing of Code

April 15th Still in Progress


41

Testing Of Communications Systems,

April 16th April 23rd

seven segment connections to PIC, proper


code compilation,

Product Design Specification


Based on the level of understanding of the lectures done by Dr. Ronald De Four which was
invocated prior to this semester lectures this section of the report was constructed. When
designing any product it is very important that we consider all activities of the design. For good
product design specification the following must be addressed. They are listed below in point
format below:
Performance- The remote PI control of the DC motor implemented in the PIC16F877
device must be able to have speed characteristics, accuracy, resolution, inter-connections
range and thorough put in order for it to achieve optimal performance.
Speed Characteristics and Range - The design was built to comply with basic
standards as well as to meet the specifications and the requirements demanded by
the customer. In accordance with speed the remote PI control DC motor must
operate within a voltage of 0-9V for maximum efficiency of the motor. Between 0
3 V there will be little of no response of the motor however when operated
within the range of 3 9 V the maximum response of the motor is achieved. The
nominal voltage is not constant at 6V since we need to vary the nominal voltage
in-order to maintain the speed. Under no load conditions the speed of the motor
should be around 10,000 rpm and be able to display this speed on the LED display
with the suppression of leading zeros. Accounting for the speed when the load
(Toy car) is driven the motor will initially slow down, and the voltage at the
output will decrease. This will cause an increase in the difference between the
voltages of the amplifier and cause it to drive more current to the motor. The
42

increased current will increase the speed of the motor to a speed of approximately

7560 rpm which is almost the speed of the motor without the load.
Accuracy and Resolution - Accuracy relates the smallest signal to the measured
signal whereas resolution relates the smallest signal to the measured signal. The
design must be able to show values which are in close proximity to the values
calculated. Accuracy is needed so that values do not vary much from the

calculated values.
Inter-connections - Wires were cut short enough to connect all components since
connecting wires posses resistance which can affect the performance of product
being designed. Also if wires are stripped improperly we could get input floating
or even partial connections. Check the breadboard for shorts between
neighbouring tracks. If there are shorts jump wires for maximum connection. For
soldering parts try not to make bad solder joints and make sure you have
connectivity between joints. This will improve the overall performance of the
design.

Environment- Environment is a key factor which affects the design of remote PI


controlled DC motor whose control algorithm is implemented on the PIC16F877. This
device must be built to be operated in any environment condition. It must be designed to
provide a certain degree of protection. According to the NEMA 250-2003 standards this
is a type 3RX which inhibits, Enclosures constructed for indoor use to provide a
degree of protection to personnel against access to hazardous parts and to provide a
degree of the equipment inside the closure against ingress of solid falling objects (falling
dirt); to provide a degree of protection with respect to harmful equipment due to ingress
water(rain, sleet or snow); that will be undamaged by the external formation of ice on
the enclosure that provides an additional level of protection against corrosion; and that
will be undamaged by the external formation of ice on enclosures.
Shell life- Shell life refers to the amount of time a product can operate efficiently without
any defects or faults. The product life cycle of the remote PI controlled DC motor
implemented on the PIC16F877 is time from which the design is fully functional to the
time that at least one part of the design fails to work or goes bad to proper design
43

practices. The must designed according to proper design standard and be constructed to
last at least a life-time under the environmental conditions indicated above. In this case it
could be marketed and meet the customers demand.
Quantity and Quality - If the design produced is successfully implemented, it may be
required that the customer may require a large quantity of the product designed. To
produce on a large scale purpose the cost of the design should be minimized without
affecting the quality of the product being designed and the time should be taken into
consideration also. The quality of the product being designed depends on a few
characteristics which include reliability, availability and maintenance.

Customer requirements- The product being designed must conform to the

specifications provided by the customer.


Reliability Is the product being designed reliable enough to withstand safety
conditions, performance specifications as well as be implemented in other

designs.
Availability the product must be ready and available by the designer for

commercial production, once it has passed test and safety standards


Maintenance The product must be design so that if there are any faulty parts, the
parts could either be fixed or replaced with ease.

Target Cost Cost is a major concern with the implementation of this design project. We
want to develop the Remote PI controlled DC motor on the PIC to achieve good
performance without having to spend excess money. So the best design approach was
used and minimal hardware/ material was used, to achieve the specifications of the design
without any short comings.

Detailed Design Problem


The Students of laboratory and project design III were required to design, build and test a
remotely controlled DC motor using a PI control strategy on a PIC. The designed process was
listed below:

44

1. We were required to use the specification sheet of the motor provided to determine the
mathematical model of the motor from the characteristic curves.
2. Measure the mass of the armature and the entire motor to find the motor capacity and
account for the load that the motor could handle.
3. Use the specification sheet for the disc to model the motor for load
4. Determine the control specifications of the model by finding both K i and K p
5. Use PWM for speed control of the motor
6. Program the PIC 16F877 to use PI control using PWM, perform motor control, and
display the change of speed on the LED displays.
7. The motor speed is measured by the phototransistor optical interrupter switch (H21A1)
and an interrupter disc.
8. Provide the design with current sensing strategies for currents exceeding 1A for the
protection of the motor.
9. Use a transmitter and receiver system which was previously built to achieve a wireless
communication range of at least 1 meter.
10. Combine the entire structure and test the design by varying the speed of the motor and
displaying the speed on the 7-segment LED displays. The motor speed is to be displayed
using 7-segment LED displays.

Project Plan
The design structure of the project requires the students of ECNG 2005 to design build
and test a remote PI controlled DC motor using a PIC16F877 chip. This design must take the
load into account and when implemented be able to drive the DC motor at a fixed speed when
different loads within the design is applied to it. The system was thoroughly analysed and the
45

based on the complexity of the design, it was broken down into smaller systems which can be
troubleshoot to examine how each part works and making the necessary adjustments to make that
section of the design work. When all systems are working, the system can be integrated into one
fully functional system. For the purpose of this design, it was essential that each section be
broken down since time management practice was poorly used. There are three major modules
and they include:
Communication Section
a. Building the transmitter
b. Building the receiver
c. Accounting for the wireless communication range of 1m
d. Communication requirements

Set Point from the computer to the Transmitter via the RS232 9pin serial
port

Transferring the square wave output from the receiver via the USART
which makes use of the Hyper-Terminal program to communicate the
signal to the PIC16F877 chip

Analogue Section
a. Motor Assembly
b. Driver Circuit
c. Current Protection of 1A

46

d. Speed Sensing Circuit

Controller
a. Modelling of the Motor and Controller
b. Pulse Width Modulation calculations
c. PI control Code
d. Speed sensing Code (increase or decrease in speed)
e. Display Module code
f. Programming the PIC16F877 chip

Concept Design and Evaluation

From the project plan devised before we take that into consideration, and conceptually
design the system. The block diagram below shows the conceptual design of the remote PI
controlled DC motor. By stepping through the design we see that the wireless communication
would transmit data from one point to another, which would then be sent to the PI controller
which would control the motor, which would then be sensed by the speed sensing module and
then display the speed on the Display unit.

47

Figure 3: Shows the General Block Diagram Conceptually Designed

The PI/ Speed control algorithm for the DC motor was required to be programmed on the
PIC16F877 chip. If we were to look at the design from a real world aspect the system would look
similar to that shown in the diagram below.

48

Figure 4: Shows a 3-dimensional diagram for real world application

Evaluation of Conceptual Design


The conceptual design of the proposed system for the remote PI controlled DC motor should
be capable of complying with the design specifications, cost management practices, quality and
shell life durability as well as the standards compiled by both ANSI / NEMA ICS 61800-1
standards for Adjustable Speed Electrical Power Drive Systems 2002 and the OSHA of
Trinidad and Tobago 2004. It is very important when designing a system that, the simplest
approach possible be taken. The conceptualized design was made with the following principles
in mind. These principles include:

Functionality - All functions the product is meant to perform


User interaction - Controls, displays
Physical form - Dimensions, weight, materials, aesthetics
Safety Legal - requirements - special considerations, results of product failure
Operating Environment Target environment - e.g. temperature and humidity ranges,
EMC

Signals Inputs, Outputs, response times


Power Supply - Source of power, power consumption
Maintenance Reliability - time between failures
Costs Development costs, product cost
Schedules Product time scales, delivery times6

49

(Source: Joshi, Ajay. Introduction to Micro-Processors 1 Course Lecture notes. DECE, 2009.6 )

By following the above principles, we can evaluate the way in which we could
implement the system without over-budgeting and using unnecessary hardware equipment. The
diagram below shows how the algorithm for the speed control of the DC motor could be
implemented.

50

Initialize variables for

Model the transfer

Programme the

error, potentiometer

function of the DC motor

PIC16F877 with the

voltage, PWM, reference

and the PI controller for a

Speed Control
Algorithm

No
Check the sample
time = Ts
Start the TMR1 to obtain

Initialize the motor

the PWM signal and TMR2

output and the

check the sampling time

controller output

Count the number of

Calculate the Speed of

pulses within the

the motor with no load

sample signal form the

with the current error

interrupter disc

Display the no load Speed of


Motor on LED
51

Yes

Find the speed of

Check the speed of the

motor

Motor with toy car load

Set TMR2 to zero


Find the new system
output from the change of

Back to TMR1

speed
And TMR2

Figure 5: Conceptual Design of the Control Algorithm

52

Detail design of the motor


Mathematical Model
The block diagram below was constructed to represent the Mathematical Model of the
Motor. The specification sheet for both the motor and the Photo transistor Optical Switch can be
used to determine the values of the mathematical model of the system.

Figure 6: Shows the Mathematical Model of the DC motor

Now recall that:


B eq=bm +

J eq =J m +

b
n2

jl
2

53

1
J l= ( m r 2 )
2

Motor Torque = ka x ia

ka is the motor torque constant


ia is the motor current

Torque is converted to SI units. To calculate for motor torque constant, the current and torque at
stall test results are used. The current Ia is found by the difference between the current values at
stall test and no load test
ka = Torque / Ia
= (117 x 10-5 x 9.81)/ (2.48 0.14)
= 0.004905 Nm/A

Theoretically, the motor torque constant is the same as the motor voltage constant in magnitude
but not in units.
From Figure 3, Kirchhoffs Voltage and Newtons Laws are coupled to give the flowing
equations
J + b = Ki
L di/dt + Ri = V K

Ka = Kb=0.004905

54

Ra = Va/ Ia
=6/2.48
=2.419

Moment of inertia of load is given by: JL = mR2

m is the mass of motor


R is the radius

JL = x 0.04kg x 0.0242
= 1.2 x 10 -5

J T = J L / n2 + J M

JT is total inertia
JL is load inertia
JM is mass inertia

Assumption: n = 1 and mass inertia is small compared to load inertia


Hence the total moment of inertia for the system is JL = 1.2 x 10-5 Nms2 /rad

From the graph of the motor characteristics, it can be seen that maximum velocity is at 10000
rpm at 0 torque value.

Damping ratio can be calculated by finding the motor efficiency


55

Power conservation Theory states that the output power is equal to the input power minus the
losses
Input power = VT x Ia
Output power = T x w
Power losses = I2 R (due to armature resistance) + frictional and windage losses PB
Efficiency is given by the ratio of the output power to the input power
Efficiency ,n = P out / Pin
= Pout / (Pout +P losses)
Ploss = (Pout / n) - Pout
= 1.64 / 0.4855 - 1.64
=1.74 Watts
Ploss = I2R + PB
PB = Ploss I2R
= 1.74 0.572 x 2.419
= 0.95 Watts
From the torque equation, Jeq w = T - beq w
We assume that angular acceleration is zero at steady state
Therefore T = beq w
Beq = T / w
56

= 0.0002108 / 446.1
= 2.66 x 10-7
Using the information acquired form the specification sheet, the value of the moment of inertia
of the motor, Jm, can be calculated:

J m = m m rm 2
J m =(0.04)(0.00915) 2
J m = 3.35 x 10-6

kg
m2

Jeq= Jm + (1/n2)JL

we assume n=1 thus

Jeq = 3.35 x 10-6 + 1.2 x 10 -5


=1.535 x 10-5
Hence the system parameters along with their values are shown below:

Damping Ratio of the mechanical system beq = 2.66 x10-7


Jeq =1.535 x 10-5
Electromotive force constant (ka) = 0.004905Nm/Amp
Electric resistance (R) = 2.419
Electric Inductance (L) = assumed to be zero
Input (V) = Source Voltage
Output = Velocity of Shaft
57

Assumption: rotor and shaft assumed rigid (for modeling purposes)


The transfer function for the DC motor is given as

When the values are substituted into the equation the following transfer function is derived:
K
166.7

s 1 1.26 s 1

TWE(s) =
The system was then inserted into MATLAB and using the rtool function the step response and
the root locus was made.

58

Root Locus Editor for Open Loop 1 (OL1)

1
0.8
0.6
0.4

Imag Axis

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-3

-2.5

-2

-1.5
Real Axis

-1

-0.5

Figure 7: Actual Motor Root Locus

59

Step Response

0.7

System: Closed Loop r to y


I/O: r to y
Peak amplitude >= 0.694
Overshoot (%): 0
At time (sec) > 2.5

System: Closed Loop r to y


I/O: r to y
Settling Time (sec): 1.5

0.6

Amplitude

0.5

0.4

0.3

0.2

0.1

0.5

1.5

2.5

Time (sec)

Figure 8: Step Response for Actual Motor

From the graphs shown it can be deduced that the system with no controller and open loop is
only capable of getting a zero percentage of overshoot as well as 1.3 s of 2% settling time. This
is not the desired system and as such PI control methods must be inplemented in order to get the
desired parameters which are:
5% overshoot
0.2s 2% settling time

Determination of key motor parameters and justification of design


The Key motor parameters can be justified by the target cost and performance of the motor
under different conditions to achieve the desired specifications. We know that the speed of the
motor which is determined by the rate at which the shaft spins depend on the load specifications.
60

Without load conditions the motor performs optimally and can have a speed range from 0 to
9999 rpm. At this speed the motor, is 100% efficient and the power consumed by the circuit is at
a maximum. To reduce the power consumption we need to reduce the current flowing through
the circuit. The transistor driver circuit reduces the collector current, I c so that power is reduced.
With load conditions the motor initially slow down and ramps back up to a speed within the 09999 range. The maximum speed that can be achieved with load is 7560 rpm. This speed the
motor was only 75.6% efficient but was capable of handling the maximum load without any
problems. Power required by the circuit was less than the one with load. Hardware equipment
costs were taken into consideration when designing the motor as well as the code. The system
was built so that at the minimum cost practices we were able to have a good performance of the
motor. Extra hardware such a resistors and transistors was used to drive the motor in a driver
circuit. Values for the motor were taken directly from the specification sheets and the motor
model was derived using these values. As stated in the controls lab, the motor torque constant
was assumed to be equivalent to the back emf i.e. Ka = Kb.

Design Consideration
Control, Measurement and display of the measured speed
PI Control Specifications
The most common approach is to combine both proportional and
integral terms to form a PI Controller. In this algorithm it can achieve optimal
performance for low order system and for complicated systems a reasonable
good performance for more complicated systems only if the specifications
are justifiable. For this type of control strategy there should be an integrator
in the forward loop of the cascaded controller and plant as illustrated in the
diagram below. This ensures perfect regulation and set point control if the
closed loop system is stable. If the system is stable there is no assurance of
a good transient response. The basic forms of these controllers are therefore
augmented with other feedback components to facilitate improvements in

61

the quality of control. The block diagram below shows the PI control structure
of the motor with the integrator in the forward loop.

Figure 9: Shows the block diagram for the PI control specifications

The system would be used to drive a car in one direction only. In order to get the maximum
overshoot and the desired settling time to be accurate the following controller configuration
specification must be used. The transfer function of the system can be determined by using the
closed loop gain which is given by:
TF=

G (s )
1+ H ( s ) G ( s )

( K + Ks )( J

Ka

Where G(s) is the numerator which is

eq

La ( s )+ ( J eq Ra + Beq La ) ( s ) + Ra Beq + K a K b

And H(s) = 1

62

Figure 10: Shows the In depth Block diagram of the PI controller with the motor

The mathematical model developed for the motor is given by


M =

Therefore the new transfer function is given by the equation:


Transfer Function=

132(K i + K p s)
s +(132 K p +0.792)s+132. K i
2

Whichis approximately of the form

Transfer function=

A n2
s2 +2 ns+ n2

Desired Specifications are overshoot peak of 5% and a 2% setting time of 0.2 s which is used to
calculate the characteristic equation:
63

cot

5% Overshoot, therefore

Cot=

M P =e

=0

.05

ln 0.05
=0.953

cos =069

A 5% settling time of 0.12 s is desired since a reasonably past response time is desired

t 2 s=

4
4
4
rad
= n=
=
=29
n
t 2 s 0.69 x 0.2
s

2
So s +40.2 s +841 isthe characteristical equation of the system

Comparing both equations


n 2=841=132.3 K i

Therefore= K i =6.36

132 K p + 0.792=4 0 .2

K p=0.298

64

Recall that C ( s ) =

K i + K p s 6.36+0.298 s
=
s
s

This was placed into MATLAB and the following graphs plotted:

Root Locus Editor for Open Loop 1 (OL1)

25
20
15
10

Imag Axis

5
0
-5
-10
-15
-20
-25
-45

-40

-35

-30

-25
-20
Real Axis

-15

-10

-5

Figure 11: Root Locus for Motor with PI control

65

System: Closed Loop r to y


I/O: r to y
Peak amplitude:
1.22
1.4
Overshoot (%): 21.6
At time (sec): 0.0753

Step Response

System: Closed Loop r to y


I/O: r to y
Settling Time (sec): 0.168

1.2

Amplitude

0.8

0.6

0.4

0.2

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

Time (sec)

Figure 12: Step Response for motor with PI Control

From these graphs it can be seen that the settling time is within the desired range but the
overshoot is considerably above the specifications and such the proportional on error system
does not work. This is because of the zero that the PI control introduces into the transfer function
and as such cannot be modeled by the previous transfer function:
A n2
Transfer function= 2
s +2 ns+ n2

It has been decided that in order to get the desired specifications the system will have to be
incorporating the proportional on PV control. The values of Kp and Ki will be he same but the
topology used ensures that the transfer function is an all pole one making it suit the model
66

transfer function better.The proportional on PV system response to a step input shown as


follows:

Root Locus Editor for Open Loop 1 (OL1)

25
20
15
10

Imag Axis

5
0
-5
-10
-15
-20
-25
-40

-35

-30

-25

-20
Real Axis

-15

-10

-5

Figure 13: Motor rot locus with proportional on PV Control Topology

67

Step Response

1.4

System: Closed Loop r to y


I/O: r to y
Peak amplitude: 1.05
Overshoot (%): 5.42
At time (sec): 0.145

1.2

Amplitude

System: Closed Loop r to y


I/O: r to y
Settling Time (sec): 0.207

0.8

0.6

0.4

0.2

0.05

0.1

0.15

0.2

0.25

0.3

Time (sec)

Figure 14: Motor step response with proportional on PV control topology

Choice and use of micro-processor peripheral


There are numerous micro-processor peripherals which can be used with microprocessors.
The following peripherals chosen for different reasons:
PORT C - the main reason for choosing this port is because it can be multiplexed with
several peripherals functions such as UART serial communications, PWM, Compare and
Capture mode as well as the oscillator input/output of the TMR1.
PORT A Port A pins can be multiplexed with analog and analog reference voltage for
the A/D converter. Pin 1 for the reference voltage and pins 2-5 for the cathode of the four
LED displays.

68

PORT E Port E has three pins (RE0/RD/AN5, RE1/WR/AN6, and RE2/CS/AN7) which
can be configured as I/O when the PSPMODE (TRISE<4>) bit is set. PORTE pins can be
multiplexed with analog inputs which are activated by ADCON1).

TMR0 For operation in the counter mode with an internal clock. It has a single
programmable pre-scalar mode which can be can be used to extend the range of
OPTION_REG. TMR0 interrupt is generated when the TMR0 register over-flows from
00 to FF.

TMR2 this timer has both pre-scalar and post-scalar properties and is used in
conjunction with PWM time base to give added flexibility.
A/D converter This peripheral has 8 channels and can be multiplexed with PORT A and
PORT E pins. The 10 bit digital result can be stored in the ADRESH and ADRESL
registers
PWM located on portC and has two PWM outputs. The PWM is set by the PR2 on the
TMR2 module.
USART the USART is one of two serial I/O modules located on the PIC16F877;
configured in two modes to communicate with the transmitter and receiver; use hyper
terminal for communication over the RS232 ; USART is addressable with PORTC

Capture and Compare Mode Has features such as automatic capture of the timer value
when an external input occurs and automatic switching of an external signal when the
timer value matches a pre-set value.

Source: (Radix, Cathy-Ann. Introduction to Micro-Processors 1 Course Lecture notes.


DECE, 2010.6)

69

Pulse Width Modulation (PWM)

Pulse Width Modulation mode (PWM) is a frequency which is used to transmit data as well
as digital to analog conversion practices. The pulse width modulator is used to control speed of
the motor as well as the brightness of the LED display unit in this design project. Therefore it
plays an important role in this design project. The main reason for the use of PWM to control the
DC motor control is so that excessive heat dissipation in the motor in power amplifier can be
avoided. Heat dissipation in the power amplifier results in large heat sinks and forced cooling of
the motor which we want to avoid. The plant to be controlled is a small toy car base assembly,
with a motor inertial load (fan or rotating disc). This is mounted directly onto the armature shaft
so that it would rotate at the armature speed.

70

Figure 15: PWM for the PIC 16F877 chip

A simplified block diagram for pulse width modulation on the PIC16F877 chip is shown
above. The output from the port pins is given by a square wave. The voltage of the square wave
is given by the equation:
V =D V max + (1D ) V min=DV max

Where D=

; T =the period of the square wave=duration of motor


T

For the PIC16F877 microprocessor, the CCPxx generates up 10- bit resolution PWM
output. The RC2 / CCP1 pin located on port C is multiplexed with port C data latch to clear the
TRISC <2> pin to make port C an output and this pin corresponds to PWM1. The RC2 /
TOCS1 / CCP2 pin is multiplexed with the port C data latch to make it an output and this pin
corresponds to PWM2. The pulse width period can be given by the equation below:
PWM period =

{ ( PR 2 )+1 }4TMR 2 PresalarTOSC

The PWM period can be specified by writing to the PR2 register as observed in the block
diagram above. Since the PWM period is given by this equation the PWM frequency is therefore
(1 / PWM period). PWM is associated with the TMR2 module which is as an eight bit timer with
a pre-scalar as well as a post scalar. The TMR2 module is both readable and writable and can be
cleared on any device by the use of the reset command when programmed o the PIC16F877. In
the PWM mode it is commonly used for Time base of the CCP1 and the CCP2 modules.

71

Figure 16: Shows the PWM output from any device

(Source: PIC16F877 Manual)


The PWM duty cycle is given by the equation:
CCPR 1 L :CCP 1CON <5 :4>

PWM duty cycle =

The resolution is given by the equation:

Resolution =

F osc
F pwn

lg

Given a particular PWM frequency, PWM has resolution which is given by the equation
above. Conceptually, if we want to obtain a low speed range with a large duty cycle the
frequency used will be low and the motor will thus have a reduced life cycle. However if use a
high frequency, we can acquire a high speed durability and the product life cycle is expanded
with an improved performance since the fans on the DC motor requires a high speed rate to
perform at a optimal rate. Taking this into consideration we will require a high resolution so that
72

the full 10 bits of the register is required, therefore from the PIC manual on page 62 we select the
following bits of information:
Therefore=TMR 2 prescalar =1

PR2=0 xFFh

PWM frequency =19.53 KHz

With the use of the Registers CCP1CON 00xx1100, where xx can be either high or low,
we can set the 10 bit resolution using CCP1CON 4bit and CCPR1L 8 bit registers. The MSB of
the 10 bit resolution should be set to the duty cycle. It is important to note the CCP2CON
register will trigger an A/D bit therefore for the purpose of this design it is not used because we
do not want to trigger the A/D module. Let the PIC16F877 be powered up with a 7 Voltage
supply, therefore the maximum duty cycle:

PWM Period =

256411
=0.000025650
40000000

PWM Duty Cycle =

10231
1=0.000025575
4000000

Duty Cycle, D % =

0.000025575
x 100=99.7076
0.000025650

Therefore ,V =11.988 V

Now the minimum duty cycle =

1x

1
=0.000000025
40000000
73

D=

0.000000025
x 100=0.0972665
0.000025650

Position / Speed of the Motor

Figure 17: Show the diagram of the motor with the controller used for position / speed of the motor

Originally the output from the programmed PIC and the motor would be the position of
the motor. But cannot measure the position of the motor therefore we needed to convert the
position to the speed of the motor which is achieved by the above diagram. The measurement of
the motor speed is done by measuring the rotational speed of the motor using a photo-transistor
optical interrupter switch and an interrupter disc. The photo transistor optical interrupter switch
is designed to indicate the presence or absence of voltage which has been placed in the emitter to
detector path. The interrupter disc is divided such that one half of the disc is white and the other
half of the disc is black. The disc has eight holes and eight areas of darkness. By rotating the disc
the amount of light passing through the photo-transistor also changes and this results in a change
in the current emitted by the photo-transistor. Under normal conditions, we check to see if the
hole is unblocked by taking the position signal generated and providing positive feedback with a
unity gain of one, and checking the error signal between the set point and the Variable algorithm
to see if they correspond to each other. The PIC manipulates the signal and if the signal is correct
74

the LED will light up, which causes a photo current to be developed in the circuit and the speed
of the motor would be displayed on the LED bars. If however there is a fault in the signal
transmitted, the PIC will indicate to the LED that something is incorrect, the LED would not
light causing the photo transistor switch to be turned off and no speed will be displayed on the
LED unit. This would indicate that no voltage was detected so the hole was closed. Using the
information from figure five of the data sheet, and the 5V allocated for the PIC power
If=

75
at V cc =5 V normalized R=2.5 K
Rl

Therefore a current of 30 mA needed in the phototransistor switch. To limit the current


flowing through the circuit we use this value of current and the voltage drop across the diode to
find a suitable resistor value. Assuming that the voltage drop across the diode is 0.70V, the
resistance is given by:
R=

V cc0.7 50.7
=
=143.333
0.03
0.03

The resistor value determined above was not available in stores. The closest value which
was 150

was selected. To determine the rotation rate of the motor, the micro-controller only

has to count the number of pulses per specific time. The disc used is divided equally into two
sections; eight unblocked holes and eight blocked holes. Therefore we would have approximately
eight pulses per revolution.

Display of the Speed


The LED display is used to display the speed of the motor which is measured by
measuring the number of duty cycles in the photo transistor. Depending on the speed of the
motor, we can display the values on the LED.
75

Figure 18: Shows the LED display unit used

The can display speed from 0 to 9999 depending on the load of the motor and the pulse
width modulation of the motor. Under no load conditions the motor rotates at full speed and the
speed being displayed is a maximum. When a load is applied to the motor the speed is reduced
initially and then increases but not to the same speed as previously acquired. By using PWM the
speed of the motor is determined and displayed on the LED segment. The configurations for the
different numbers being displayed from MSB to LSB (RD7 to RD0) is shown in the table below.
Character

Code Using Micro-Processors lab 4 circuit

01111110

00110000

01101101

01111001

01110011

01011011

01011111

01110000

01111111
76

01110011

10000000

Table 3: Shows the values characters that could be displayed on the LED display unit

Techniques for driving the Motor


There are numerous techniques which can be used to drive the motor. We will explore the
techniques of using a MOSFET or a transistor to drive the motor. In the first case DC motor
controllers using MOSFET devices can be used in speed control and servo applications to
provide outstanding drive performance. The advantages of using MOSET devices are
1. Switching Performance MOSFET devices have very fast switching performance. This
is due to the fact that the MOSFET is a majority carrier device. The MOSFET
therefore has no minority carriers to be moved in or out of the devices when it switches
from on to off respectively. At higher switching speeds, the switching loss as well as the
device on state loss becomes very important.
2. Simple Gate Drive Requirements The gate drive circuits required to switch the devices
are relatively low power circuits. They also have good overload capability and safe
operating area which make them easy to use.
3. Ease of use the MOSFET devices are also Voltage driven switches therefore gate drive
circuits are easy to use. During the switching process the gate drive provides a current to
charge and discharge the capacitance of the devices. For quick switching of the gate
driver must be able to source and sink currents up to 1A. The MOSFET can be switched
using a resistive drive and some gate source over-voltage.
4. Paralleling of the MOSFET MOSFETS tend to have a positive temperature co-efficient
and therefore tend to share the total current equally. By connecting the MOSFET devices
in parallel higher currents can be achieved than using just one MOSFET.
5. Higher Switching Frequencies - Using higher switching frequencies reduces the need for
additional discrete inductances in the motor circuit whilst still achieving low ripple

77

currents in separately excited, permanent magnet and series connected field wound
motors.
The second method for driving the motor is the use of a bipolar transistor device.

Figure 14: Transistor switch circuit.


Source: http://webpages.ursinus.edu
Bi polar Transistors have the following qualities which make them suitable for driving motors;
1. On resistance Bipolar transistors unlike MOSFETs have a good on resistance feature
which depends on the current available.
2. Speed Linear switch: very fast saturated switch: moderate
3. Drive Power they tend to have moderate drive power. However they can achieve high
drive power by using a higher collector current and a low forced gain
4. Temperature Stability Bipolar transistors have excellent temperature stability. At the
base voltage it operates at 2mV per C
5. ESD sensitivity they are very rugged in nature.
For my design, we used a transistor with a resistor in a driving circuit with current cut-off
protection.
Choose

But

I c =1 A

I c = Rb where was determined t o be a 100 the data sheet


78

Therefore

R b=

Ic
1
=
=10 mA
100

To find Ra
Recall that V =IR c

Therefore

R c=

V 5
= mA=510
I 10

For current cut off circuitry a 1A fuse was inserted into the circuit to test for current sensing.
Units and the Nature of Set Point
Set point control is widely used in industries to establish perfect steady
state tracking. The main problem however is that it requires that the control
system be designed so that the steady state error to step reference and step
disturbance is zero. In order to achieve perfect steady state tracking of
constant input of a system:
1.

If the "plant" has at least one integrator (i.e. at least one pole at the
origin), then the required controller should at the very least provide for
output that is proportional to the error (Proportional (P) Control) i.e. f =
Kp e(t).

2. If the "plant" has no integrator (i.e. no pole at the origin), then the
required controller should at the very least provide for output that is
proportional to the integral of the error (Integral (I) Control) e.g. f =
Kie (t)dt
79

Source: Copeland, Brian. ECNG Laboratory and Project Design III, lab 2: DC Motor Speed
and Position Control. DECE, 2009.
The Unit of the set point will be the unit of what is being imputed into
the PIC. In our design the signal which was generated from the receiver was
a square wave which outputted a peak to peak voltage. Since the unit of the
signal into the PIC16F877 was voltage the unit of set-point was Voltage, V.

80

RESULTS AND ANALYSIS


Communications Section
Due to time constraints the communications section of the project could not have been attempted
in time for the submission of this report. Research was done into the Bluetooth module and it
was confirmed that the USART peripheral on the PIC 16F877 could have been used to achieve
the remote control aspect of the project. A conceptual design however is shown in the discussion
since it is still intended to be implemented in the final design.

Analog Section
Motor
The motor was assembled with great ease and when tested without the driver circuit and
the current limitation circuit the motor which spinned very fast. The driver circuit was used to
drive the motor so that it operated efficiently at the maximum speed possible. At no load speed
the motor operated within the range of 0 9999 RPM and was 100% efficient. At load speed the
motor operated within the range of 0 7560 RPM and was only 75.6 % efficient. The motor
operated within the range of 3 - 12V and could operate up to a maximum current of 2.48A.
Driver Circuit and Current Sensing
The Driver circuit was built with a transistor and some resistor and incorporated current
sensing and cu-off to drive the motor at a considerable power. They achieve a high drive power
by using a high collector current with a low forced gain. The driver circuit worked in
collaboration with the 1A fuse to provide current limitation for currents that exceeded 1A. The
fused cut-of the current at 1A and the fuse blow out making a short circuit so that current
limitation is achieved

81

Display Unit
The display unit was tested without the PIC16F877 chip in the presence of the laboratory
technician and each LED bar lighted up by testing each segment. We tested the ability of the the
LED display to display numbers. The number 5 was asked to be displayed on a single LED bar.
Also the number was multiplexed by passing the wire across the connection of pins 2-5 of the
LED.

Controls

The controls section of the code was implemented by using speed control, PI control and Display
unit code which were included in the appendix. The code was complied together and simulated
on the MPLAB IDE v7.6 and a code walk through was initiated to ensure that the code did what
it was expected to do without downloading it onto the PIC16F877 chip. The code gave some
errors and as such a fully functional system was not realised. The process of trouble-shooting and
debugging still continues.

82

DISCUSSION

The design of the remote PI controlled DC motor using a PIC16F877 was constructed by
building the individual sections of the design, testing each section and the then interfacing the
system to ensure that the system worked according to the design specifications. In order to
understand how the system works we need to thoroughly investigate the operation of the
complete system built. The system can be broken down into atransmitter and receiver, a PIC
16F877 chip which the PI control is programmed on, a DC motor, a driver circuit, load and the
phototransistor/ interrupt Disc. The transmitter circuit used in the design is able to transmit
analog signals as well as digital signals. The transmitter connected via the computer to the
USART module. Basically this the USART module is one of the two Input/output serial which is
located on the PIC chip and it is usually configured as full duplex mode or half duplex mode in
order to communicate with other devices. Taking this into consideration the transmitter is then
connected to a 9 pin RS232. The set-point data of the controller would be transmitted as the input
signal from the 9-pin RS232. Input signals into the computer may be in the form of a square,
sinusoidal wave or a triangular waveform. The computer then utilizes the USART serial
communication device with a programme known as the Hyper Terminal. By doing this the
USART does physical communication via the RS232 pin.
At the other end is the receiver obtains the output from the transmitter, filters out the
signal wanted from the unwanted signal, amplifies the signal to the desired level required and
then demodulate the signal that is desired. The receiver accepts all the different forms of analog
signals that is sent via the transmitter and outputs a square wave. This is most applicable with
digital signal. The receiver is connected to the receiving pin on the PIC16F877 chip. The output
signal will be transmitted via this connection.
Since this is an analog system the system would take in analog values and then transmit it
the controller module which would then use the analog signal. The signal is sent to the
PIC16F877 chip, which is programmed in assembly code for the speed of the motor, the PI
83

control, pulse width modulation, A/D converter system and a display unit. Using the A/D
converter algorithm will accept the signal from the receiver, and attempt to convert the signal
from analog to digital format. The analog value is stored in a capacitor and then the value is
converted to ten bits. The result is then stored in the ADRESH and the ADRESL registers which
are both 8 bits wide. Therefore 16 bits is available to store the data. The ADRESH could store
the first eight bits and the ADRESL could store the other 2 bits or either the ADRESL could store
the first eight bit and ADRESH could store the other two bits. It doesnt matter which of the
address bits store the most amount of bit but however that all the bits are stores in the registers
available. How the bits are stored in the registers can be accounted for by the ADCON0 and the
ADCON1 control bits.
The pulse width modulation technique is then used to convert the digital signal back to
analog without using an A/D converter. The PIC16F877 chip has a PWM module which is
located on port C of the chip. There are two outputs which are PWM1 and PWM2 respectively
and these correspond to the registers CCPR1L and CCPR2L respectively. The period of the
PWM is set by setting the CCPR1L register moving from the banks to set the period and then
switching back to bank zero. The CCP1CON register is used to set the duty cycle of the pulse. In
this part the PWM is achieved by outputting a square wave with a fixed frequency. We can
change the width of the pulse outputted from the PWM module by the number of pulses per
period. This leads to the voltage or duty cycle of the pulse which changes with the width of the
pulse generated.
A square wave is then sent to the motor which is controlled by the Proportional Integral
control which is implemented on the PIC16F877 micro-processor chip. The motor is driven by a
driver circuit which consist of a simple transistor and a resistor element. If the motor speed
increases the Speed Increase routine will determine the number which needs to be stored in the
CCPR1H register and set the PWM duty cycle to account for the increase in speed. If however
the motor speed decreases, the Speed decrease routine will determine the number which needs to
be stored in the CCPR1L register and set the PWM duty cycle to account for this decrease in
speed.

84

Speed of the motor cannot directly be measured at the output of the configuration.
Therefore we include a phototransistor switch and an interrupter disc into the circuit to sample
the position of the shaft in order to determine the speed of the motor. The phototransistor
operates in the presence of light, and the reference voltage is measured by the interrupter disc.
By taking the position signal generated and providing positive feedback with a unity gain of one,
and checking the error signal between the set point and the Variable algorithm to see if they
correspond to each other. The PIC manipulates the signal and if the signal is correct the LED will
light up, which causes a photo current to be developed in the circuit and the speed of the motor
would be displayed on the LED bars. If however there is a fault in the signal transmitted, the PIC
will indicate to the LED that something is incorrect, the LED would not light causing the photo
transistor switch to be turned off and no speed will be displayed on the LED unit.
The transmitter and the receiver circuit worked as expected being able to maintain a
wireless communication range of 1m and provided an output of a perfect square wave from the
receiver to the PIC16F877 chip. The signal that was sent into the transmitter module could have
been square, triangle or sinusoidal waveforms. The wave would then be modulated and amplified
when pass through the circuit. The output wave from the receiver was passed through a Schmitt
trigger to remove any noise present and generate the perfect square wave of 8V peak to peak. At
first trial in the laboratory there were some problem with both the receiver and the transmitter
circuit. The wave being observed on the screen of the oscilloscope was distorted and seemed to
contain a lot of noise. The source of this disturbance could have been due to the air condition unit
system. With the assistance of the TA Mark Lesley, the circuit was trouble shooted and the
system was tweaked until we observed what was expected on the oscilloscope. The receiver was
revised when it was found out that most of the students system didnt work. This circuit was also
trouble shoot and tweaked until the design worked as expected outputting a square wave on the
screen of the oscilloscope.
The analog section with the motor and the driving circuit also worked as expected. The
system was designed in such a way to limit the current of the circuit although the motor is being
driven at a maximum speed. There were a few considerations when designing the system. Firstly
the transistor and the resistor network must be capable of driving the motor to obtain maximum
85

performance. Secondly since the motor would be operating at high speeds, to limit the current of
the circuit when 1A is breached a 1A fuse was inserted into the circuit. Although this didnt
provide current sensing it ensured that the circuit is short circuited when 1A is reached, providing
protection of the motor. However, steps will be taken to implementing a current sensing circuit
before the practical examination.
The Display was built with the four LED in parallel with access to the same resistor pack.
The main purpose of the resistor pack was to limit the current flowing through the LED which
could only handle up to 25mA. The common cathode of the LED bar was connected to the base
of the transistor and the resistor was connected to the collector of the transistor. The reason for
this connection was due to the fact that the PIC16F877 chip could also only handle currents up to
25mA. By placing the LED bars in parallel each of them will acquire the same current and thus
smaller current will pass through the circuit. The system was tested without the PIC16F877 and
the system was checked by the technician before powering up. A diode was placed between the
positive and the negative terminal so that if any high current were to pass through it would hit the
diode before going to the PIC causing the diode to switch off. The Display worked as expected
and we were able to display numbers as well as see each segment on each LED bar light up. By
touching the wire to the cathode connected to the PIC configuration we established multiplexing.
When checked initially there was a few bad connections, which was pointed out. These were
changed before the design was tested.
The PI control, speed control, and the display code was completed and integrated
together. The code when first compiled generated numerous errors. By stepping through the
code, and rebuilding the code on every step the errors were reduced but still were preventing the
system from fully functioning. The code was successfully complied and steps through to see if
the code operated in the way it was designed to do which is where it was realised that there were
some errors in what was actually being done which then required an analysis of the algorithm for
the code. Due to time constraints the code was not downloaded onto the entire system. The code
which was complied is included in the appendix.
Time for completion of this project was inadequate. If more time was given, in
accordance to the work load of the course, we would have completely implemented the full
86

design and generate the required results that was necessary. The project turned out to be both
enjoyable and challenging and unfortunately it has not been completed as yet. Steps will be
taken to counteract all problems still proceeding with the completion of the project. From this
point my plan is to fully integrate the system and have it fully functional by the practical
examination.

87

CONCLUSION

A remote PI controlled DC motor using a PIC16F877 chip designed with current sensing
cut-off circuitry and wireless communication range of 1m was successfully built, integrated and
tested according to the requirement specifications, cost management practices, performance and
standards and safety practices. Students were able to become more competent with soldering
practices, the PIC16F877 micro-chip, the use of MATLAB 7.0.1 and MPLAB IDE v7.60 as this
would be beneficial when doing final project in year. Students were also exposed to PI control as
applied to real world applications such as the DC motor. Due to time constraints and poor time
management practices, results for the entire design were not accumulated. However, tests were
done on the separate sections to determine the extent to which they worked. The motor operated
in the range of 3-12V with a maximum current of 2.48 and when the current breached 1A the
current cut off limited the current. The display unit was tested without the PIC16F877 chip in
the presence of the laboratory technician and each LED bar lighted up by testing each segment.
The number 5 was then demonstrated and multiplexing of the LEDs was also shown. The
PIC16F877 chip was programmed with a combination PI control, speed control and display
code. Although there were many discrepancies, which lead to problems in the design,
justifications for these were discussed and steps will be taken to fix the problem so that the
system can perform as expected for the practical examination. Overall this design project was a
success and skills learnt will prove to be a great asset for future projects.

88

REFERENCES
Books and publications:

Copeland, Brian. Control System 1 Course Notes. DECE, 2009.


Adams, Richelle. Communications System 1 Course Lecture notes. DECE, 2009.

Joshi, Ajay. Introduction to Micro-Processors 1 Course Lecture notes. DECE, 2009.6

Lutchman, Alvin. Electromechanical Machines Course lecture notes. DECE, 2009.

Occupational Safety and Health Act of Trinidad and Tobago, 2004. Accessed April 19th, 2009.2

ANSI / NEMA ICS 61800-1 standards for Adjustable Speed Electrical Power Drive Systems
2002 3

Canadian Centre. Occupational Health and Safety Act, 2004 standards. OSHA, Accessed 19th
April, 2009. 4

Sankar, Malissa. Risk Assessment Section of the Design and Construction of a Series Pass
Voltage Regulator project .5 DECE, 2008

Maiocchi, G. AN281 Application Note for Driving DC motors. STMicroelectronics Group of


Companies. Accessed April 10th, 2009
89

Sukumar, Kamalasadan A PID Controller for Real time DC Motor Speed Control Using the
C505C Microcontroller. DECE , West Florida. Accessed 15th April 2009.

Copeland, Brian. ECNG Laboratory and Project Design III, lab 1: DC Motor Static and
Dynamic Characteristics. DECE, 2009.

Copeland, Brian. ECNG Laboratory and Project Design III, lab 2: DC Motor Speed and
Position Control. DECE, 2009.

Adams, Richelle. ECNG laboratory and Project Design III, lab 4: AM Transmitter/ Receiver.
DECE, 2009.

Carruthers, Jeffery B. Wiley Encyclopedia of Telecommunications- Wireless Infra-red


Telecommunications. DECE, Boston University, Boston, 2009.

Microchip PIC16F87X Data Sheet, 2001, Microchip Technology Incorporated, Printed in the
U.S.A.

Websites:

http:// www.boondog.com
http:// www.fairchildsemi.com
http:// www.google.com
http:// www.howstuffworks.com
90

http:// www.everlight.com
http:// www.manntel.com
http:// www.robocup.com
http:// www.fira.net
http:// www.microchip.com.motor
http:// www.wikipedia.org
http:// www.datasheets.com
http:// www.national.com

91

APPENDIX 1
Code for the PI control, Display unit and the speed control

LIST p=16f877
INCLUDE

<p16F877.inc>

__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _LVP_OFF

speed

EQU

0x08

;Reference speed (5x8/256=0.156V)

change

EQU

0x01

;Change value (2mV/ms)

LED

EQU

0x20

;LED control data save area

spseed

EQU

0x21

delayCnt

EQU

0x22

proportional_lo

EQU

0x23

proportional_hi

EQU

0x24

integral_hi

EQU

0x27

integral_lo

EQU

0x28

integralsum_hi

EQU

0x29

integralsum_lo

EQU

0x30

volt_hi

EQU

0x31

volt_lo

EQU

0x32

Display0

EQU

0x33

;Least significant bit


92

Display1

EQU

0x34

Display2

EQU

0x35

Display3

EQU

0x36

Display_Act

EQU

0x37

go

EQU

0x38

divisionCount

EQU

0x39

divisor

EQU

0x40

dividend_lo

EQU

0x41

dividend_hi

EQU

0x42

RPS

EQU

0x43

spspeed

EQU

0x44

voltage

EQU

0x45

voltage_hi

EQU

0x46

voltage_lo

EQU

0x47

speederr

EQU

0x48

M1

EQU

0x49

RPO

EQU

0x50

mult_hi

EQU

0x51

mult_lo

EQU

0x52

int

EQU

0x53

; Most Significant Digit

ORG 0x00 ;Reset Vector


goto

init
93

ORG

0x04

;Interrupt Vector

ORG

0x20

;start main program here

goto

main

;======================================================
;**************** Initial Process *********************
;======================================================
init
;============================
;*** Port initialization*****
;============================

bsf

STATUS,RPO

; Change to Bank1

movlw

b'00000001'

; AN0 to input mode

movwf

TRISA

; Set TRISA register

BANKSEL

TRISB

; Set TRISB to output mode

clrf

TRISC

; Set TRISC to output mode

bcf

STATUS,RP0 ; Change to Bank0

;===================================
;*** A/D converter initialization***
;===================================

94

movlw

b'10000001'

;ADCS=10 CHS=AN0 ADON=ON

movwf

ADCON0

;Set ADCON0 register

bsf

STATUS,RP0 ;Change to Bank1

movlw

b'00001110'

movwf

ADCON1

bcf

STATUS,RP0 ;Change to Bank0

;Set ADCON1 register

;====================================
;*** PWM initialization**********
;====================================

clrf

TMR2

;Clear TMR2 register

movlw

b'11111111'

;Max duty (low speed)

movwf

CCPR1L

;Set CCPR1L register

bsf

STATUS,RP0 ;Change to Bank1

movlw

d'255'

;Period=1638.4usec(610Hz)

movwf

PR2

;Set PR2 register

bcf

STATUS,RP0 ;Change to Bank0

movlw

b'00000110'

movwf

T2CON

movlw

b'00001100'

movwf

CCP1CON

;Pst=1:1 TMR2=ON Pre=1:16


;Set T2CON register
;CCP1XY=0 CCP1M=1100(PWM)
;Set CCP1CON register

95

;===========================================
;*** Compare mode initialization*********
;===========================================

clrf

TMR1H

;Clear TMR1H register

clrf

TMR1L

;Clear TMR1L register

movlw

h'61'

;H'61A8'=25000

movwf

CCPR2H

;Set CCPR2H register

movlw

h'a8'

;25000*0.4usec = 10msec

movwf

CCPR2H

;Set CCPR2L register

movlw

b'00000001'

movwf

T1CON

;Set T1CON register

movlw

b'00001011'

;CCP2M=1011(Compare)

movwf

CCP2CON

;Set CCP2CON register

;=======================================================
;*** Interruption initialzation****************************
;=======================================================

bsf

STATUS,RP0 ;Change to Bank1

movlw

b'00000001'

;CCP2IE=Enable

movwf

PIE2

;Set PIE2 register

bcf

STATUS,RP0 ;Change to Bank0


96

movlw

b'11000000'

;GIE=ON PEIE=ON

movwf

INTCON

;Set INTCON register

wait
goto

main_loop

;Interruption wait

;===============================================================
;********** The Display unit Routine***************************
;===============================================================

main

call

cnfg_7segment

call

cnfg_pwm_usart

;call cnfg port A & D for display ;

nop
BANKSEL

Display_Act

clrf

Display_Act

;clears Display_Act

;
=====================================================================
===============
;************Main loop test the load to allow appropriate data to PORTD**************
;
=====================================================================
===============
main_loop
BANKSEL

PORTD

movlw

B'00000000'
97

xorwf

Display_Act,W

;moves Display_Act into the W

btfsc

STATUS,Z

; checks the status of the carry bit

goto

DisplaySet0

movlw

B'00000001'

xorwf

Display_Act,W

btfsc

STATUS,Z

goto

DisplaySet1

movlw

B'00000010'

xorwf

Display_Act,W

btfsc

STATUS,Z

goto

DisplaySet2

movlw

B'00000011'

xorwf

Display_Act,W

btfsc

STATUS,Z

goto

DisplaySet3

;====================================================================
;********************end of tests to load appropriate data*********************
;******* Selection of the Port for controlling the display*********************
;====================================================================
DisplaySet0

movf

Display0,W
goto

DisplaySet1

movf

main_loopRes
Display1,W
98

goto
DisplaySet2

movf

Display2,W
goto

DisplaySet3

main_loopRes

movf

main_loopRes
Display3,W

goto

main_loopRes

;=======================================
;************ main_loop**************
;=======================================
main_loopRes

call

lookup_numbers

movwf

PORTD

BANKSEL

PORTA

movf

Display_Act,W

andlw

b'00000011'

;selects port A to control Display active

; the first 2 bits for counting

purposes
call
lookup_DisplayUnit ;calls lookup_DisplayUnit to convert
DispActive value to an appropriate value
movwf

PORTA

call

delay5ms

movlw

B'00000011'

xorwf

Display_Act,W

btfsc

STATUS,Z

call

DisplayRes

incf

Display_Act,F
99

goto

main_loop

BANKSEL

TRISD

;selects port D

clrf

TRISD

;sets port D as output

BANKSEL

TRISA

;selects port A

clrf

TRISA

;sets port A as output

BANKSEL

Display0

clrf

Display0

clrf

Display1

clrf

Display2

clrf

Display3

cnfg_7segment

return
;
=====================================================================
==========
;*******Configuration of the Pulse width Modulation with the USART routine*****
;
=====================================================================
===========
cnfg_PWM_USART
BANKSEL

TRISC

movlw
B'10000000'
receive, RC6 as transmit and RC2 as PWM output

;selects port C
;sets pattern for RC7 as

100

movwf

TRISC

; bit pattern into TRISC

BANKSEL

CCP1CON

;selects bank with CCP1CON

movlw

B'00001100'

;sets pattern for PWM used

movwf

CCP1CON

;sets pattern into CCP1CON

BANKSEL

PR2

;selects bank with PR2

B'00111111'

;0x3F sets pattern for 8bit

movwf

PR2

;sets pattern into PR2

BANKSEL

T2CON

;selects bank with T2CON

movlw

B'00000100'

;sets bit pattern to enable

movwf

T2CON

;sets bit pattern

BANKSEL

CCPR1L

;selects duty cycle controlling

movlw
resolution with high frequency

timer and have prescaler = 1

register
clrf

CCPR1L

;clears it just in case

return

cnfg_Speed
BANKSEL

OPTION_REG

;selects bank with

OPTION_REG
movlw
B'11100010'
;disable pullups on B, set
interrupt on rising, use external for TMR0, increment on rising, use 1:8
movwf

OPTION_REG

BANKSEL

INTCON

;selects bank with INTCON

B'10110000'

;enable external interrupt,

movlw
overflow interrupt and global interrupt

101

movwf

INTCON

return
DisplayRes
movlw

0xFF

movwf

Display_Act

return

;
=====================================================================
=
;***********convert binary to BCD**************************************

; ********************* Mathematical operation carried out*************


;
=====================================================================
=
divide_16by8

divide_16by8_loop

divide_16by8_quotient

movlw

0x09

movwf

divisionCount

movf

divisor,W

subwf

dividend_hi,F

btfsc

STATUS,C

goto

divide_16by8_quotient

addwf

dividend_hi,F

bcf

STATUS,C

rlf

dividend_lo,F
102

rlf

dividend_hi,F

decfsz

divisionCount,F

goto

divide_16by8_loop

bcf

STATUS,C

rrf

dividend_hi,F ;return MSB of quotient in carry on

exit
return ;return with quotient in dividend_lo and
remainder in dividend_hi

;===================================================================
;***************************delays used for mux & sampling**********
;===================================================================

delay1ms
BANKSEL

OPTION_REG

;selects OPTION_REG bank

movlw

b'00000001'

;TOCS = 0, prescalar = 1:4

movwf

OPTION_REG

;sets parameters

bcf

INTCON,T0IF

;clear flag so no overflow

BANKSEL

TMR0

clrf

TMR0

BANKSEL

OPTION_REG

bcf

OPTION_REG,T0CS ;start timing

bcf

STATUS,RP0

delay1ms_loop
103

btfss

INTCON,T0IF

;checks for overflow, if

goto

delay1ms_loop

BANKSEL

OPTION_REG

bsf

OPTION_REG,T0CS ;stops timing

bcf

STATUS,RP0

overflow, then 1ms

return
delay5ms
movlw

.5

movwf

delayCnt

call

delay1ms

decfsz

delayCnt,F

goto

delay5ms_loop

delay5ms_loop

return
;============================================================
;********************Lookup table for the display unit*****
;=============================================================
lookup_numbers
addwf

PCL,F

retlw

0x3F

; bit pattern for 0

retlw

0x06

; bit pattern for 1

retlw

0x5B

; bit pattern for 2


104

retlw

0x4F

; bit pattern for 3

retlw

0x66

; bit pattern for 4

retlw

0x6D

; bit pattern for 5

retlw

0x7D

; bit pattern for 6

retlw

0x07

; bit pattern for 7

retlw

0x7F

; bit pattern for 8

retlw

0x6F

; bit pattern for 9

addwf

PCL,F

retlw

0x0E

;select least significant digit 0

retlw

0x0D

;select digit 1

retlw

0x0B

;select digit 2

retlw

0x07

;select digit 3

lookup_DisplayUnit

;=======================================================
;*************** Interruption Process *****************
;========================================================
int
105

clrf

PIR2

;Clear interruption flag

btfsc

ADCON0,go ;A/D convert

goto

ad_check

;No. Again

movfw

ADRESH

;Read ADRESH register

sublw

speed

;Ref speed - Detect speed

btfsc

STATUS,C

;Reference < Detect

goto

PICntrl

ad_check

;====================================================================
;PICnrtl routine functions to find the proper implementation of PI control
;====================================================================

PICntrl
movf

RPS,W

subwf spspeed,W

; Speed of the rotor(RPS)


; W = spsspeed - RPS. ; sps = set point speed

btfsc STATUS,C
; negative answer,carry is generated and a
decrease in speed required;positive anwser, no carry generated and an increase in speed is needed
call

SpeedDecr

; rotor speed > setpoint speed therefore a

call

SpeedIncr

; rotor speed < setpoint speed so we need an

decrease in speed
increase in speed

106

;
=====================================================================
======================================================
; The maximum voltage (Hi:lo) will have a value = speederr[2*pi*(Kp) + 2*pi*(Ki)] = 4275
where Kp = 1.038 and Ki = 12.99795
; to full 8 bit register (4275 / 255 = 16.765)
;
=====================================================================
=======================================================

Borrow

Divide_2

clrf

voltage

movlw

.16765

subwf

voltage_lo,F

btfss

STATUS,C

goto

Borrow

goto

Divide_2

movlw

0x01

subwf

voltage_hi,F

btfss

STATUS,C

goto

Borrow

incf

voltage,F

goto

Divide_2

; repeated subtraction of 16.765

; add one and loop again

return

;=================================================
;******** SpeedIncr Routine *****************
107

;=================================================
SpeedIncr
movf

speederr,F

; speederr is the error output from Refspd-

call

proportional

call

integral

movf

integral_lo,W ; move integral_lo into the working register

addwf

integralsum_lo,F ; integralsum_lo = integralsum_lo + W

movf

integral_hi,W

btfsc

STATUS,C

incf

integralsum_hi,F

addwf

integralsum_hi,F

movwf

volt_hi

movf

integralsum_lo,W

movwf

volt_lo

movf

proportional_lo,W

addwf

volt_lo,F

movf

proportional_hi,W

btfsc

STATUS,C

incf

volt_hi,F

RPS

volt16positive

; W = integral_hi

; integralsum_hi = integralsum_hi +

; move proportional_lo into the

working register
; volt_lo = volt_lo + W
; W = proportional_hi

108

addwf

volt_hi,F

; volt_hi = volt_hi + W

return

;====================================================================
;******** SpeedDecr Routine *********************************************
;====================================================================
SpeedDecr
movf

spspeed,W

; move the spspeed into the working

subwf

RPS,W

; W = RPS - spspeed.

call

proportional

call

integral

movf

integral_lo,W

subwf

integralsum_lo,W

movwf

voltage_lo

btfss

STATUS,C

decf

integralsum_hi,F

movf

integral_hi,W

subwf

integralsum_hi,W

movwf

voltage_hi

register

volt16negative

; W = integralsum_lo -

integral_lo

; W = integralsum_hi - integral_hi

109

;===========================================
;******* voltage_(hi:lo) *****
;===========================================

movf

voltage_hi,W

movwf

integralsum_hi

movf

voltage_lo,W

movwf

integralsum_lo

;====================================================================
; *subtraction of the 16-bit number in proportional_hi and proportional_lo, from the 16-bit
number in voltage_lo and voltage_hi****************
; *store result in volt_lo and volt_hi*************************************************
;====================================================================
movf proportional_lo,W
subwf voltage_lo,W
movwf

volt_lo

btfss

STATUS,C

decf

voltage_hi,F

movf

proportional_hi,W

subwf

voltage_hi,W

; W = voltage_lo - proportional_lo

; W = voltage_hi - proportional_hi
110

movwf

volt_hi

return

;====================================================================
;********* Scaling proportional error term***************************
;====================================================================

proportional
movlw
b'10001000'
; use 648 because 2*pi*(Kp=1.0308)
= 6.48, so multiply by 648, which is the term scaled up by 100
movwf

M1

clrf

proportional_hi

clrf

proportional_lo

; clear result location

clrw
Mu8x8

addwf

speederr,W

; add speederr to itself

btfsc

STATUS,C

; if carry set

incf

proportional_hi,F

decfsz

M1,F

goto

Mu8x8

movwf

proportional_lo

return

;===========================================================
111

;******** Scaling of integral error term*******************


;===========================================================
integral
movlw
b'00110000'
so multiply by 816, which is the term scaled up by 10
movwf

mult_lo

movlw

b'00000011'

movwf

mult_hi

clrf

integral_hi

clrf

integral_lo

; use 816 because 2*pi*(Ki=) = 81.6,

; clear the location result

clrw

Loop

call

Add16bit

decfsz

speederr,F

goto

Loop

nop
nop
return

Add16bit

movf

mult_lo,W

addwf

integral_lo,F

movf

mult_hi,W

; move mult_lo into the working register

; move mult_hi into the working register


112

btfsc

STATUS,C

; check the status of the carry bit

incfsz

integral_hi,F ; if high increment integral_hi

addwf

integral_hi,F ; integral_hi = mult_hi + W( = integral_hi)

return

;====================================================================
;************ The PWM routine **********************************************
;====================================================================
PWM
BANKSEL

PR2

movlw

0xFF

movwf

PR2

BANKSEL

T2CON

movlw

b'00000110'

movwf

T2CON

movf

voltage,W

movwf

CCPR1L

return
END

113

Nichibo DC Motor

114

115

Datasheet for Phototransistor Optical Switch

116

117

118

119

120

121

122

You might also like