Sunteți pe pagina 1din 6

Instituto Tecnolgico de Chihuahua ELECTRO 2001

REAL-TIME FUZZY MICROCONTROLLER FOR


A DIDACTIC LEVEL SYSTEM

Fernando Lara-Rojo1, Edgar N.Snchez2, Daniel Zaldvar-Navarro1


1) ITESO University.
Perifrico Sur Manuel Gmez Morn 8585
45090 Tlaquepaque, Jal., Mxico.
Tel. 52-3669.3517, Fax. 52-3669.3511
e-mail flara@iteso.mx
2) CINVESTAV. Unidad Guadalajara.
Prolongacin Lpez Mateos Sur 590
45091 Guadalajara, Jal., Mxico.
Tel. 52-3134.5570, Fax. 52-3684.1708.
e-mail sanchez@gdl.cinvestav.mx

1. ABSTRACT. Fuzzy techniques have been fuzzy logic solutions are usually not aimed at
successfully used in control in several fields, and achieving the computational precision of traditional
engineers and researchers are today considering techniques, but aim at finding acceptable solutions
fuzzy logic algorithms in order to implement in shorter time.
intelligent functions in embedded systems. We Fuzzy logic enables users to implement intelligent
have started to develop a set of teaching tools to functions in embedded systems. Typical fuzzy
support our courses on intelligent control. Low cost logic applications are being used to enhance
implementations of didactic systems are existing products with intelligent functions that
particularly important in developing countries. In allow for better adaptation to user requirements.
this paper we present the implementation of a For instance, we can find fuzzy control algorithms
minimal PD fuzzy four-rule algorithm in a low-cost in washing machine control, automatic focusing
8-bit microcontroller, using a fuzzy logic software control, servo motor force control, and many other
development system. On this ground we devices [2]. A primary advantage of an embedded
constructed a stand-alone fuzzy controller for a fuzzy logic control system is that even complicated
didactic liquid level system. We describe the functions can be implemented using the limited
methodology we followed, and present simulation resources of a low-cost general use
and real time results of this controller. microcontroller, instead of an ASIC device or a
dedicated fuzzy microcontroller.
2. INTRODUCTION. Low cost implementations are particularly
Fuzzy logic is a natural, continuous logic patterned attractive in the case of didactic systems for
after the approximate reasoning of human beings. universities of developing countries, where
It is a computational paradigm originally resources can be rather scarce. We are building up
developed in the early 1960s [1]. Fuzzy logic a set of teaching tools to be developed and
allows for partial truths and multivalued truths. It is employed in our courses on intelligent control in
therefore especially advantageous for problems that both our bachelors and masters' programs on
cannot be easily represented by mathematical Electronics Engineering . The fuzzy
modelling because data is either unavailable, microcontroller reported in this paper is our first
incomplete, or the process is too complex. The step in this direction.
real-world language used in fuzzy control enables To the purpose of implementing fuzzy logic control
engineers to incorporate ambiguous, approximate systems in low-cost microcontrollers, we consider
human logic into computers. Using linguistic the smallest possible fuzzy controller, consisting of
modeling, as opposed to mathematical modelling, two inputs, error and change of error ( rate for
greatly simplifies system design and modification. short ), one output, and four fuzzy control rules.
It generally leads to quicker development cycles, The relation between PD controllers and this
easy programming, and fairly accurate control. minimal four rules fuzzy controller has been
However it is important to underline the fact that established in [3]. The four rules fuzzy algorithm

153
Instituto Tecnolgico de Chihuahua ELECTRO 2001

has been successfully used in real time MIMO fuzzy PD controller, originally presented in
applications. In [4], for instance, it was applied to [9].
swing-up an underactuated two-link mechanism. The structure of this MIMO fuzzy PD controller,
There is a wide range of fuzzy logic which is a continuous - time controller, is based on
implementation alternatives [5]. We decided to the two inputs, one output controller shown in
achieve a software implementation on a low-cost Figure 1, from which it can be seen that
general use microcontroller. To this purpose we u (t ) = K u u * (t )
chose the PIC16C711 microcontroller [6] . In this
endeavor we used the fuzzyTECH-MP Explorer [7], (2.1)
which is a fuzzy logic software development where K u is a fuzzy control gain determined by
system for PIC16/17 microcontroller devices. the designer and u * (t ) is the output of the fuzzy
fuzzyTECH-MP Explorer is a limited version of the
fuzzyTECH-MP Edition that allows for the controller.
definition of fuzzy logic rules with a maximum of
Set
two input variables and one output variable. It is point Fuzzify . u y
Ke u*
necessary to develop several assembly code Control
routines to provide for system gains, analog to de/dt
Kr Rules . Plant
rate Defuzzify .
digital conversion, and some other functions
required by the fuzzy control algorithm. We used
the MPLAB [8], which is an integrated
Fig. 1. Fuzzy PD Controller.
development environment for the Microchip
PIC16/17 microcontrollers, to construct, integrate
this code with the fuzzyTECH supplied kernel, and The two inputs are: the error signal e(t ) and its
simulate it. MPLAB was also used to implant the
code into the chip. rate of change e(t ) ; the only one output, u(t), is
We applied the procedure described here (above or fed to the controlled process. Membership
below) to develop a stand-alone fuzzy controller functions are shown in Figures 2 and 3
around the PIC16/17 microcontroller for an respectively, where the same membership function
experimental liquid system. This is a relatively
simple system which requires a two input - one is applied for both e(t ) and e(t ) for simplicity. To
input controller. The stand-alone fuzzy controller employ the same membership function on two
works with a minimal PD fuzzy four rules inputs, two scaling factors, k p and k d , are used to
algorithm embedded in a PIC16C711
microcontroller. We present simulation as well as magnify e(t ) and e(t ) . L and H are two positive
real time results of the system. The fuzzy constants to be determined.
microcontroller showed a satisfactory performance.
The paper is organized as follows : In Section 2 Ke* negative Ke* positive error
error Kr*negative rate
we briefly discuss the minimal fuzzy four rules
10
controller. In Section 3 we describe the assembly
code construction process for the PIC16C711 using
fuzzyTECH-MP Explorer and MPLAB [8]. The
didactic liquid level system is described in Section
Ke*erro
4. Section 5 describes the main points of the r
process for assembler code integration and Kr*rate
Fig. 2 Input membership functions.
construction of a stand-alone fuzzy controller for
this plant. We show real-time results in Section 6.
Conclusions and future work are presented in Negative Zero output Positive
Section 7. 10

2. THE MINIMAL FOUR-RULE FUZZY


ALGORITHM .
For the sake of completeness, we first briefly
review the basic structure and formulation of the H 0 Output (u*)
Fig. 3. Output membership functions.

154
Instituto Tecnolgico de Chihuahua ELECTRO 2001

and some arithmetic functions.


Based on the above membership functions, the A set of assembler code application routines had to
fuzzy control rules are established as follows: be designed to perform the following functions:
(R1). IF e is ep AND e& is rp THEN output is op minimal fuzzy algorithm gains, error and error rate
(R2). IF e is ep AND e& is rn THEN output is oz calculation, A/D conversion, digital filtering, PC
(R3). IF e is en AND e& is rp THEN output is oz set point reading and 128-bit format. The latter one
(R4). IF e is en AND e& is rn THEN output is on is necessary to be able to operate with both
In these rules, e and e& are defined as above, output negative and positive 128-bit numbers
is the output of the fuzzyfication mechanism, u* , in the microcontroller.
ep means error positive and op means This set of application routines was integrated with
output positive, etc. Moreover, AND is the fuzzyTECH generated code in a main program.
Zadehs logical AND . The commonly used The method just described can be directly applied
center of mass formula is employed to defuzzify to develop fuzzy PIC16C711-based
the output of the control action of the fuzzy PD microcontrollers for other two-input one output
controller. systems. To extend it to systems with more inputs
it would be necessary to use the full fuzzyTECH-
3. IMPLEMENTATION OF THE MINIMAL MP Edition development environment.
FUZZY ALGORITHM UNDER FUZZYTECH-
MP EDITION . 4. The liquid level system
As mentioned above, we chose the PIC16C711, The liquid level system is shown in Figure 7
which is a low-cost 8-bit microcontroller, to It consists of a single cylindrical tank with a fixed
implement the fuzzy minimal fuzzy algorithm. The outlet at the bottom. Water is fed into the tank
PIC16C711microcontroller has an A/D converter, through an electric-pneumatic valve. A
1024 bytes ROM program memory, 68 bytes RAM piezoelectric cell is attached to the bottom of the
memory and 20 MHz clock frequency. tank as a pressure sensor. Both the electric- Both
Figure 4 shows the membership functions and the electric-pneumatic valve and the pressure
fuzzy rules for the minimal fuzzy algorithm in the sensor are connected through a signal conditioning
fuzzyTECH project editor window. fuzzyTECH interface, so that the input signal to the controller
generates a runtime code kernel for the actual as well as the output control signal are in the 0-10
fuzzy logic project . It consists of the routines volts range.
required for fuzzification, inference,
defuzzification, management of RAM memory,

Fig. 4. The minimal fuzzy algorithm in the fuzzyTECH project editor window.

155
Instituto Tecnolgico de Chihuahua ELECTRO 2001

Fig. 7. The liquid level system.

A simple model for the tank is given by


dh(t )
qe (t ) = A + Ao 2 gh(t )
dt
This model was simulated under MATLAB /
SIMULINK in order to determine the input and 5. THE STAND-ALONE FUZZY
output gains Ke , Kr y Ku, , as well as the constant MICROCONTROLLER
L, which have to be integrated in the fuzzy The input and output gains Ke K,r y Ku, previously
algorithm for this system. We obtained rather obtained for the liquid level system were
good results with the following values for the incorporated in the design of the fuzzy controller,
constants : Ke = 60, Kr =1, Ku = 2, L = 127 . and then in the assembler code generated,
Figure 8 shows the system behavior with a square following the procedure described above.
reference signal that starts from zero (tank empty), In our implementation, the fuzzyTECH supplied
and then fluctuates between 64.5 and 32.75 cm. code (basic fuzzy logic routines and kernel)
These values were chosen in order to directly requires 313 bytes. The code for the auxiliary
compare the results with corresponding routines is 224 bytes long. Hence, the total length
experiments calculated on an 8-bit base, which is of the fuzzy algorithm code is 537 bytes, which
the word length of the PIC16C711 amounts to 53% of the PICs program memory.
microcontroller. The same reference signal values There still remain 487 bytes of the PIC16C711
program memory, which are available for other
purposes.
The present implementation was conceived for
Height in centimeters

demonstration purposes. For this reason we


arbitrarily restricted the possible values of the
reference signal to the two values mentioned
above (32.75 and 64.5 cm), which are to be
commuted with a single bit signal. This restriction
can easily be lifted with the help of a small extra
Time in seconds routine to capture and use arbitrary reference
signal values. The stand-alone PIC16C711-based
Fig. 8. Simulation with a square reference fuzzy microcontroller was constructed on a 6.5
signal cm x 6 cm board.The power supply was
were used later for the real time experiments. constructed on a separate module. The

156
Instituto Tecnolgico de Chihuahua ELECTRO 2001

microcontroller board is shown in Figure 9. Both 6. REAL TIME RESULTS


microcontroller board and power supply can be The experimental layout for the real time test of
used in other experimental control applications in the stand alone fuzzy microcontroller is shown in
two input - one output systems. A simple PC- Figure 10.
based monitoring interface was also developed. Figure 11 shows the real time results with a
This monitoring interface was used to capture and similar reference signal as that used in the
display the real time results presented in Section simulations. One can observe a fairly good
6. approximation to the top and bottom values of the
reference signal. Numerical results are presented
in the table of Figure 12. No further adjustment
for the gain values was necessary. There are some
discrepancies in the rise and fall times. This can
be attributed to the roughness of the model used in
the simulations, in particular to the fact that it
does not take into account a more accurate model
for the behavior of the electric-pneumatic valve.
The results show nevertheless that the
implementation of the fuzzy minimal algorithm in
a low-cost microcontroller, can be successfully
applied to control tasks in a similar range, which
require sample times not less than 10
microseconds.
Based on this experience, we are able to easily
reprogram the stand-alone fuzzy controller board
produced in this project and are planning to apply
this technique to other two input - one output
Fig. 9. Fuzzy microcontroller board. control tasks in our laboratory.

voltage / current

current / pressure
5V
Control signal
-5V 0-10 volts

10V

-10V

GND

Power source 0-10 volts


Level signal

Reference signal

32.75 or 64.5

Fuzzy microcontroller current / voltage

Liquid level system


pressure / current

Personal Computer

Figure 10. Experimental layout.

157
Instituto Tecnolgico de Chihuahua ELECTRO 2001

stand alone controller in other experiments. We


also intend to apply a similar technique to plants
with more than two inputs.

Remarks :
fuzzyTECH and MPLAB are registered trademarks of
Inform Software Corporation.
PIC is a registered trademark of Microchip Technology
Inc. in the U.S.A.
MATLAB/SIMULINK is a simulation tool developed
and distributed by The Mathworks Inc., 24 Prime Park
Way, Natick, Mass. 01760; http://www.mathworks.com
IBM and PC are registered trademarks of International
Business Machines Corporation.
Fig. 11. Real time results 8. REFERENCES .
[1] L.A. Zadeh, Fuzzy sets, Information and Control,
vol. 8, pp. 338-353, 1965.
Fig. 12. Numeric real time results [2] J. Yen, R. Langari, and L.A. Zadeh, Industrial
Applications of Fuzzy Logic and Intelligent Systems,
IEEE press, USA,1995.
Reference Real time value [3] H. Ying, and W. Siler, "Fuzzy Control Theory: A
( set point ) Nonlinear Case", Automatica, Vol.26, No.3, pp. 513-
520, 1990.
64.5 cm 64.2 cm [4] E. Snchez, L.A. Nuo, Y.-C. Hsu, and G. Chen,
"Real Time Fuzzy Control for an Underactuated
32.75 cm 33.0 cm Robot", IV Joint Conference on Information Systems,
Research Triangle Park, N.C., U.S.A., 1998.
[5] A. Costa, A. De Gloria, P. Faraboschi, A. Pagni, G.
7. CONCLUSIONS . Rizzotto, "Hardware Solutions for Fuzzy Control",
Proc. IEEE, Vol. 83, No. 3, pp. 422-434, 1995.
We have started to build a set of didactic tools to
[6] fuzzyTECH-MP, User's Guide, Microchip
support our courses on intelligent control. As a
Technology Incorporated, USA, 1994.
first step we have
[7] PICmicro Mid-Range MCU Familiy Reference
undertaken the construction of a fuzzy
Manual , Microchip Technology Incorporated,
microcontroller. In this approach we have taken
USA, 1997.
into consideration low cost implementations [8] "MPLAB IDE, Simulator, Editor. USER'S
which are particularly attractive for educational GUIDE", Microchip Technology Incorporated,
purposes in developing countries. We USA, 1996.
implemented a minimal fuzzy four rules control [9] Y. Hsu, G. Chen, E.N. Sanchez, "A fuzzy PD
algorithm in a low-cost microcontroller, and built analysis for multi-link robot control: Stability
a stand-alone fuzzy controller for a didactic liquid analysis", Proc. 1997 IEEE Intl. Conference in
level system. We selected the PIC16C711 as the Robotics and Automation, pp 1412-1317,
target microcontroller. We used the fuzzyTECH- Albuquerque, New Mexico, USA, April 1997.
MP Explorer software development system to
implement the basic fuzzy control algorithm, and
MPLAB IDE for the design of auxiliary assembly
code routines and integration of the whole system.
The code for the liquid level system controller
required only 537 bytes of program memory.
Sample time must not be less than 15
microseconds. The real time performance of the
fuzzy autonomous controller is very satisfactory.
Based on this experience, the controller can be
easily reprogrammed and adapted to other control
tasks. As future work we consider to apply the

158

S-ar putea să vă placă și