You are on page 1of 5

2017 International Conference on Communication, Control, Computing and Electronics Engineering (ICCCCEE), Khartoum, Sudan

Implementation of a PID Control System on


Microcontroller (DC Motor Case Study)

Mohamed Nasreldin M.A., Abdalaziz Abdalgfar A.A., Ahmed Alfatih A., Ahmed Abdelrahman A.A.
Karary University
Omdurman, Sudan
mohammedagab95@gmail.com

AbstractThis paper concerns with the design and known technique pulse width modulation (PWM) with help of
implementation of a microcontroller based PID controller for the fast switching power electronics circuits mostly chopper
purpose of controlling PMDC motor speed. The design had been circuits which is used to switch dc voltage on and off at very
done using MATLAB and Simulink and the system then
high rate and hence changes the power supplied to the
simulated using Proteus, in addition to a practical physical
machine [3]. These traditional methods of controlling the DC
system. The controller was implemented on an Arduino Uno
board to control the speed of the motor at a desired value with machine lacks the efficiency and fast response, therefore to
the possibility of changing it and its direction of rotation. The compensate this we have to use controllers to achieve stability
proposed system use an optical encoder as feedback sensor of and better performance which generally is represented as
motor speed which is compared with reference speed to produce transient and steady state response.
error signal for the controller input, the control signal then sets This paper aims toward implementing a PID controller
the PWM duty cycle to change the motor speed which controlled on a microcontroller board with focusing on control design
via H-bridge. The controller was able to track the input and analysis of the controller when used to control PMDC
regardless of friction, disturbance and medium changes of load
motor speed.
on motor shaft. Both implementation and simulation results had
The design procedure has taken in account several
been obtained and compared.
researches related to the subject along with studying system
Keywordscontrol; microcontroller; computing; machine dynamics before designing the control algorithm.
control. This paper organized as follows: Section II contains
theoretical information and related work. Section III describes
I. INTRODUCTION system design, implementation, software and hardware
Nowadays control systems are essential part of our life, components. Section IV presents experiments and simulation
they are found in home, office, transports, communication results. Section V contains conclusion, recommendation and
systems and computer systems. future work.
In general control systems are classified as classical
control systems and modern control, classical control systems II. THEORETICAL BACKGROUND
depends on feedback and transfer function on its operation, In order to do a control design or analysis we need system
while modern controller uses state-space representation, model, in this case our model is the transfer function of
digital computers, fuzzy logic and neural networks [1]. permanent magnet DC motor. Generally controlling dc motor
PID controller is classified as a classical controller but also uses armature circuit or excitation circuit, the paper deals with
it becomes modern controller when implemented as a code in armature circuit variables. Fig. 1 represents an armature
a control loop. Modern high speed microcomputers and controlled permanent magnet dc motors equivalent circuit,
microcontrollers are widely used in digital control systems and Fig. 2 shows the mechanical component.
because of its efficiency, speed, compactness and reasonable It is clear that electrical variables control the mechanical
cost [2]. ones so we can relate these two sets of variable by applying
DC motors are the most commonly used machines in circuit laws and motion laws to get the following equations
industry because it is simple, rigid and easy to control, the (1), (2) and (3).
most common control among this type of machine is varying
the supply voltage which is easy to manipulate using the will

978-1-5090-1809-3/17/$31.00 2017 IEEE


Then we can write the last equation as a difference
equation by using inverse Z-transform as follows:
KT
u ( kT ) = u ( kT T ) + K p e ( kT ) e ( kT T ) + P e ( kT ) +
Ti
K PTd
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
controllers problems like integral wind-up and derivative
Fig. 2. Mechanical variables in DC motor. kick [5].
di a Several researches have been made to provide a
e a (t ) = R a * i a (t ) + La * +v b (1) convenient speed control however we took three papers as
dt
reference and guide.
z *p
vb = * w(t) = kb w (t ) (2) Panduranga Talavaru, Nagaraj Naik R et al. provided a
2 * A
closed loop speed and position control using PID controller
s 2 J m * (s ) + sD m * (s ) = T m (s ) (3) implemented on ATmega32 microcontroller, the system used
T m = k t * I a (s) (4) rotary encoder as speed sensor and PMW technique to set the
motor speed at the desired set point entered via GUI on
Using Laplace transform on above equations we can get computer [6]. The design is simple and compact, however it
the transfer function that relates the shaft speed to the supply ignores the system performance analysis on transient and
voltage as follows: steady state.
w (s) 1 Sukumar Kamalasadan and Abhiman Hande Designed a
= (5)
Ea (s) 2 La R L R precise control of speed and direction, the system uses two
[(s Je +s( a Je + a De ) +( a De +Kb )]
microcontrollers, the first microcontroller reads the motor
Kt Kt Kt Kt
speed and drives it while the second one calculate the control
Where: signal, communication between the two microcontrollers was
2 done using controller area network (CAN) protocol [7]. The
N (6)
Je = J m + J L m proposed system was precise but suffers complexity in
NL choosing a sampling time due to the use of two
2
N microcontrollers.
De = D m + D L m (7) Another paper by Petr Dostalek, Libor Pekar et al. show
NL
that a self tuning controller can be implemented on
The sub letter L denotes load while m denotes motor [4]. 68HC908GB60 an 8-bits microcontroller manufactured by
PID controller uses three terms: proportional, integral and Freescale which is a part of the development board
derivative to drive an error signal (e) to zero, equation (8) M68EVB908GB60 by Axiom Manufacturing, The process is
shows continuous time PID controller transfer function. identified using modified recursive least squares method with
U (s ) K (8) a digital PID controller whose parameters are designed by
= K P + I + K DS
E (s ) S pole placement, the paper focused on decreasing the sampling
To implement a PID controller as a code we need to time that result in better system stability, the controller then
transfer it to a discrete controller and so we used backward used on two heat plants [8]. The last paper proofs that low
integration on equation (8) to get the following form: cost 8-bit microcontroller has sufficient arithmetic power to
handle adaptive control tasks.
U (z ) = K 1 + T +T d
(1 z )
1
(9)
E (z ) T i (1 z 1 )
p
T

III. SYSTEM DESIGN from transfer function that were discussed earlier, control
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 PID controller, Fig. 5 shows block diagram of the system
the reference with actual speed that represent feedback signal in Simulink program.
to 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
Fig. 3 Closed loop PID control system. requirements, there is several ways to do this, including: trial
However modern trend today is to implement the and error, Ziegler-Nichols method and computer aided design
controller digitally using high speed microcontrollers due to software [5]. Fig. 6 shows process of tuning the PID controller
advantages of digital control systems over analog ones 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. Its 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
Fig. 4 Block Diagram of the proposed system. analog inputs and a USB connection, providing suitable
The design requirements are as follows: steady state error platform for developing digital controllers, Arduino IDE was
less than 5%, rise time less than 2 seconds and settling time used to write the program code. The main program task is to
less than 4 seconds. control motor speed at the desired set point while reading user
In our method MATLAB and SIMULINK are used to requests and monitoring system state on LCD display. The
design the PID controller after building the D.C. motor model
output signal of the control loop is converted to a duty cycle
of PWM signal that drives the motor.

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 Fig. 8 Flow chart of the main program.
Uno which contain a counter that allows us to calculate the
Fig. 9 shows Proteus simulation and Fig. 10. Shows the
motor speed in revolutions per minute or revolution per
simulated system response.
seconds, pin2 in Arduino Uno triggers INT0 every rising edge
of the sensor output.
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
Fig. 9 Proteus simulation of the proposed system.
be simulated on Proteus, the controller behaved well on
tracking the reference speed as well as overcoming load
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 Fig. 10 The simulated system response.
programs like MATLAB linearizes the system model first Practical implementation based on same simulation
before simulating its response. 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.
In every stage of our design, system response was
analyzed so we can compare between simulation and
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


Fig. 11.(a) Hardware overview.
This paper represented a detailed way of designing and
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, 5th 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 H.Rashid, Power Electronics Handbook, Elsevier
Inc., ISBN 10: 0-12-088479-8, 2007.
plotted using MATLAB of logged data via serial monitor tool
[4] Norman S.Nise, Control Systems Engineering, 6th Edition, John
available in Arduino IDE, Fig. 12: shows the implemented Wiley & Sons, ISBN 13 978-0470-54756-4, 2011.
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
accurate than the simulated one due to sensor resolution that V,Microcontroller based closed loop speed and position control
of 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 Dostalek, Libor Pekar et al., Microcontroller based
self-tuning digital PID controller, Latest Trends on Systems
(Volume I).
[9] Arduino IDE, [Online] (last visited 3-JUN-2016),
www.arduino.cc.
[10] PROTEUS Software [Online] (last visited 10-JUN-2016),
https://www.labcenter.com/.
[11] Virtual serial port emulator [Online] (last visited 8-JUL-20I6),
www.eterlogic.com/Products.VSPE.html.
[12] CoolTerm software, [Online] (last visited 8-JUL-2016),
www.freeware.the-meiers.org.

Fig. 12 The implemented system response.

You might also like