Effect of Moving Average Filter With Pid Controller Using Hil Technique20210901110811
Effect of Moving Average Filter With Pid Controller Using Hil Technique20210901110811
Bilal A. MUBDIR1
Abstract
Designing fast response controller that can achieving steady state with minimum error
is big challenge in control application. Proportional Integral Derivate (PID) controllers
are conventional controllers for their simplicity and wide range of applications in
industrial. Many efforts have been made in improving the PID controller performance by
enhancing the controller with different techniques for tuning its operation or filtering the
feedback signal. In this paper, the effect of using Moving Average filter with the PID
controller for controlling the speed of Permanent Magnet DC (PMDC) Motor with noisy
speed sensor is discussed. PID controller and the moving average filter are modeled in
MATLAB/Simulink software, where the Hardware in the Loop (HIL) technique with aid
of microcontroller was used for the controlled plant which is a PMDC motor in this
study. Comprehensive study on the available techniques used to modeling the PID
controller is done as well. Furthermore, full practical tests prove that the controller
behavior is more stable when moving average filter used and its effect minimized time
needed to reach the steady state point clearly by 76%.
Keywords: HIL, PID, Moving Average, Microcontroller, MATLAB, Speed Control.
1
Polytechnic University, Iraq, [email protected], https://orcid.org/0000-0001-8096-8027
Introduction
One of the most important things to pay attention to when designing a control system is the
stability of the system and obtaining the lowest error rate with respect to the set point of the
system. Real time control is widely used in many industrial applications where it could be achieved
by different approaches and methods.
Among all available techniques, Proportional-integral-derivative (PID) control are the traditional
controls that used since more than 70 years in control engineering science [1]. Nowadays, more
than 90% of the applied consumers and industrial control systems are built based PID controllers.
Different PID software, patents, and hardware modules are discussed and the differences between
the industrial and academic research practice are bring out in [2]. Furthermore, in NASA rocket
lunch systems the control process is commonly performed by PID controller as reported by Y.
Eisenberg and M. Dupuis in [3].
PID controllers in the past decades are developed by using analog circuits that has its own
limitations. With emerge of computer technology and the continuous development in embedded
processors technology in speed of performance and the cost, implementing PID controllers
currently is done easily by deploying the PID algorithm into a single microcontroller unit. Moreover,
in academic research many software packages provide an easy way to simulate the mathematical
models of the PID controller such as MATLAB and LabView software application. Out of many
examples and applications for developing PID controllers, controlling the speed of a DC motor is
the most used application due its simplicity and easy of setup.
C. Agarwal and A. Gupta have used FPGA to develop a speed controller of PMDC motor with the
aid of encoders for speed feedback. They implemented PID controller model under MATLAB with
predefined parameters, where the model has been simulated to test its effectiveness then
uploaded to the FPGA. Their developed speed controller proves high accuracy in controlling the
speed compared to the traditional microcontroller. The tested the model n different types of FPGA
boards and they compared the performance for each one[4].
The authors in [5] have designed and tested a PID controller to achieve a predefined threshold for
the rise time, settling time, and the steady state error-based microcontroller. Primarily, their design
has been configured under Simulink and with simulated PMDC motor. The practical they have
tested the PID controller on an Atmega328 microcontroller under Proteus Software simulation
application. The microcontroller has been connected to a PMDC motor and rotary encoder to feed
the speed back to the microcontroller. They reported that their aims have been achieved under this
design.
The power of using simulation software such as MATLAB offers a great method to simulate PID
controller or any other types of controllers and test their performance. Not only simulating the
controller, also the controlled plant may be simulated which the DC motor in which this paper is
focused on as explained in [6], where Ling Xu eta al., have simulated the equivalent model of the
brushless type of DC motor in Simulink and they used double loop technique in their control mode
to ensure the performance and the speed stability of the motor.
In 2017, K. Sharma and D. K. Palwalia have proposed a PID controller tuned by Fuzzy logic
control. In their design, the PID controller parameters have been controlled by the Fuzzy logic
control in order to provide better control over the speed of the DC motor. The work has been
performed under MATLAB/Simulink software and the performance of the Fuzzy logic tuned PID
(FPID) controlled has been compared to the conventional PID controller. As a result, the proposed
FPID achieved higher performance than the conventional PID in terms of speed, steady state
error, and overshot [7].
Another control approach was used by N. Pati and his friend under MATLAB/Simulink software.
The researchers have simulated the layout of Youla Parameterization approach that depend on
the plant model inversion to control separately excited PMDC Motor and then compare it to the
classic PID controller without filter for the same study case. The aim of their research is to present
the performance analysis of the closed loop control for the motor in two different approaches [8].
G. Shahgholian eta al. has focused on the adaptive model control and their advantages over the
conventional non-adaptive control models when it used to control the speed of the motors. Thy
aimed to increase the stability of control system and reduce the consequences of load
disturbances and changes. They simulated the in MATLAB/Simulink software the model of two
adaptive controller type, Fuzzy and reference one. The two-controlapproached, and non-adaptive
control model have been studied and compared to each other. The authors have concludedafter
testing that the performance of the system is better when using adaptive controller rather than
conventional type. Also, the found that the adaptive Fuzzy type provide superior performance over
the other adaptive types.[9].
Controlling the speed of a DC motor is not necessary to be in a closed loop control system as in
PID control criteria. For example, S. N. Thanh and his colleagues have been designed a sensor-
less control system which is applied separately excited DC motor. Their system has been
designed and simulated under Simulink and it technically reveals that its performance much better
than the linear PI controller[10].
Practically, HIL technique has been used to develop a closed loop PI controller for PMDC motor in
reference [14]. H. Khan and his colleague have used the 8-bit Atmel 8051 microcontroller as a
hardware in the loop of the controller. The algorithm of the PI controller was deployed into the
microcontroller, while the DC motor as the controlled plant has been simulated in the
MATLAB/Simulink software. The embedded processor Atmel 8051 feed the control signal to the
plant in Simulink, and the output of the plant is feed to the microcontroller again. Both feeding is
carried out from/to the microcontroller via serial communication port.
Literature [15] described a method for characteristics analysis and compassion of two control
methods for the permanent magnet synchronous motor (PMSM). The researchers have used high
efficiency PSMS development method according to rapid control prototype (RCP). Hardware in the
loop simulation model have been developed by using hardware and software environment system,
the simulation carried out by MATLAB and CCS softwares. The hardware such as the PMSM,
driving circuit, encoders and other circuitry have been interfaced to the real time control
TMS320F28335 32-bit microcontroller unit. Their results show the hardware in the loop simulation
performed very well as expected in the mathematical models with the same PID controller
parameters
In [16], H. Hameed has simulated the brushless DC motor in MATLAB/Simulink and designed a
PID controller to regulatethe BLDC motor’s speed. The designed controller has been compared to
the Proportional (P), and Proportional Integral (PI) controllers under the MATLAB simulation
environment. His results show that the designed PID controller performed better than the other
types. The author also has used the Hardware in the loop technique to test the output signal of the
controller on the oscilloscope which is in the form of PWM by using Arduino development board.
Likewise, M. Gavran and his colleges have implemented a closed-loop controller by using Arduino
development board that contain Atmega328 microcontroller from Atmel and PI controller built in
MATLAB/Simulink installed on personal computer with help of speed sensor that works as a
negative feedback to the controller. They used a ready to use software developed by MathWorks
Company to access the pins and the features of the microcontroller from the Simulink. They tested
the system practically on a DC motor loaded practically with generator [17].
Using HIL is not limited only to test and validate controllers. For example, Y. C. Chou eta al. have
present HIL simulation to test autonomous underwater vehicles (AUV) and developing its control
system. They have used HIL between the AUV computer and the Simulation server. They
concluded that developing control system for the AUVs could be more effective if the HIL
simulation is used[18].
In this paper, the Simple Moving Average (SMA) filter is used to filter out the noise in the feedback
of the closed-loop controller with different window’s sizes. The SMA is governed by the
mathematical expression of equation (1), knowing thatn is the number of the previous data points
or the window size [24].
(1)
Where:
SMA: Simple Moving Average value
PM: point value at time M
n: window size or number of data points
3. Problem Statement
The control process of an electromechanical system sometimes involved with noise generated by
mechanical vibrations or electronics components interference and other causes. In any embedded
system, sensors are the most part affected by noise, and it could result in an error on its output.
Considering closed-loop controller controlling DC motor possess the specifications outlined in
Table (1), with a noisy sensor used to measure the motor speed as return feedback for PID type
controller. The noise generate by the sensor will affect the behavior of the speed response of the
DC motor and develop serious delay in reaching the steady state level of the desired reference
speed of the DC motor.
control loop to send and receive data from the external hardware, which is act as Hardware in the
Loop (HIL) as shown in Figure (2).
Figure 2: The simulate model for the closed-loop control system with HIL.
The HIL has been interfaced over Serial communication Protocol with aid of an external UART
circuit. The physical stage here is the Atmega328P microcontroller unit (MCU) from Atmel [25].
According to Figure (3), the MCU is connected to the motor driving circuit and speed measurement
circuit as well.
The motor driving circuit is designed using MOSFET operated as switch to control the voltage of
the motor by varying duty cycle PWM signal from the MCU, thus controlling its speed as shown in
Figure (4).
On the other hand, simple encoder circuit was used to measure the speed of the motor with the
aid of plastic wheel attached to the motor’s rotational shift. The encoder circuit built using a pair of
IR transmitter and receiver as illustrated in Figure (5), to generate a pulse every single complete
rotation. The MCU has been programmed to accumulate the pulses and calculate the
instantaneous revolutions per minute (RPM) and driving the MOSFET continuously according to
the received signal from the PID controller in MATLAB.
The data are sent and received every 50ms over serial communication protocol with a baud rate of
115200 bps. The while Simulink model has been configured to work on a sampling rate of 50ms to
be compatible with the HIL. The motor used in the experiments is Brushed DC motor with technical
specifications as explained in Table (1). The motor operated by separated 9V power supply with a
total of 1.9A current consumption on rated speed.Moreover, The Simulink model has other blocks
for data collection purposes and exporting waveforms drawings. Moving average block with
different window sizes has been used in five tests and disabled on others by commenting it
through.
Parameter Value
P 2.5
I 1
D 0.5
The resultant response in Figure (6) shows that when the sensor is accurate the overshot is 14%
and the settling time is 4.544 sec, this is the case where it is considered as the reference case for
the controller in this research. It is clearly seen in Figure (6) that noisy sensor results in less
overshot 6.78% but with longer settling time 19.987 sec. Longer settling time with continuous
fluctuation could lead to unstable performance, which is not preferable for critical applications.
At this point, moving average filter with different window sizes has been embedded in the control
loop on Simulink and the step response tested to obtain the speed response. The tests are carried
by set the moving average’s window size to 5, 10, 15, 20, 30, and 50 to evaluate the performance
in each case. The speed response is shown in Figures (7) to (12) for all each case 5, 10, 15, 20,
30, and 50 respectively.
Figure 7: Motor’sspeed response with Moving Average Filter used (window size = 5).
Figure 8: Motor’sspeed response with Moving Average Filter (window size = 10).
Figure 9: Motor’sspeed response with Moving Average Filter used (window size = 15).
Figure 10: Motor’sspeed response with Moving Average Filter used (window size = 20).
Figure 11: Motor’sspeed response with Moving Average Filter used (window size = 30).
Figure 12: Motor’sspeed response with Moving Average Filter used (window size = 50).
With quick look at the resultant responses, it is obvious the change in the overshot, settling time,
and thus the stability. Table (3) summarized the step response characteristics for each case in
addition to the reference case. As the moving average’s size of the window increases, the noise
eliminated but the response tends to be unstable. With lower window’s size, the stability was
enhanced better than larger size.
Size of window =
Size of window =
Size of window =
Size of window =
Size of window =
Size of window = 5
sensor
10
15
20
30
50
1.33 1.050 0.963 1.11 1.073 1.049 1.242 1.718
RiseTime (sec.) 7 5 1 3 1 6 9 4
It’s clearly seen from Table (3) that when the window size is more than 20, the system is
completely became unstable and never reach to the steady state. At the lowest window size, the
performance of the step response for the noisy sensor was improved by about 76% in terms of
Settling time, and it reaches the steady state level just 257ms later to the reference response
shown in Table (3) but with larger overshot. When the size of the window doubled to 10, the
settling time increases again and became 5.353 sec but still acceptable in terms of stability with
73.2% improvement compared to the noisy sensor case step response. Furthermore, the settling
time is 5.47 sec and 8.41sec when the moving average filter’s window size is 15 and 20
respectively with an improvement of 72.6% and 57.9% compared to the noisy sensor case step
response.
5. Conclusion
To sum up, Using the HIL technique provide an easy method to test and verify the control system
by integrating the facilities of the computer-based applications like MATLAB with the real physical
plant. Improving the closed-loop control system can be performed using different techniques, extra
tuning for the controller parameters, or using proper filers to achieve better performance. The
results proved that using even a simple moving average filter with minimum window size leads to a
significant improvement in stability in case of using a noisy sensor in the feedback of the closed-
loop control system. Where the time needed for reaching the steady state level is reduced by
15.18 sec with an overall improvement of 76%. However, an increase in overshot along with the
improvement in reaching the steady state level is observer, where it could be not preferable in
some cases which must be considered for specific applications.
Reference
A. O'Dwyer, "PI and PID controller tuning rules: an overview and personal perspective," 2006 IET
Irish Signals and Systems Conference, pp. 161-166, 2006.
Li, Y. and Ang, K.H. and Chong, G.C.Y., “Patents, software and hardware for PID control: an
overview and analysis of the current art,”IEEE Control Systems Magazine, vol. 26,
no.1, pp. 42-54, 2006.
Y. Eisenberg, and M. Dupuis, “Adaptive Control Law for PID,” Grantee Report, NASA Internships
and Fellowships (NIF), April 12, 2019.
C. Agarwal and A. Gupta, "Modeling, simulation-based DC motor speed control by implementing
PID controller on FPGA," Confluence 2013: The Next Generation Information
Technology Summit (4th International Conference), pp. 467-471, 2013. doi:
10.1049/cp.2013.2358.
Yu, Jaehong, Seoung B. Kim, Jinli Bai, and Sung W. Han, "Comparative Study on Exponentially
Weighted Moving Average Approaches for the Self-Starting Forecasting," Applied
Sciences, vol. 10, no. 20: 7351, 2020. https://doi.org/10.3390/app10207351
S. Hansun, "A new approach of moving average method in time series analysis," 2013 Conference
on New Media Studies (CoNMedia), pp. 1-4, 2013. doi:
10.1109/CoNMedia.2013.6708545.
Atmel Corporation, “8-bit AVR Microntroller with 4/8/16/32K Bytes In-System Programmable
Flash,” ATmega 328P datasheet, 2019.