Real-Time Implementation of Model Predictive Control On A 16-Bit Microcontroller For Speed Control of A DC Motor
Real-Time Implementation of Model Predictive Control On A 16-Bit Microcontroller For Speed Control of A DC Motor
Real-Time Implementation of Model Predictive Control On A 16-Bit Microcontroller For Speed Control of A DC Motor
net/publication/323184966
CITATIONS READS
2 2,647
1 author:
Sohaib Aslam
Superior University
10 PUBLICATIONS 22 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Real time comparison among PID, MPC and Fuzzy Logic control techniques for speed control of a DC motor View project
All content following this page was uploaded by Sohaib Aslam on 15 February 2018.
*Corresponding authors
Abstract: Model Predictive Control (MPC) is an optimization based control technique and handles process
operational constraints more effectively in comparison to Proportional Integral and Derivative Controller
(PID). This paper presents real-time implementation of MPC on a 16-bit PIC microcontroller for speed control
of a DC motor in constrained environment. Although the computational burden of MPC is a key hindrance but
Laguerre functions have been used to reduce the computational burden of classical MPC algorithm and make it
feasible for a simple microcontroller implementation. The simulations of MPC for speed control of a DC motor
are presented in four modes without constraints, with input constraints, with output constraints, and with both
input and output constraints. In all four modes, MPC gives better performance. Finally, MPC is real time
implemented on a 16-bit PIC microcontroller for speed control of DC motor in presence of constraints and then
its performance is further evaluated in presence of magnetic brake as a load torque and again MPC shows good
results to convince the idea of implementing MPC on a cheaper microcontroller for single input and single
output (SISO) application.to the knowledge.
Keywords: Optimization, DC motor, Microcontroller, SISO, Laguerre Functions.
1 Introduction
Automatic Control System is playing a key role in all areas of commercial ventures like quality control of
made items, automatic mechanical production system, machine instruments, control space engineering,
transportation frameworks, power frameworks, robotics and numerous more. Latest use of modern control
theory includes in non-engineering systems as biomedical, biological, economic and socio-economic systems.
The advancement of control software and technology has given a chance to utilize more refined control
algorithms for industrial systems. Because of this, Proportional Integral (PI) and Proportional Integral
Derivative (PID) have gained extensive application due to its compatibility to both hardware and software
implementation [1]. PID controller has been the most broadly used controller because of its simplicity of
usage [2] PID represents more than 90% of automatic industrial systems. PID compares the actual value with
the desired value, and then uses the compared error to compute the new input to minimize this error and to
achieve the desired steady state [3]. However, since most control processes operate at constraints, therefore, it
415
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
must be ensured that the input and output constraints are not violated [4]. But PID does not has the ability to
handle input and output constraints and also tuning parameters of PID have to be adjusted repeatedly to get
optimal performance for any change occurring in dynamics of a system. PID has also limitations in handling
multivariable processes subject to constraints [5,6]. Solution to these confinements is MPC that can deal with
the process operational limitations more effectively. Different recent publications also indicate the growing
market for advance controllers and few vendors offer turn-key products [7-9] MPC portrays human conduct
by selecting control activities which may lead to best anticipated results over some constrained Skyline and
continuously upgrade choices as new perceptions are accessible [10,11]. MPC acts as a closed loop optimal
control method and explicitly use the process model to handle input and output constraints and also works
more effectively in a dynamic environment [12-14]. MPC is often seen as more effective control technique
and there is a great need to actively implement MPC in different control processes to get more sophisticated
results. MPC is generally used to regulate slow dynamical systems with high bandwidth applications such as
process control in the petrochemical, pulp and paper industries where sampling times can be on the order of
seconds or minutes [15-17]. The major hindrance in implementing MPC on embedded system is the
computational ability needed for the solution of an online recursive optimization problem which is used to
calculate an optimized control input to satisfy both input and output constraints [14]. Development of
advanced embedded systems with increased computational power and faster optimization algorithms has
motivated researchers to implement MPC for higher bandwidth applications i.e. robotics, aerospace, electrical
power and automotive [15]. Recent research work has investigated the performance of MPC in fast devices
such as PLC and FPGA [15-17]. In [15] MPC algorithm is implemented on FPGA which takes advantage of
slack parallel computational channels of FPGA to become suitable for systems with fast sampling times. [16]
has optimized MPC algorithm and implemented on PLC. In [17] MPC has been implemented on PLC by
transforming general MPC in to an efficient algorithm with less computational burden by using Laguerre
functions. But the disadvantage associated with PLCs and FPGAs is their high- power consumption, long
compilation times and high cost. Although, the significant requirement for embedded systems application is
the small power and cost-effective solution [14]. [18] has proposed fast interior-point implementation of MPC
without constraints on very fast but expensive embedded devices i-e Intel Atom with 32-bit processor, ARM
Cortex A9. [19] and [20] has implemented MPC on a high performance 32-bit STM 32 microcontroller for
SISO application in absence of input and output constraints. Similarly, [21] has implemented MPC on high
speed CortexA7 series processor for a simple process and in presence of only input constraints and even it has
tested the results only in Hardware in Loop (HIL) mode. [22] has used Laguerre functions to make MPC
efficient and presented only simulations for DC drive control. Therefore, based on the need of fast dynamical
systems with maximum power efficiency and cost-effective solutions, novelty of this research work is the
improvement in computational burden of MPC by using Laguerre functions and then its implementation in
real-time on a simple cost effective 16-bit microcontroller for speed control of DC motor in the presence of
both input and output`` constraints. Also, the robustness of controller is tested by applying load torque at the
output of DC motor. DC motor has outstanding speed control characteristics therefore, played an important
role as a drive configuration in many applications for a wide range of torques and speeds and it also provides a
test bed to researchers for testing different control algorithms [23-25]. In section 2 Laguerre functions are
discussed. Section 3 presents implementation of MPC. Simulations based analysis is done in section 4.
Hardware implementation and real-time results are shown in section 5. Finally, conclusion is summarized in
section 7.
416
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
2. Laguerre Functions
When The optimized control vector ∆U of MPC is represented by:
(1)
Where, NC is the number of elements in control vector and is known as control horizon. At any given time k i,
the elements of optimized vector can be presented in the form of discrete δ-functions with ∆U is the
coefficient
(2)
Where, δ(i) = 1 if i = 0 and δ(i) = 0 if i ≠ 0 so the function δ is the pulse operator and δ(i-d) shifts the center
of pulse onward with increase in index d so above relation can be used to capture the trajectory of control
vector. It is evident that for i=0, 1,….NC-1 can be characterized by a discrete polynomial function
so discrete Laguerre functions can be used to realize the relation shown in Eq. (1) .
The Laguerre functions are orthonormal in nature and discrete time Laguerre network is generated by
discretization of a continuous-time Laguerre network. The set of continuous time Laguerre functions for any
value of p > 0 are defined below [26]:
Where, p is the time scaling constant of Laguerre functions. The z-transforms of discrete-time Laguerre
functions are shown below:
Where, a is the user define pole of discrete-time Laguerre function and its value ranges from 0 to 1. The
discrete time Laguerre functions can be easily realized using state space approximation of network
417
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
Let denote the inverse z-transform of Γ1(z,a) by l1(k), Γ2(z,a) by l2(k) and similarly ΓN(z, a) by lN (k) and this
forms a set of Laguerre functions in discrete domain shown in a vector form as
Taking advantage of Eq. (4) the set of discrete time Laguerre functions validates the following difference Eq.
(7)
Where, Al is (N×N) matrix and it is a function of parameters a and β = (1-a2). By analysing the Laguerre
equations and using the following z transform properties given in Table 1
Sr.
Z-Domain Discrete-time
No.
1 X(z) X(k)
2 X(z)H(z)
3 X(0)
3 Implementation of MPC
Implementation of MPC for speed control of DC motor can be achieved by applying the System Model shown
in Figure 1 [27]. This System Model illustrates the inter connection of different subsystems to realize a control
system. The first subsystem is the input transducer which converts the input to the form compatible with the
controller. Here, input is the desired speed for the DC motor and output is the actual speed. The controller
estimates the control signal to drive the plant i-e DC motor at the desired speed. The output is given back to
418
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
the controller as feedback via output transducer. It measures the output and transforms it to a compatible form
for the controller.
Disturbance 1 Disturbance 2
error
Refrence Output
Input
Transducer
X Controller X Process X
Output
Transducer Feedback
MPC for the speed control of DC motor is implemented by following the sequence of steps as shown in MPC
flow diagram in Figure 2.
Refrence
Past Inputs 0r Trajectory
Outputd
Predicted Output
Model X
Future
Inputs
Optimizer
Future errors
Cost
Function Constraints
The MPC flow diagram consists of two blocks one is system model and other is optimizer. The initial inputs
and outputs in terms of voltage and speed are given to the system model and it will give the predicted output
speed. Output will be compared with the reference speed and the future errors will be given to the optimizer.
The optimizer in presence of cost function and constraints optimizes the future control signal. The control
signal will be further applied as an input to the system model to predict the output and this procedure will
remain continue until the desired steady state is achieved.
Perfection of any controller is based on how efficiently the dynamics of a system have been modeled [28]. DC
motor is not only frequently used in industrial motion control systems but also provide a standard platform for
researchers to test various control algorithms [29]. There are four major types of DC motor. They are Shunt
DC motor, Series DC motor, Permanent Magnet DC motor (PMDC) and Compound DC motor. PMDC is
419
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
used in the research work. The schematic of PMDC is shown in Figure 3. Vm is the applied voltage, Rm is the
armature resistance and Lm is the armature inductance. Vb is the back emf generated by the motor. Motor
torque, load torque, moment of inertia and speed are T m, TL, Jm and ωm respectively. The mathematical model
of DC motor is obtained by applying electrical and mechanical equations to the electromechanical system i-e
DC motor and then putting the values of internal parameters of DC motor in the transfer function to get exact
model to be used for MPC. The internal parameters of DC motor are shown in Table 2. [30].
Apply KVL to the loop in above Figure 3 to get electrical equation for the system
Where Vb = kω and km= Motor torque constant. Motor is an electromechanical system can be represented by
the Eq. (10).
Here TL is assumed zero to simplify transfer function modeling, Bm is damping friction and Tm =kmIm
After applying Laplace transform to Eq. (9) and (10), simultaneously solve them to get the transfer function
model as shown in Eq. (11).
Substituting DC motor parameters from Table 2 in Eq. 11, the transfer function becomes
Sr.
Parameter Value
No.
420
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
6 Rated voltage Vm = 12 V
This transfer function is discretized by some sampling interval. The sampling interval of a control system is
calculated by using a rule of thumb given below [31]
Where, BW is the Bandwidth of the system and for second order system it can be calculated by Eq. (13) [26].
Where, is natural frequency and is the damping ratio of the system so values of these two variables can
be calculated by comparing Eqs. 12 and 14
The calculated values of and are 0.206 and 84.515 respectively. By putting the values in Eq. (13) BW is
127.296 Hz and it is further used to calculate the sampling time of 261µs.
The Eq. (15) and (16) represent the state-space model that will be used as a system model in Figure 2 for
implementation of MPC.
3.3 Optimizer
MPC is an optimization based technique that optimizes control signal to keep the process output at the set
point and within the predetermined system constraints [32].
Where the Lagurre function and η is the parameter optimized at every sampling instant by the function
shown in Eq. (18).
421
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
Where, Q is the weight matrix, Np is the prediction horizon and RL is a diagonal matrix in the form the RL = rw
x INCxNC (rw ≥ 0). rw is a tuning parameter for desired closed loop performance. For the case that r w = 0, the
cost function is interpreted as the situation where there is no attention paid to how large the ΔU might be and
goal would be solely to make the error (Rs − Y)T (Rs − Y ) as small as possible. For the case of large r w, the
cost function is interpreted as the situation where the magnitude of ΔU is of concern which results in
cautiously reduction of error (Rs − Y)T (Rs− Y) while (m) is expressed by the following Eq. (19) and its
number of rows is identical to the number of rows in η
The first step in implementation of MPC is to acquire state space model (SSM) of the DC motor and introduce
the design parameters, reference point and constraints. Then MPC optimizes the control vector ΔU for output
constraints after the input constraints are ensured to be within the predetermined range. Finally, that control
signal is applied to the SSM of DC motor to predict the output and this procedure continues until desired set
point is achieved. Flow chart of MPC algorithm is shown in Figure 4 [27].
422
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
Simulations based MPC analysis is done in four modes. These modes are discussed below:
The MPC is simulated without constraints for two cases. First with set-point 50 rad/sec and second with set-
point 80 rad/sec. The results are shown in Figure 5
423
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
From above figure it is clear that MPC control the outputs at the desired speeds effectively
As maximum rated voltage of DC motor is 12V and to keep the motor out of dead-zone minimum 1V must be
applied at motor. Therefore, two cases for input constraints imposed on control signal are presented. They are
given below:
Case1: , and Case 2: ,
The simulation results for this mode are shown in Figure 6
424
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
From Figure 6 it is clear that in both cases the input constraints are not violated. In first case due to input
constraint applied at 12V the maximum speed limits to 225 rad/sec and in second case the input constraint was
at 10V and maximum speed limits to 196 rad/sec.
As the maximum rated speed is 235 rad/sec so the output constraint is implemented for two cases at 200
rad/sec and 190rad/sec. the simulation results are shown in Figure 7
From Figure 7 it is evident that in both cases speed does not violate the output constraint and MPC effectively
handles the output constraints
425
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
To understand the handling of both input and output constraints simultaneously by MPC the input constraint is
applied at minimum of applied voltage and output constraint is applied at rated speed 200 rad/sec while
considering the set-point at 235 rad/sec. The constraints imposed on both input and output is given below:
From Figure 8 it is clear that both the input and output constraints are simultaneously handled effectively by
MPC and none of the constraints are violated.
The block diagram of the MPC speed controller is shown in Figure 9. It constitutes of an input transducer to
transform the desired speed reference to a form compatible with the controller, PIC microcontroller generates
required PWM for speed control using MPC algorithm. Motor driver regulates voltage at terminals of DC
motor. Output transducer or sensor measures speed and convert it into the form used by the controller and give
426
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
the result to the controller for estimation of PWM using MPC and display unit shows the result of actual speed
and the applied PWM.
Keypad is used as a user interface unit. It is used to provide a reference or desired value of speed to be
achieved by the motor in the form compatible to the microcontroller. It also provides options to select four
different modes for speed control of DC motor in constrained environment.
5.1.2 Microcontroller
DSPIC30F4011 is a general purpose 16-bit digital controller and it provides precise control by taking
advantage of combining the calculation capability of digital signal processor and controlling capability of PIC
microcontroller. It has high performance modified RISC architecture. The controller has a C compiler
optimized instruction set mechanism with dynamic addressing modes [33]. It is a low power consumption
device with wide range of operating voltage from 2.5V - 5.5V. Controller is used to generate PWM pulses to
regulate the motor speed by getting feedback from encoder
Controller generates 5V PWM pulses and is applied at the driver circuit. Driver circuit regulates voltage at the
DC motor [32]. The Driver circuit used in this project is Dual H Bridge IC L293D. Motor is connected
between pins 3 and 6 of L293D. A separate supply for running motor is applied at pin No. 8 of L293D. VCC
is applied at pin No.4 and 16 while pin No 5 is grounded [33].
5.1.4 DC Motor
DC Motors have numerous industrial and domestic applications and can be selected in various sizes and rates
as per applications. The DC motor used in the research work is WLC-C25MD with built in optical encoder.
The specifications of this motor are shown in Table 3
427
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
LCD is used to show real time results of speed. The LCD used is 16*2 display LCD module. It consists of 16
rows and 2 columns of 5*8 dot matrices. It has 16 pins.
Optical encoder is used to measure the real speed of motor and converts it into a form compatible to
microcontroller. This information is given back to the controller for the optimization of control signal to
generate accurate PWM to drive the motor at desired speed.
The output from microcontroller to motor driver is PWM. MPC optimizes the PWM duty cycle to control the
power supplied to DC motor to get the desired speed. In this research work DSPIC30F4011 microcontroller is
used which has a PWM window from 0 to 8000. 0 means fully “Off” 0% duty cycle while 8000 means fully
“On” 100%duty cycle and any value between them is a proportion of this range.
5.3 Results
Hardware results are shown here in four modes. The first mode is speed control without constraints, second is
with input constraints, third is with output constraints and the last is with both input and output constraints.
The parameters and constraints applied in all four modes are shown in Table 4.
428
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
In this mode the MPC has been implemented on DSPIC30F4011 controller without any constraints imposed to
evaluate MPC for simple step response. The real-time results are shown in Figure 10.
In this mode the MPC has been implemented onDSPIC30F4011 controller for speed control of DC motor with
input constraints imposed. As DC motor has maximum rated voltage of 12V so PWM window should not be
more than 8000 which results in 100% duty cycle so to drive motor within the saturation limit the maximum
allowable duty cycle is 80%. While to keep the motor state out of dead-zone minimum 1V is required which
results in 12.5% duty cycle so constraints in this mode are Umin=12.5 and Umax=80 .The real time results are
shown in Figure 11
429
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
The real-time results have shown that the input constraints are not violated and MPC maintains the applied
PWM with in the applied constraints.
Maximum rated speed of DC motor is 120 rad/sec so to keep the speed within the rated value constraints on
output speed are imposed which is Ymax = 100rad/sec.
The real-time results are shown in Figure 12.
The results from the Figure 12 have shown that the output constraint is not violated and MPC maintains
output in Pre-determined range
In this mode the constraints are imposed on both PWM and speed to evaluate performance of MPC in terms of
constraints handling. The constraints imposed are Umin =12.5 PWM and Ymax = 100rad/sec. The real time
results are shown in Figure 13.
430
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
(a) Output
(b) Input
The results from Figure 13 have shown that none of the input or output constraints are violated and MPC
maintains the output in pre-determined range effectively.
MPC has been evaluated in terms of load torque by using magnetic break. The set point considered is 110
rad/sec. The results are shown in Figure 14
The results have shown that when load torque is induced at output through magnetic brake the speed first dips
at 97 rad/sec but MPC optimizes the control signal to maintain the desired speed and when induced load is
removed the speed increases sharply and reaches to 122 rad/sec but again MPC optimizes the control signal to
maintain the desired speed.
431
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
6. Conclusion
In this research work, real-time implementation of MPC on a simple 16-bit PIC microcontroller for speed
control of a DC motor is done. As classical MPC has high computational burden and not appropriate for
implementation on an ordinary microcontroller so at first, Laguerre functions are used to reduce
computational burden and to improve the feasibility for embedded implementation. The simulations of MPC
have been analyzed in four modes i.e. without constraints, with input constraints, with output constraints and
with both input and output constraints. In all four modes MPC effectively regulates speed without violating
predetermined constraints. Finally, MPC is real-time implemented on a 16-bit PIC microcontroller for speed
control of a DC motor and tested in presence of input constraints, output constraints and load torque. Again,
MPC performs better and effectively regulates speed in presence of constraints and load torque. Moreover,
this paper advocates the idea of implementing MPC on a simple microcontroller for SISO application. In
future prospect this high efficient MPC can be further evaluated by implementation on 16-bit microcontroller
for Multiple Input and Multiple Output (MIMO) system and on 8-bit microcontroller for SISO system.
References
[1] K. R. Das, D. Das, J. Das, “Optimal tuning of PID controller using GWO algorithm for speed control
in DC motor” IEEE International conference on soft Computing Techniques and Implementation, pp.
108-112, June. 2016.
[2] K. H. ANG, G. Hong, Y. Li, “PID Control System Analysis, Design and Technology” IEEE Trans.
Control Systems, vol. 13, pp. 559-576, July. 2005
[3] S.W. Khubulkar, A.S. Chopade, A.S. Junghare, “Design and Tuning of Fractional order PID
controller for speed control of Permanent Magnet Brushless DC motor” IEEE International
Conference on Control, Measurement and Instrumentation, pp. 326-330, Jan. 2016.
[4] S.Aslam, S.Hannan. W.Zafar, U.Sajjad, “Temperature control of Water-Bath system in presence of
constraints by using MPC”, International Journal of Advanced and Applied Sciences, vol. 3, pp. 62-
68, 2016.
[5] K. S. Holkar, L.M. Waghmere, K.K. Wagh, “An Overview of Model Predictive Control”,
International Journal of Control and Automation, vol. 3, pp.47-64, December, 2010
[6] A.A. Ahmed, “Fast-Speed Drives for Permanent Magnet Synchronous Motor Based on Model
Predictive Control” IEEE International Conference on Vehicle Power and Propulsion, pp. 978-983,
December. 2015.
[7] J. Richal et, “. Industrial application of Predictive functional control”, In: Nonlinear Model Predictive
Control, Software and Applications. Loughborough, U.K, 2007
[8] Y.Z. Zhu, XU, J. Zhao, K. Han, J. Ojan, W. Li, “Development and Application of an Integrated MPC
Technology”, In Proceedings of the 17th IFAC World Congress, Korea, pp.6962-6967, 2008
[9] J. Rossister, R.H. Bishop. Model based Predictive Control a Practical approach. CRC Press, 2005.
[10] D.E. Seborg, D.A. Mellichamp. Process , Dynamics and Control. WILEY Publisher, 2010
[11] J. Maciejowski. Predictive Control with Constraints. Pearson Education, 2001
[12] M.V. Kathore, V. Balakrisham, M. Morari, “Robust Constrained Model Predictive Control using
Linear Matrix Inequalities” Automatica, vol. 32, pp. 1361-1379, October, 1996
[13] A.A. Kherji, F. Bouani, M. Ksouri, “A microcontroller Implementation of Model Predictive Control”
World Academy of Science, Engineering and Technology, vol. 56, pp. 662-665, 2011
432
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
433
Journal of Engineering Technology
Volume 6, Issue 1, Jan. 2018, PP. 415-434
[33] S. Priyan, P. Salvaraj, “A Wireless Speed Control of AC Drive System” International Journal of
Advanced Research in Electrical, Electronics and Instrumentation Engineering., vol. 3, pp. 448-456,
2014.
[34] S.K. Arvind, T.A. Arun, “Speed Control of DC motor using PIC 16F877A Microcontroller”
Multidisciplinary Journal of Research in Engineering and Technology, pp 223-234, 2008.
434