Fuzzy PID Controllers Using FPGA Technique For Real Time DC Motor Speed Control
Fuzzy PID Controllers Using FPGA Technique For Real Time DC Motor Speed Control
Fuzzy PID Controllers Using FPGA Technique For Real Time DC Motor Speed Control
Figure 1. DC motor.
Figure 2. Schematic representation of the considered DC
motor.
Table 1. Dc motor parameters.
Parameter Value
Moment of inertia of the rotor J = 0.00025 Nm/rad/s
2
Damping (friction) of the mechanical
system
b = 0.0001 Nm/rad/s
Terminal resistance RA = 0.5
Terminal inductance LA = 1.5 mH
Electromotive force constant K = 0.05 Nm / A
The input is the armature voltage V in Volts, and the
measured variables are the angular velocity of the shaft w
in radians per second. The motor torque, T, is related to
the armature current, i, by a constant factor K:
T Ki = (1)
The back electromotive force (emf) Vb, is related to
the angular velocity by:
d
K K
d
b
V
t
u
e = = (2)
From Figure 2 we can write the following equations
based on the Newtons law combined with the
Kirchhoffs law:
2
2
d d
d d
J b K i
t t
+ = (3)
d
d d
i
L Ri V - K
t t
+ =
d
(4)
Using the Laplace transform, equations (3) and (4) can
be written as:
( ) ( ) (
2
Js s bs ) s KI s + = (5)
( ) ( ) ( ) ( LsI s RI s V s - Ks ) s + = (6)
From (6) we can express I(s):
( )
( ) ( ) V s Ks s
I s
R Ls
=
+
(7)
And substitute it in (5) to obtain:
( ) ( )
( ) ( )
2
V s Ks s
JS s bs s K
R Ls
+ =
+
(8)
This equation for the DC motor is shown in the block
diagram at Figure 3.
From the block diagram in Figure 3, it is easy to see
that the transfer function from the input voltage, V(s), to
the angular velocity.
( )
( )
( ) ( )( )
2
a
s K
G s
V s s R Ls Js b K
u
= =
( + + +
(9)
Copyright 2011 SciRes. ICA
B. M. HAMED ET AL. 235
T(s)
Figure 3. A block diagram of the DC motor.
( )
( )
( ) ( )( )
2 v
s K
G s
V s R Ls Js b K
= =
+ + +
(10)
3. Fuzzy Logic
Fuzzy Logic (FL) is an approach to control engineering
problems, which mimics how a person would make deci-
sions, only much faster. FL incorporates a simple
rule-based IF X AND Y THEN Z approach to a solv-
ing control problem rather than attempting to model a
system mathematically [7,8]. The FL model is empiri-
cally-based, relying on an operators experience rather
than his technical understanding of the system. In other
words fuzzy logic is used in system control and analysis
design, because it shortens the time for engineering de-
velopment and sometimes, in the case of highly complex
systems, is the only way to solve the problem [9,10].
Every Fuzzy system is composed of four principal blocks
as shown in Figure 4:
1) Knowledge base: Rules and parameters for mem-
bership functions.
2) Decision making unit: Inference operations on the
rules.
3) Fuzzification interface: Transformation of the crisp
inputs into degrees of match with linguistic variables.
4) Defuzzification interface: Transformation of the
Fuzzy result of the inference into a crisp output.
4. Field Programmable Gate Arrays
(FPGAs)
FPGAs shown in Figure 5, stands for Field Programma-
ble Gate Arrays are one type of programmable logic de-
vices (PLDs). It is based on an integrated circuit that can
be configured by the user in order to implement digital
logic functions of varying complexities. FPGAs can be
very effectively used for control purposes in processes
demanding very high loop cycle time. One of the funda-
mental advantage of FPGA over DSP or other micro-
processors is the freedom of programming parallelism
[11,12]. Since different parts of FPGA can be configured
to perform independent functions simultaneously, its
performance is just not tied to clock rate as in DSPs. This
FUZZY
Figure 4. General structure of fuzzy inference system.
Figure 5. Structure of a Xilinx FPGA standard.
fact enables FPGAs to score over general purpose com-
puting chips in the digital control systems implementa-
tion [13].
5. Controllers Design
This paper presents the process used to design three
kinds of widely used controllers (PID, Fuzzy, and
Fuzzy-PID) for the DC motor using FPGA technique.
Figure 6 contains the main block diagram for the sys-
tem.
To provide DC motor with the required voltage, we
need a PWM driver shown in Figure 7. PWM is a way
of digitally encoding analog signal levels. The duty cycle
of a square wave is modulated to encode a specific
analog signal level. The PWM signal is still digital
Figure 6. Block diagram for DC motor controller.
Copyright 2011 SciRes. ICA
B. HAMED ET AL. 236
Figure 7. PWM signals.
because, at any given instant of time, the full DC supply
is either fully on or fully off. The voltage or current
source is supplied to the analog load by means of a
repeating series of on and off pulses. Figure 7 shows
three different PWM signals with PWM output at a 10%,
50%, and 90% duty cycles, respectively. These three
PWM outputs encode three different analog signal values,
at 10%, 50%, and 90% of the full strength of the Dc
voltage [13].
Three different controllers were developed in this pa-
per: PID controller, Fuzzy controller, and Fuzzy-PID
controller. Finally, a comparison will be made among
these controllers to find the best performer.
5.1. PID Controller
The block diagram of a PID controller algorithm is
shown in Figure 8.
Its required to build a digital PID controller in the
FPGA card. There are many approaches are available to
convert from analogue to digital. In this proper we used
the Tus- tin approach. The equation which represents the
PID controller is:
( ) ( ) ( )
( ) d
d
d
p i d
e t
u t K e t K e t t K
t
= + +
}
(10)
There are many methods available to get the best val-
ues of K
p
, K
i,
and K
d
. One approach is to use a technique
that was developed in the 1950s but has stood the time
and is still used today. This is known as the Ziegler
Nichols tuning method [14].
A general rule of thumb in control design is to sample
at least 4 to 20 times the rise time of the system response,
so the sampling time will be chosen to 4.1 milliseconds.
Hence, the output of the PID controller will feed to the
plant speed register of the PWM.
The Simulink block diagram for the PID speed con-
troller for DC motor is shown in Figure 9. The controller
has been tested using Simulink in Matlab. The result of
PID controller is shown in Figure 10.
Figure 8. PID algorithm.
Figure 9. PID speed controller for Dc motor.
Figure 10. PID controller step response.
Copyright 2011 SciRes. ICA
B. M. HAMED ET AL. 237
5.2. Fuzzy Logic Controller FLC
FLC has been constructed Using VHDL and embedded
PicoBalze processor in FPGA. The block diagram for the
FLC for the DC motor is shown in Figure 11.
FLC has two inputs, which are: Error (E) and the Error
change (CE), and one output feeding to the plant speed
register of the PWM. Figure 12 illustrates the method
used in reaching the desired speed value. For example, at
stage A the Error is positive (desired speed actual speed)
and the Change Error (Error - last Error) is negative,
which mean that the response is heading in the right di-
rection; hence, the FLC will go forward in this direction.
Using the same criteria at stage B, the Error is negative
and CE is big negative; hence, the response is heading in
wrong direction so FLC will change its direction to enter
Stage C, until reaching the desired speed.
In this paper, Mamdani approach in FPGA has been
used to implement FLC for the DC motor. FLC contains
three basic parts: Fuzzification, Base rule, and Defuzzi-
fication.
5.2.1. Fuzzification
The Fuzzy set of the Error input which contains 7 Tri-
angular memberships is shown in Figure 13.
Figure 14 illustrates the Fuzzy set of the Change Error
input which contains 7 Triangular memberships.
Figure 15 illustrates the Fuzzy set of the output which
contains 7 Triangular memberships.
5.2.2. Control Base Rules
Table 2 presents the knowledge base defining the rules
for the desired relationship between the input and output
Figure 11. FLC speed controller for Dc motor.
Figure 12. Error and error change approach in FLC.
Figure 13. Error fuzzy set of FLC.
Figure 14. Change error fuzzy set of FLC.
Figure 15. Fuzzy set of FLC output entering to plant speed
register.
Table 2. Fuzzy controller base rules
E
CE
NB NM NS ZE PS PM PB
NB NB NB NB NB NM NS ZE
NM NB NB NM NM NS ZE PS
NZ NB NM NS NS ZE PS PM
ZE NB NM NS ZE PS PM PB
PS NM NS ZE PS PS PM PB
PM NS ZE PS PM PM PB PB
PB ZE PS PM PB PB PB PB
variables in terms of the membership functions. The
control rules are represented as a set of:
IF Error is.. and Change Error isTHEN the output
will .
Figure 16 shows the surface of the base rules used in
FLC.
Copyright 2011 SciRes. ICA
B. HAMED ET AL. 238
5.2.3. Defuzzification
The center of gravity centroid method was used in this
paper. Figure 17 shows the Simulink block diagram for
the Fuzzy speed controller for DC motor. The controller
has been tested using Simulink in Matlab. The result of
Fuzzy controller is shown in Figure 18.
5.3. Fuzzy-PID Controller
Here, another approach which depends on mixing the
PID controller with Fuzzy controller in FPGA using
VHDL code. Hence, the value of the PID parameters will
be evaluated using the Fuzzy controller. A complete de-
sign of the system is shown in Figure 19. The Fuzzy sets
Figure 16. Rules surface of FLC
Figure 17. Fuzzy logic speed controller.
Figure 18. Fuzzy controller step response.
for the output: K
p
, K
i,
and K
d
is shown in Figure 20,
practically there are three different Fuzzy sets for these
parameters. The inputs of the controller used are the er-
ror and change of error as presented in the previous sec-
tion.
Table 3 presents the base rules of Fuzzy-PID control-
ler (K
p
). Practically there are three base rules tables for
K
p
, K
i,
and K
d
Simulink block diagram for the Fuzzy-PID speed con-
troller for DC motor is shown in Figure 21.
Figure 19. Fuzzy-PID controller for the induction motor.
Figure 20. Fuzzy sets for Kp, Ki, and Kd with different
memberships boundaries.
Table 3. Base rules for fuzzy-PID controller (Kp).
E
CE
NB NM NS ZE PS PM PB
PB ZE PS PM PB PB PB PB
PM NS ZE PS PM PB PB PB
PS NM NS ZE PS PM PB PB
ZE NB NM NS ZE PS PM PB
NS NB NB NM NS ZE PS PM
NM NB NB NB NM NS ZE PS
NB NB NB NB NB NM NS ZE
Copyright 2011 SciRes. ICA
B. M. HAMED ET AL. 239
Figure 21. Fuzzy-PID logic speed controller.
The controller has been tested using Simulink in Mat-
lab. The result of Fuzzy-PID controller is shown in Fig-
ure 22.
5.4. Results Comparison
Table 4 shows controllers comparison, hence its found
that the Fuzzy-PID controller is the best controller
among the other controllers.
All three controllers presented in this paper are im-
plemented in hardware using the FPGA card; then these
controllers have been tested with real time experiments.
An auxiliary program in the FPGA is implemented to test
the step response of these controllers. Then our program
displays the results on the LCD using the PicoBlaze proc-
essor technique as a real time tester. The LCD displays
Figure 22. Fuzzy-PID controller step response.
Table 4. Controllers comparison.
Controller Overshoot Settling time Steady state error
PID 4.82 0.0187 0
Fuzzy 2.43 0.014 0
Fuzzy-PID 0.965 0.00344 0
the desired speed, the overshoot, the settling time, and
the PID parameters for each controller as shown in Fig-
ures 23 and 24. The result of the real time experiment
we have is very close to the Matlab simulation. A digital
optical encoder with two channels is used to read the
speed of the motor, and it displays the direction of the
motor as shown in Figure 25. Many features were ap-
plied to the system as overload protection, motor direc-
tion switch and also we used three switches to enter the
controllers type and to specify the parameters of the PID
controller.
5.5. Modelsim Results
PWM algorithm was tested using Modelsim (VHDL
simulator) program, which is a powerful simulator estab-
lished by Xilinx Company. Using this simulator we can
specify the input and the output ports then the simulator
will test the VHDL code which shown in Figure 26.
6. Conclusions
In this paper, Fuzzy-PID controller has been selected to
Figure 23. FPGA card with LCD and controlling keys.
Figure 24. Real time experiments results on the LCD.
Copyright 2011 SciRes. ICA
B. HAMED ET AL.
Copyright 2011 SciRes. ICA
240
7. References control the speed of DC motor due to its advantages over
the traditional PID controller. The control scheme was
modeled and designed in VHDL. It was simulated and
synthesized using the Xilinx Foundation package and
implemented into a Xilinx Spartan 3-A FPGA (Figure
27). The experiments show that the dynamic response of
a system using the proposed controller is better when
compared to a classical PID, and Fuzzy controller. Also
these controllers have been tested using Matlab/Simulink
program under speed and load variation conditions. The
comparison results showed that the Fuzzy-PID controller
was the best controller.
[1] S. Raghavan, Digital Control for Speed and Position of a
DC Motor, MS Thesis, Texas A & M University Kings-
ville, 2005.
[2] Z. Xiu, and G. Ren, Optimization Design of TS-PID
Fuzzy Controllers Based on Genetic Algorithms, 5th
World Congress on Intelligent Control and Automation,
Hangzhou, 2004, pp. 2476-2480.
[3] S. Z. He, S. Tan and F. L. Xu, Fuzzy Self-Tuning of PID
controllers, Fuzzy Sets and Systems, Vol. 56, No. 1,
1993, pp. 37-46. doi: 10.1016/0165-0114(93)90183-I
[4] B. Lacevic, J. Velagic and N. Osmic, (2007). Design of
Fuzzy Logic Based Mobile Robot Position Controller
Using Genetic Algorithm, IEEE/ASME International
Conference on Advanced Intelligent Mechatronics, Zu-
rich, 2007, pp. 1-6.
[5] Xilinx Company, Programmable Logic Design, 2006.
http://www.xilinx.com/company/about/programmable
[6] Xilinx Company, Spartan-3A Starter Kit Board User
Guide, 2007.
http://www.xilinx.com/bvdocs/userguides/ug330
[7] L. A. Zadeh, Fuzzy Sets, Information and Control, Vol.
8, No. 3, 1965, pp. 338-353.
doi:10.1016/S0019-9958(65)90241-X
[8] E. H. Mamdani, Application of Fuzzy Algorithms for
Control of Simple Dynamic Plant, Proceedings of the
IEEE, Vol. 121, No. 12, 1974, pp. 1585-1588.
Figure 25. Digital optical encoder.
[9] L.-X. Wang, A Course in Fuzzy Systems and Control,
Prentice-Hall, Inc., Upper Saddle River, 1997.
[10] M.-Y. Shieh and T.-H. S. Li, Design and Implementa-
tion of Integrated Fuzzy Logic Controller for
Servo-Motor System, Mechatronics, Vol. 8, No. 3, 1998,
pp. 217-240. doi:10.1016/S0957-4158(97)00052-4
, 1992, pp. 561-568.
[11] J. Birkner et al., A Very-High-Speed
Field-Programmable Gate Array Using Metal-to-Metal
Antifuse Programmable Elements, Microelectronics
Journal, Vol. 23, No. 7
doi:10.1016/0026-2692(92)90067-B
Figure 26. PWM modelsim signal.
[12] S. Poorani, T. V. S. Urmila Priya, K. Udaya Kumar and S.
Renganarayanan, FPGA Based Fuzzy Logic Controller
for Electric Vehicle, Journal of the Institution of Engi-
neers, Vol. 45 No. 5, 2005, pp. 1-14.
[13] T. Runghimmawan, S. Intajag and V. Krongratana,
Fuzzy Logic PID Controller Based on FPGA for Process
Control, IEEE International Symposium on Industrial
Electronics, Vol. 2, No. 11, 2004, pp. 1495-1500.
[14] D. Zhang, et al., Digital Anti-Windup PI Controllers for
Variable-Speed Motor Drives Using FPGA and Stochas-
tic Theory, IEEE Transactions on Power Electronics,
Vol. 21, No. 5, 2006, pp. 1496-1501.
doi:10.1109/TPEL.2006.882342
Figure 27. Spartan-3A, Xilinx company.