International Conference on Communication, Control, Computing and Electronics Engineering, 2017
IMPLEMENTATION OF A PID CONTROL
SYSTEM ON MICROCONTROLLER (DC
MOTOR CASE STUDY)
Mohamed Nasreldin M.A.1, Abdalaziz Abdalgfar A.A.2, Ahmed Alfatih A.3, Ahmed Abdelrahman A.A.4
Department of Electrical and Computer Engineering,
Karary University, Omdurman, Sudan
1. mohammedagab95@[Link]
2. 7ebaisha@[Link]
3. ahmadalfatih808@[Link]
4. mogwari2000@[Link]
Abstract ـــthis paper concerns with the design and DC motors are the most commonly used machines in
implementation of a microcontroller based PID controller for the industry because it is simple, rigid and easy to control, the most
purpose of controlling PMDC motor speed. The design have been common control among this type of machine is varying the
done using MATLAB and Simulink and the system then simulated
supply voltage which is easy to manipulate using the will
using Proteus, in addition to a practical physical system. The
known technique pulse width modulation (PWM) with help of
controller was implemented on an Arduino Uno board to control
the speed of the motor at a desired value with the possibility of
fast switching power electronics circuits mostly chopper
changing it and its direction of rotation. The proposed system use circuits which is used to switch dc voltage on and off at very
an optical encoder as feedback sensor of motor speed which is high rate and hence changes the power supplied to the machine
compared with reference speed to produce error signal for the [3]. These traditional methods of controlling the DC machine
controller input, the control signal then sets the PWM duty cycle lacks the efficiency and fast response, therefore to compensate
to change the motor speed which controlled via H-bridge. The this we have to use controllers to achieve stability and better
controller was able to track the input regardless of friction, performance which generally is represented as transient and
disturbance and medium changes of load on motor shaft. Both
steady state response.
implementation and simulation results have been obtained and
This paper aims toward implementing a PID controller on
compared.
a microcontroller board with focusing on control design and
Keywords ــــcontrol; microcontroller; computing; machine analysis of the controller when used to control PMDC motor
control. speed.
The design procedure has taken in account several
I. INTRODUCTION researches related to the subject along with studying system
Nowadays control systems are essential part of our life, they dynamics before designing the control algorithm.
are found in home, office, transports, communication systems This paper organized as follows: Section II contains
and computer systems. theoretical information and related work. Section III describes
In general control systems are classified as classical system design, implementation, software and hardware
control systems and modern control, classical control systems components. Section IV presents experiments and simulation
depends on feedback and transfer function on its operation, results. Section V contains conclusion, recommendation and
while modern controller uses state-space representation, digital future work.
computers, fuzzy logic and neural networks [1].
PID controller is classified as a classical controller but II. LITERATURE REVIEW
also it becomes modern controller when implemented as a code In order to do a control design or analysis we need system
in a control loop. Modern high speed microcomputers and model, in this case our model is the transfer function of
microcontrollers are widely used in digital control systems permanent magnet DC motor. Generally controlling dc motor
because of its efficiency, speed, compactness and reasonable uses armature circuit or excitation circuit, the paper deals with
cost [2]. armature circuit variables, fig.1 represents an armature
controlled permanent magnet dc motor’s equivalent circuit, and
U z
K p 1
T
T
1 z 1 ..........(9)
fig.2 shows the mechanical component.
E z
T i 1 z 1 d
T
Then we can write the last equation as a difference
equation by using inverse Z-transform as follows:
K T
u kT u kT T K p e kT e kT T P e kT
Ti
K PT d
e kT 2e kT T e kT 2T .....(10)
T
Where:
Kp, Ti, Td: represents PID constants.
Fig.1: DC motor equivalent circuit. T: represents sampling time.
Equation (10) is known as velocity form of PID controller
which is suitable for implementation on a control loop because
it provides smooth control and avoids common controller’s
Fig.2: Mechanical variables in DC motor. problems like integral wind-up and derivative kick [5].
Several researches have been made to provide a
It is clear that electrical variables control the mechanical convenient speed control however we took three papers as
ones so we can relate these two sets of variable by applying reference and guide.
circuit laws and motion laws to the following equations: Panduranga Talavaru, Nagaraj Naik R et al. provided a
di closed loop speed and position control using PID controller
ea (t ) R a * i a (t ) La * a v b ..........................(1) implemented on ATmega32 microcontroller, the system used
dt
z *p rotary encoder as speed sensor and PMW technique to set the
vb * w(t) kb w (t )............................(2) motor speed at the desired set point entered via GUI on
2 * A
computer [6].
s 2 J m * (s ) sD m * (s ) T m (s )..........................(3)
The design is simple and compact, however it ignores the
T m k t * I a (s)......................................................(4)
system performance analysis on transient and steady state.
Using Laplace transform on above equations we can get
Sukumar Kamalasadan and Abhiman Hande Designed a
the transfer function that relates the shaft speed to the supply
precise control of speed and direction, the system uses two
voltage as follows:
microcontrollers, the first microcontroller reads the motor
w (s ) 1
.....(5) speed and drives it while the second one calculate the control
E a (s) 2 La Ra La Ra signal, communication between the two microcontrollers was
[(s J e s ( J e De ) ( De K b )]
Kt Kt Kt Kt done using controller area network (CAN) protocol [7].
Where: The proposed system was precise but suffers complexity
2 in choosing a sampling time due to the use of two
N
J e J m J L m ...........................................(6) microcontrollers.
NL Another paper by Petr Dostalek, Libor Pekar et al. show
2 that a self tuning controller can be implemented on
N
De D m D L m ........................................(7) 68HC908GB60 an 8-bits microcontroller manufactured by
NL Freescale which is a part of the development board
The sub letter L denotes load while m denotes motor [4]. M68EVB908GB60 by Axiom Manufacturing, The process is
PID controller uses three terms: proportional, integral and identified using modified recursive least squares method with a
derivative to drive an error signal (e) to zero, equation (8) digital PID controller whose parameters are designed by pole
shows continuous time PID controller transfer function. placement, the paper focused on decreasing the sampling time
U s K that result in better system stability, the controller then used on
K P I K D S ......................................(8)
E s S two heat plants. Paper proofs that low cost 8-bit microcontroller
To implement a PID controller as a code we need to has sufficient arithmetic power to handle adaptive control tasks.
transfer it to a discrete controller and so we used backward
integration on equation (8) to get the following form: III. SYSTEM DESIGN
General PID speed control system is shown in fig.3 system toolbox used to plot system response as well as tuning
below, the controller compares desired speed that represent the the PID controller, fig.5 shows block diagram of the system in
reference with actual speed that represent feedback signal to Simulink program.
calculate error signal which is the input signal of the controller,
then a control signal is calculated based on controller gain and
structure, the control design aims to force the system output to
settle on its reference.
Fig.5: Block diagram of the system in SIMULINK.
The most important part when designing PID controller is
tuning the controller parameters to meet design requirements,
Fig.3: Closed loop PID control system. there is several ways to do this, including: trial and error,
However modern trend today is to implement the Ziegler-Nichols method and computer aided design software
controller digitally using high speed microcontrollers due to [5].
advantages of digital control systems over analog ones Fig.6 shows process of tuning the PID controller gains.
including implementation errors, speed and accuracy.
There are two approaches to design a digital controller:
the first one is emulating analog controller, the second one is
designing the controller in the discrete time domain using Z-
transform techniques, the first approach was followed in our
design. It’s been noticed that when using the first approach the
resulting system will have a damping ratio poorer than the
original one because of the sampling process so we need to tune
controller parameters carefully. Fig.4 below shows the
proposed system, the PID controller was implemented on
Arduino Uno board, and user interface consists of pushbuttons
that used to set the desired speed and direction and LCD display
that shows desired and actual speed.
Fig.6: PID controller tuning.
The resulting system response is then plotted in fig.7.
According to design requirements the response is found to be
satisfying.
The next step is to simulate the designed controller in
Proteus software. To implement a PID controller on a Arduino
Uno board, The 8-bits microcontroller board based
on ATmega328P running on 16MHz quartz crystal has 14
digital input/output pins which provide 6 PWM outputs, 6
analog inputs and a USB connection, providing suitable
Fig.4: Block Diagram of the proposed system.
platform for developing digital controllers, Arduino IDE was
The design requirements are as follows: steady state error
used to write the program code. The main program task is to
less than 5%, rise time less than 2 seconds and settling time less
control motor speed at the desired set point while reading user
than 4 seconds.
requests and monitoring system state on LCD display. The
In our method MATLAB and SIMULINK are used to
output signal of the control loop is converted to a duty cycle of
design the PID controller after building the D.C. motor model
PWM signal that drives the motor.
from transfer function that were discussed earlier, control
Fig.7: Step response of the system after tuning
parameters.
Feedback signal is generated by a custom made rotary
encoder from fc-51 sensor, the encoder outputs pulses as the
motor rotates, those pulse trigger interrupt service in Arduino
Uno which contain a counter that allows us to calculate the
motor speed in revolutions per minute or revolution per Fig.8: Flow chart of the main program.
seconds, pin2 in Arduino Uno triggers INT0 every rising edge
Fig.9 shows Proteus simulation and Fig10. Shows the
of the sensor output.
simulated system response.
The microcontroller compares the reference input with the
feedback signal to produce error signal, the control algorithm
uses the PID velocity form discussed in equation (11) which
runs every sampling interval to produce control signal from
error signal. The control signal then converted to PWM signal
is generate by the microcontroller using built-in library, the
pulse width varies between 0-255. PWM signal drives the
motor with the help of L293D motor driver IC. Fig.8 shows
flow chart of the main program.
Now the system circuit and program is completed and can
be simulated on Proteus, the controller behaved well on
tracking the reference speed as well as overcoming load
Fig.9: Proteus simulation of the proposed system.
changes on motor shaft.
The simulated system response has been plotted using
MATLAB by logging real time system output changes over
time, data array saved to text file via serial communication then
red by MATLAB and plotted.
Simulated system response shows similar behavior to its
counterpart designed earlier, while having more overshoot due
to greater sampling time choice than the one that used to design
the controller in Simulink program in addition to the fact that
D.C. motor is non-linear system while CAD programs like
MATLAB linearizes the system model first before simulating
its response. Fig.10: The simulated system response.
Practical implementation based on same simulation
components and code, except the feedback speed calculations
due to the difference in resolution of practical and simulated
sensors. Fig.11 (a) shows hardware components and fig.11 (b)
shows hardware setup.
implementation. The performance gap between simulation and
implementation can be bridged by using more accurate sensors
and smaller sampling time even if that will lead to hardware
upgrade but the overall system performance will be much
better.
V. CONCLUSION AND FUTURE WORK
This paper represented a detailed way of designing and
Fig.11 (a): Hardware overview. implementing a PID controller on microcontroller.
The proposed controller resulted a good performance in
transient and steady state response, in addition to that the
overall system is simple, easy to modify, has a low power
consumption and small size makes it ideal for the subject.
Practical system was implemented and tested to match
with its simulated counterpart and the comparison was made.
System Performance upgrade includes using faster
microcontroller and more precise speed sensor, Future work
may include developing an auto tune PID controller to adapt
changes in system dynamics and provide better stability.
Fig.11 (b): Hardware setup. REFERENCES
IV. EXPERIMENTS AND RESULTS [1] Katsuhiko Ogata,” Modern Control Engineering”, Fifth
Edition,PrenticeHall, ISBN 13: 978-0-13-615673-4, 2010.
The implemented hardware system is quite similar to the [2] Sami Fadali, “Digital Control Engineering Analysis and Design”,
simulated one, again the performance analysis is important Elsevier Inc., ISBN 13: 978-0-12-374498-2, 2009.
aspect of this design so real time system response has been [3] Muhammad [Link],”Power Electronics Handbook”, Elsevier
Inc., ISBN 10: 0-12-088479-8, 2007.
plotted using MATLAB of logged data via serial monitor tool
[4] Online Presentation,” Modeling of Dynamic system_TF of
available in Arduino IDE, Fig.12: shows the implemented Permanent DC motor”, 2009.
system response. [5] Dogan Ibrahim, “Microcontroller Based Applied Digital Control”,
Wiley & Sons Ltd, ISBN-10 0-470-86335-8, 2006.
The practical system has good performance, but it is less [6] Panduranga Talavaru, Nagaraj Naik R, V. Kishore Kumar Reddy
V,“Microcontroller based closed loop speed and position control of
accurate than the simulated one due to sensor resolution that
DC motor”, International Journal of Engineering and Advanced
leads to choosing higher sampling time which will result in Technology, June 2014.
lagging response and oscillation. [7] Sukumar Kamalasadan and Abhiman Hande, “A PID Controller for
Real-Time DC Motor Speed Control using the C505C
Microcontroller”.
[8] PETR DOSTÁLEK, LIBOR PEKAŘ, VLADIMÍR VAŠEK, JAN
DOLINAY,” Microcontroller based self-tuning digital PID
controller”, LATEST TRENDS on SYSTEMS (Volume I).
[9] Arduino IDE, [Online] (last visited 3-JUN-2016), [Link].
[10] PROTEUS Software [Online] (last visited 10-JUN-2016),
[Link]
[11] Virtual serial port emulator [Online] (last visited 8-JUL-20I6),
[Link]/[Link].
[12] CoolTerm software, [Online] (last visited 8-JUL-2016),
[Link].
Fig.12: The implemented system response.
In every stage of our design, system response was
analyzed so we can compare between simulation and