You are on page 1of 6

978-1-4673-2376-5/12/$31.

00 2012 IEEE

2012 International Conference on System Engineering and Technology
September 11-12, 2012, Bandung, Indonesia
Fuzzy PID Controllers Using 8-Bit Microcontroller
for U-Board Speed Control
Sereyvatha Sarin
#1
, Hilwadi Hindersah
*2
, Ary Setijadi Prihatmanto
*3

#
Department of Electronic, National Polytechnic Institute of Cambodia
St.Kobsrov, Saroung krom, Dangkor, Phnom Penh, Cambodia
*
School of Electrical Engineering & Informatics, Institut Teknologi Bandung
Jl. Ganesha 10, Bandung 40132, Indonesia
1
sereivatha@yahoo.com
2
hilwadi@lskk.ee.itb.ac.id
3
asetijadi@lskk.ee.itb.ac.id

Abstract This paper presents a design and implementation of
Fuzzy Logic PID Controller using 8-bit microcontroller U-Board
speed control. The speed of system depends on the speed of
considered DC motor. So, the main speed control is to control the
speed of considered DC motor.
The completed system composes of Fuzzy PID
controller, Half-bridge driver, motor, 4:1transmission
gear, tire, and speed sensor. The controller reads the
commanding speed from user and compares to the actual
speed read by the speed sensor which is attached with the
U-Board frame, performs the Fuzzy PID computation,
then sets the result of calculation to the PWM ports to
drive the motor. The tire of the U-Board is connected to
the motor by the chain with 4:1 reduced gear, it can be
clearly seen that the speed of U-Board is slower than the
speed of motor 4 times.
The feasibility and effectiveness of the control techniques are
verified using the experimental results and implemented using
the PIC 8-bit microcontroller under speed variation and showed
the superiority of Fuzzy-PID.

Keywords Fuzzy Logic Control, PID Control, Speed Control,
PIC Microcontroller, U-Board.
I. INTRODUCTION
The electrical alternative transportations or personal
transportations are the most interesting and are being
produced by automotive company dedicated to providing
environmentalists, and everyday consumers with the perfect
ride: smooth, quiet, clean, green ,and zero emissions to the air
environment [1].
To fulfil the needs of green technology, the brushed DC
motor has been used and the intelligent controllers also have
been deployed to control the speed of the system. Due to its
excellent speed control characteristics brushed DC motor has
been widely used in these electrical personal transportations
even though its require the scheduling maintenances , the
speed of DC motor can be adjusted to a great extent by
varying the armature voltage, so it can provide easy control
and high performance [2,3,4].
Emerging intelligent techniques have been developed and
extensively use to improve or to replace conventional control
techniques because these techniques do not require a precise
model [4]. One of the intelligent techniques, fuzzy logic
developed by Lotfi A. Zadeh [5] is applied for controller
design in many applications [4,6,7]. Fuzzy Logic has been
successfully applied to a large number of control applications
and platforms such as FPGA [8], personal computer [9] or off
the shelf microcontroller [10].
At present, Proportional-Integral-Derivative PID
controller, due to its simplicity, stability, and robustness, is a
type of controllers that is most widely applied [11,12]. For
brushed DC motors, factors such as unknown load
characteristic and parameter variation influence seriously the
controlling effect of speed controller [8].
Fuzzy logic controller provides an alternative to PID
controller since it is a good tool for the control of systems that
are difficult in modelling. The control action in fuzzy logic
controllers can be expressed with simple if-then rules.
Fuzzy control gives robust performance for a linear or
nonlinear plant with parameter variation. Hardware
implementation of the controller can be achieved in a number
of ways to create new products [8].
On the other hand, using microcontroller to implement a
FL-PID controller is inexpensive and the physical size of the
system is small; however, it is suitable for movable equipment,
but the FL-PID controller requires longer processing time to
complete the performance [8].
Based on advantages of higher level microcontroller
device, microchip PIC18F family can be used to integrate
large amounts of code in a single IC. PIC microcontrollers are
one of the fastest growing parts of the embedded integrated
circuit market in recent times [13]. PIC18F2550 is suitable for
fast implementation controller and can be programmed to
process any type of digital functions and for motor control
applications.
II. SYSTEM DESCRIPTION
As shown in Fig 1, the speed of system depends on the
speed of considered DC motor. So, the main speed control is
to control the speed of considered DC motor. The first step in
simulating the DC motor is deriving its equations of motions.
The actual speed of system will be me
and feedback to microcontroller. In micro
calculate the error between the desired sp
speed then, determine duty cycle of pulse-
(PWM). Finally, the duty cycle will drive t
either accelerate or decelerate system to ma
speed
Fig 1 The block diagram of the sys
A. DC motor
The model schematic representation of t
Motor is shown in Fig 2, where R
a
is the a
L
a
is the armature inductance, V is the vol
motor, i is the current through the moto
electromotive force (emf) voltage, J is the
of the load, b is the viscous friction coeffici
generated by the motor, and is the angu
motor [14].
Fig 2 Schematic representation of the conside
A block diagram representation of the DC m
is shown in Fig 3.
Fig 3 block diagram representation of the
From the Fig 3, the transfer function of co
motor can be written as
2
) . . ( ) (
) (
) (
J R b L S J L S
K
s V
s
s G
a a a
a
+ + +
= =

All motor parameters in this paper
experiment as shown TABLE I .
TABLE I
DC MOTOR PARAMETERS
easured by encoder
ocontroller, it will
peeds to the actual
-width- modulation
to DC motor driver
aintain it at desired

stem
the considered DC
armature resistance,
ltage applied to the
or, V
b
is the back
moment of inertia
ient, T is the torque
ular velocity of the

ered DC Motor
motor in Simulink

DC motor
onsidered DC
2
. K b R
a
+
(1)

are obtained by
Parameters
Moment of inertia of the rotor
Damping (friction) of the
mechanical system
Terminal resistance
Terminal inductance (La)
Electromotive force constant (K
An experiment, as shown in
parameters and characteristic
measuring the data of shaft r
voltage by increasing and dec
from 0 to 36V (rated voltage) an
shows that the lowest armature
and static friction for stating th
0.68V armature voltage can sust
Fig 4 Shaft rotational
The armature voltage for dri
0V to 36V. When the motor ro
the motor will generate the
velocity of motor. The limited
represents the highest angular v
B. Speed Sensor
As shown in Fig 5, the sp
separated parts, the first part
DFRobot, It detects white colou
and black colour to set output a
printed encoder disk, it is prin
one region, those are 32 whi
regions and 32 black regions se
wheel of the system is rotat
proportionally to velocity of wh
sensor will read the transparent
and set output to 0 (0V) for
rotation the output will change
from 1 to 0 proportional to nu
the sensor, this sequential
sequential pulses in proportion
This will give a resolution of 3
these pulses are generated, the
microcontroller to count the nu
by using the pulse-counting met
Values
J = 0.0000885 Nm/rad/s
2

b = 0.00130 Nm/rad/s
Ra = 0.66
La = 0.011791815H
K) K = 0.0941 Nm/A
n Fig 4, is set up to identify the
of considered DC motor by
rotational speed and armature
creasing the armature voltage
nd 36V to 0V. This experiment
voltage to overcome deadzone
he motor is 1V, while at least
tain the rotation.

l speed of DC motor
iving the motor spans between
otates, the encoder attached on
pulses corresponding to the
d maximum armature voltage
elocity at 355 rad/s.
peed sensor composed of two
is line tracking sensor from
ur to set output as TTL signal 1
as 0, and the second part is the
nted with the 5.625 degree for
ite regions set as transparent
et as opaque regions. When the
ted, the disk is also rotates
heel, and then the line tracking
region and set output to 1 (5V)
r opaque region. During this
e the transition from 0 to 1 or
umber of regions were read by
transition will generate the
n to the number of transition.
32 pulses in one rotation. After
ese pulses can be read by the
umber of rotation of the system
thod over a 100ms time period.

Fig 5 Considered speed sensor
C. Half-bridge Driver
In this research, the IRS2103s from International Rectifier
are selected for using as two quadrants ( forward and braking)
driving motor control, It is a high voltage, high speed power
MOSFET and IGBT drivers with dependent high and low side
referenced output channels. The logic input is compatible with
standard CMOS or LSTTL output down to 3.3 V logic. The
output drivers feature a high pulse current buffer stage
designed for minimum driver cross conduction. The floating
channel can be used to drive an N-channel power MOSFET or
IGBT in the high side configuration which operates up to 600
V. This IC is configured to drive the 6 N-channel MOS FETs
(IRF3205); three of MOS FETs are configured in parallel for
driving the motor driven system in forward condition while
other are used for system braking
D. Transmission Gear
The experiment shows that the maximum velocity of
considered DC motor is 355 rad/s or 56 rounds per second. To
reduce this velocity the chain transmission gear is considered.
The motor is attached with the 11 teeth based gear and
followed by the 44 teeth gear which mounted with the tire of
U-Board. The rate of reduction is 4 to 1.
III. CONTROLLER DESIGN
The conventional controllers depend on the accuracy of
the system model and parameters. Fuzzy PID is an approach
depends on mixing the PID controller with Fuzzy controller;
the value of the PID parameters (Kp, Ki, and Kd) will be
evaluated using the Fuzzy controller. A complete design of the
system is shown in Fig 6.


Fig 6 Block diagram of Fuzzy PID controller
Therefore, in this paper, the result from PI controller is
initially borrowed as a-priori knowledge in the design process.
The performance of the Fuzzy PID is the improved by
adjusting the rules and membership functions. The design
procedures are described as following.
A. Procedure 1: Defining inputs, outputs and universe of
discourse
Based on experiment, to apply heuristic knowledge in the
Fuzzy PID, inputs, outputs and universe of discourse are
defined first. Fuzzy PID has one input, which is: Error (E)
(desired speed r actual speed a), two outputs feeding to
the PID parameters (Kp and Ki). The inputs and controlled
output illustrated in Fig 6 are described by:
F = e(k) = m
r
(k) - m
a
(k) (2)
Kp = Kp(k) (3)
K| = K|(k) (4)
where K is the time index.
The experiment shows the maximum speed of system is
40Km/h. the possible error in the range between -50Km/h and
+50Km/h. Therefore, the universe of discourse of E is -
50Km/h and +50Km/h. the universe of discourse of Kp based
on experiment data from the PID controller is 0 and 1, the
universe discourse of Ki is 0 and 0.1, and the Kd is constant
0.000001.
B. Procedure 2: Defining fuzzy membership functions and
rules
To perform Fuzzy PID computation, the inputs and outputs
must be converted form numerical or crisp value into
linguistic forms [4]. The terms such as Small and Large
are used to quantize the inputs and output values to linguistic
values. In this paper, the linguistic terms that used to represent
the input and output values are defined by 5 fuzzy variables as
shown in TABLE II below.
TABLE II
FUZZY LINGUISTIC TERMS
Term Definition
PL Positive Large
PM Positive Medium
PS Positive Small
ZE Zero
NS Negative Small
NM Negative Medium
NL Negative Large

Fuzzy membership functions are used as tools to convert
crisp values to linguistic terms [15,16]. A fuzzy membership
function can contain several fuzzy sets depending on how
many linguistic terms are used. Each fuzzy set represents one
linguistic term. In this research five fuzzy sets are obtained by
applying the five linguistic terms. The number for indication
how much a crisp value can be a member in each fuzzy set is
called a degree of membership, one crisp value can be
converted to be partly in many fuzzy sets, but the
membership degree in each fuzzy set may be different [15,16].
There are many different shapes of fuzzy membership
function. In this project, the triangular and trapezoidal shapes
are used because this shape is easy to represent and requires
low computation time. For performing fine-tuning to improve
the efficient of controller, the adjacent of each fuzzy set value
should overlap about 25% [4].
Instead of using mathematical formulas, a Fuzzy PID uses
fuzzy rules to make a decision and generate the control effort
[4]. The rules are in the form of IF-THEN statements. For
example, IF the error (E) is equal to positive big (PL) and
error change (CE) is equal to positive small (PS) THEN the
output (Kp) is positive big (PL). The matters in defining rules
are how many rules should be used and how to determine the
relation in IF-THEN statements. In this project, the seven
fuzzy sets are used so the maximum possibility of IF-THEN
statements is seven rules. To send out the output feeding to the
PID parameters (Kp and Ki), the output in form of fuzzy sets
must be converted to a crisp value. This process is called
defuzzification. In this research, the center of gravity
centroid method is chosen. The formula of the this method
is

=
=
=
n
i
i
n
i
i i
F
F S
Kp
1
1
(4)

=
=
=
n
j
j
n
j
j j
F
F S
Ki
1
1
(5)
where Kp and Ki are the outputs from defuzzification, S
i
and
S
j
are the specific positions at its fuzzy sets, and F
i
and F
j
is
the membership degree at the position.
C. Procedure 3: Adjusting fuzzy membership and rules
In order to improve the performance of the FLC, the rules
and membership function are adjusted. The membership
functions are adjusted by making the area of membership
function near zero (ZE) regions narrow to produce finer
control resolution [4,8]. On the other hand, making the area
far form ZE wider gives faster control response. Also, the
performance can be improved by changing the rules [4]. The
new seven rules are illustrated as following:
(1) If Error is PL then Kp is Small and Ki is Small
(2) If Error is PM then Kp is Medium and Ki is Medium
(3) If Error is PS then Kp is Big and Ki is Big
(4) If Error is ZE then Kp and Ki are Not change
(5) If Error is NS then Kp is Big and Ki is Big
(6) If Error is NM then Kp is Medium and Ki is Medium
(7) If Error is NL then Kp is Small and Ki is Small
After adjusting the membership functions of Fuzzy PID are
obtained as shown in Fig 7.

Fig 7 Membership function
IV. CONTROLLER IMPLEMENTATION
A. Hardware Aspect
The Fuzzy PID microcontroller uses PIC18F2550 for the
implementation, it is 8-bit microcontroller, the 8-bit wide data
paths, 1K RAM, one 8-bit timer/counter, three 16-bit
timer/counters, 256-byte EEPROM, 4KB Data memory, 32K
Program memory, 2 capture/compare/pulse width modulation
(PWM) , 1 (USART) module, 10 channels10-bit analog-to-
digital (A/D), and 24I/O ports [17,18].
This project Analog-to-Digital Converter Channel 0 (AN0)
pin number2 is selected to be input channels of battery level
sensing. This channel is set for synchronizing with oscillator
input (FOSC), the A/D Conversion Clock Select bits is
selected to 64, and the referent voltage is selected for Vcc
(+5V).
The most important two ports are pin 12 and pin 13 of PIC,
these ports are set as PWM output for generating PWM to half
bridge driver, and these PWM generators are configured to
generate the 1240 herts PWM signal with 10bits resolution.
The range of the output signal waveforms is 0-5V.
Other supported ports such as; PortB bit0 pin 21 is set as
external interrupt input on rising to be a safety switch, PortA
bit2 pin 4 as digital output to drive the power LED, PortA bit4
pin 6 as input counter for counting the pulse of wheel
revolution, PORTC bit6 (pin17) and bit7(pin18) are set as
USART transceiver ports for communication to computer, the
USART communication is configured with Asynchronous
communication, 57600 baud rate, 8 bits data transceiver.
B. Software Aspect
The MPLAB X IDE V1.10 software is
the code writing in C language for sys
software consists of three main module
module, the USART receive Interrupt m
overflow Interrupt module.
The first one is executed only onetim
perform initializations for the program
peripherals, and configures the PIC for spec
The second one is executed every co
request from User (USART) and by Interrup
of portb bit0 which sets as Power OFF
interrupt flags are set, the corresponding I
is served.
The third module interrupts waiting lo
underflow every 100ms. This module the
the Fuzzy PID computation and sets the re
to PWM1 and PWM2 duty cycle. The flow
control system is shown in Fig 8.
Fig 8 Overall process software flow

V. EXPERIMENTAL RESULT
A large number of experiments were c
the basic operation and performance cha
system.
Fig 9 System speed response with 5KM/h d
used to implement
stem. The control
es, the initializing
module, and timer1
me at the startup to
m variables and
cific tasks, etc.
ommand for speed
pt from rising edge
button, when the
nterrupt high level
oop by the timer1
software executes
esult of calculation
wchart of the overall

wchart
TS
conducted to verify
aracteristics of the

desired speed
Fig 10 System speed response
Fig 11 System speed response
Fig 12 Speed response w
Fig 13 Speed response w
Fig 14 Speed response w
Fig 15 System spee

e with 10KM/h desired speed

e with 20KM/h desired speed

when braking in 5KM/h

when braking in 10KM/h

when braking in 20KM/h

ed response in trail
Fig 9 shows the speed response of the system when the
desired speed changes from 0 to 5km/h, the system takes
900ms for acceleration, with the low resolution speed sensor
the system speed varies from 4.48Km/h to 5.3Km/h and vice
versa when the set point speed only 5Km/h fix, it can be seen
the error +0.3Km/h and -0.52Km/h of system with this desired
speed. The same procedure, Fig 10 shows the speed response
of the system when the desired speed changes from 0 to
10km/h, the system takes 1.4s for acceleration, the system
speed varies from 9.8Km/h to 10.7Km/h and vice versa when
the set point speed only 10Km/h fix. The system has error
+0.7Km/h and -0.2Km/h with this desired speed. With the
20Km/h desired speed as shown in Fig 11, the system takes
3.6s to meet the requirement speed, the system speed is
recorded by the speed sensor with the +0.6Km/h and -
0.3Km/h errors. The decelerations of the system in running at
5Km/h, 10Km/h, and 20Km/h are shown in Fig 12 to Fig 14,
in 5Km/h running the system takes 0.8s from running speed to
0Km/h when the 0.9s acceleration times, 1.4s from 10Km/h
running speed to 0Km/h when the 1.4s acceleration time, and
3.7s from 20Km/s to 0Km/h when the acceleration time only
3.6s. Lastly, the Fig 15 shows the trail system speed response
when the desired speeds vary from 0Km/h to 5Km/h, from
5Km/h to 10Km/h, from 10Km/h to 20Km/h, from 20Km/h to
25km/h, from 25Km/h to 30Km/h, from 30Km/h to 10Km/h,
and from 10Km/h decelerate to 0km/h.
VI. CONCLUSIONS
This paper presents the Fuzzy PID controller using
embedded microcontroller for U-Board speed control. The
implemented Fuzzy PID microcontroller works well for
speeds as low as 1KM per hour but fails below this. With the
fixed parameters traditional PID, the response of system
cannot accept for all required speeds, if we adjusted the Kp,
Ki, and Kd for slow required speed then it failed for fast
required speed, when the Fuzzy PID controller can provide the
satisfying for all required speed.
The U-Board can also change from forward to brake, and
vice versa. The time taken for the operation from forward to
brake with maximum speed 30KM per hour is almost 4.5 sec
and brake situation to 30KM per hour forward running is
almost 22 sec. Next, the controller capability of the U-Board
system is experimented and the system was able to run up to
30Km per hour without load and 20Km per hour. Increasing
the system speed by applying the large amount duty-cycle to
motor half bridge driver, the system speed increases a little bit
because of the motor driver smoothly works with PWM duty-
cycle 61% maximum.
REFERENCES
[1] _________. (2012) www.metro-board.com. [Online]. http://www.-
metro-board.com/green_transportation_electric_skateboard.htm.
[Accessed: Mar 22, 2012]
[2] S. Sonoli and K.N. Raju, "Implementation of FPGA based PID
Controller for DC Motor Speed Control System," in Proceedings of
the World Congress on Engineering and Computer Science 2010, San
Francisco, USA, 2010.
[3] S. Raghavan, "Digital Control for Speed and Position of A DC Motor,"
Texas A&M University Kingsvill, MS Thesis 2005.
[4] Y. Tipsuwan and M.Y. Chow, "Fuzzy logic microcontroller
implementation for DC motor speed control," in Industrial Electronics
Society. IECON '99 Proceedings. The 25th Annual Conference of the
IEEE, San Jose, CA , USA, pp. 1271 - 1276 vol.3, 1999.
[5] L.A. Zadeh, "Fuzzy sets," Information and Control, vol. 8, no. 3, pp.
338353, June 1965.
[6] B. Allaoua, A. Laoufi, B. Gasbaoui, and A. Abderrahmani, "Neuro-
Fuzzy DC Motor Speed Control Using Particle Swarm Optimization,"
Leonardo Electronic Journal of Practices and Technologies, no. 15,
pp. 1-18, Dec. 2009.
[7] W. Banks and G. Hayward, Fuzzy logic in embedded microcomputers
and control systems. Canada: Byte Craft Limited, 2001.
[8] B. Hamed and M. Al-Mobaied, "Fuzzy PID Controllers Using FPGA
Technique for Real Time DC Motor Speed Control," Intelligent
Control and Automation, vol. 2, pp. 233-240, 2011.
[9] W. Abd El-Meged El-Badry, "Design and Implementation of Real
Time DC Motor Speed Control using Fuzzy Logic," Faculty of
Engineering, MUST, Research Journal June 2008.
[10] O. Peter, D. Szabolcs, C. Andor, and B. Nandor, "Fuzzy Logic Motor
Control with MSP430x14x," Texas Instruments, Texas, Application
Report SLAA235, February 2005.
[11] J. Charais and R. Lourens, "Software PID Control of an Inverted
Pendulum Using the PIC16F684," Microchip Technology Inc.,
Application Note DS00964A, 2004.
[12] S. Lankton. (2005, Mar.) shawnlankton.com. [Online].
http://www.shawnlankton.com/2005/03/pic-pid-controller/. [Accessed:
Mar 22, 2012]
[13] C. Valenti, "Implementing a PID Controller Using a PIC18 MCU,"
Microchip Technology Inc., Application Note DS00937A, 2004.
[14] __________, "DC MOTOR SYSTEM," Zeltom LLC, Belleville, MI
48111, USA, User Manual release 1.2, June 3, 2010.
[15] A. M. Ibrahim, FUZZY LOGIC for Embedded Systems Applications.
USA: Elsevier Science, 2004.
[16] G. J.Kler and B. Yuan, Fuzzy Sets and Fuzzy Logic: Theory and
Application. New Jersey, USA: Prentice-Hall, 1995.
[17] T. Wilmshurst, Designing Embedded Systems with PIC
microcontrollers, 1st ed. Oxford, UK: Elsevier Ltd, 2010.
[18] Microchip, "PIC18F2455/2550/4455/4550," Microchip Technology
Incorporated, U.S.A, Datasheet DS39617A, 2003.

You might also like