Implementing Fuzzy Control Systems Using VHDL and Statecharts
Implementing Fuzzy Control Systems Using VHDL and Statecharts
Implementing Fuzzy Control Systems Using VHDL and Statecharts
net/publication/2744861
CITATIONS READS
5 214
2 authors, including:
Valentina Salapura
IBM
106 PUBLICATIONS 1,267 CITATIONS
SEE PROFILE
All content following this page was uploaded by Valentina Salapura on 01 February 2013.
{valentina,volker}@vlsivie.tuwien.ac.at
Abstract The fuzzifier and defuzzifier parts of the system, which incor-
porate a lot of mathematical computations, are described in
In this paper, we propose an approach for designing fuzzy VHDL as a hand-coded design. We assemble the fuzzy con-
controllers. To reduce design time, we employ two high-level trol system, and synthesize a gate level description for field-
design methods: VHDL and VHDL-based logic synthesis, programmable gate array (FPGA) technology.
and Statecharts with a VHDL backend for graphical design This paper is organized as follows: in section 2 we give
description. A fuzzifier and a defuzzifier parts of a fuzzy con- a brief introduction to fuzzy controllers. Section 3 lists de-
trol system are captured in VHDL, as these parts perform sign choices we have made, and section 4 brings a descrip-
complex arithmetical operations. A rule base of the con- tion of the design flow. Section 5 shows how is a rule base
troller is described in Statecharts, and then is translated into of a fuzzy controller described in Statecharts. A fuzzifier and
VHDL. A complete description of the system is assembled in a defuzzifier of the controller are modeled in VHDL, as pre-
VHDL, and is synthesized using VHDL-based logic synthe- sented in section 6, and section 7 brings the translation of the
sis. The efficiency of the generated hardware is explored for rule base to VHDL. Section 8 outlines the testbench genera-
FPGA technology. tion. The developed model is synthesized and implemented
as sketched in section 9. We draw our conclusions in sec-
tion 10.
1 Introduction
2 Fuzzy controllers
Today, still only a few full custom or semi-custom in-
tegrated fuzzy controllers exist and most of them are as- In this section, we introduce a simple controller for a gas
sembled from standard cells at the gate level. Our design heater system, which serves as an example to the various
approach presented here is a high-level one. The usage steps involved when designing a fuzzy controller. The con-
of high-level modeling methodologies for modeling fuzzy troller is sensitive to two input variables delivered by sen-
controllers reduces development time significantly, making sors: the room temperature and, assuming there is no stable
rapid design of custom fuzzy hardware possible. gas quality, the current gas heating value. The controller’s
VHDL [5] for design capture and VHDL-based logic syn- output influences the valve opening angle for the gas supply
thesis are an efficient method for designing complex hard- via an active element, e.g., a servo motor.
ware. However, for describing regular structures like finite- A membership function gives the degree of membership
state machines, a different approach is more appropriate. For of an input value to every fuzzy set. The input may belong
describing such structures, we employ Statecharts. In addi- to more than one fuzzy set. In the example application, the
tion, a commercial tool based on Statecharts incorporates a sensed room temperature is divided into three overlapping
VHDL generation facility for generating synthesizable code. fuzzy sets called “cool”, “tepid”, and “warm”. A similar
We have employed the Statecharts formalism for capturing classification and membership assignment are made for the
a rule base of a fuzzy control system. Using this high-level gas quality, namely “poor”, “medium” and “high”.
approach, design time is reduced significantly, and different In figure 1, we show the calculation of the output variable
designs of the rule base can be explored in the short time. valve angle when concrete values are assigned to the inputs
temperature (denoted i1 ) and quality (denoted i2 ). The value a dedicated chip offers the highest execution speed,
i1 is a member of fuzzy sets “cool” and “tepid” with mem-
bership degrees f11 (i1 ) and f12 (i1 ). For the value i2 , only the design time is short, due to the usage of synthesis and
fuzzy set “medium” is relevant with a membership degree high-level design tools,
f22(i2 ). low cost of real-estate.
The fuzzified input variables are inputs to the rule base.
The sample controller uses nine rules, displayed in table 1, to For designing a rule base of a controller, we have used a
find an output fuzzy set. Rule 32, for example, is interpreted high-level modeling approach instead of encoding it directly
in full English text as: in VHDL. The reasons for this choice are:
if temperature is tepid and gas quality is a high-level design approach reduces the design time,
medium then valve angle is half
global design functionality is evaluated in a short time,
In our example, the rule R21 selects the output fuzzy set
“large” with the membership degree min(f11 (i1 ); f22 (i2 )) different design choices are quickly explored,
and the rule R32 the output fuzzy set “half” with the mem-
bership degree min(f12 (i1 ); f22 (i2 )). edit-compile-debug cycle is fastened [4],
The membership degrees delimit the output set defining an
the design is represented graphically in a natural and un-
area. The solution fuzzy set is composed by combining all
derstandable way,
such areas, and taking the ordinate of the gravitational center
of the area. translation of a high-level model into VHDL is sup-
memb. ported, so that VHDL-based logic synthesis can be em-
degree ployed.
o
existence of tools supporting system modeling in State-
TINY SMALL HALF LARGE HUGE O
charts,
Figure 1. Input and output fuzzy sets. support for validating Statecharts models,
We have used field-programmable gate arrays (FPGAs) as rule_12 C12 rule_22 C22
hardware platform, because they are complex enough to be O1 O2
huge large
4 Design flow and environment memb_ang(0) = min11; memb_ang(1) = max(min21, min22);
huge O1 large O2
The rule base and the fuzzifier and the defuzzifier are
modeled in parallel and separately in different design en-
half
vironments. For designing the rule base we have used the memb_ang(2) = max (min31, min32);
for validating the fuzzifier and the defuzzifier, and for inte-
grated system simulation we employ the Synopsys VHDL small tiny
memb_ang(3) = max(min41, min42); memb_ang(4) = max(min51,min52);
system simulator [8].
The Statecharts model is converted to a VHDL code using small O4 tiny O5
5 A Statechart model of the rule base 6 VHDL models of the fuzzifier and the de-
Each rule of the base has the form: fuzzifier
Figure 4. Part of the VHDL description of a fuzzifier for one input variable.
Figure 5. Part of the VHDL description of a defuzzifier. The division unit is implemented as a function.
multiplexed in time. The decision which approach to use de- mented a 17 by 9 bit division as eight subtractions performed
pends on area and performance constraints. successively.
The defuzzifier is modeled in a similar way. Inputs to the A part of the VHDL description of the defuzzifier is
defuzzifier are vectors, one for each controlling variable. The listed in figure 5. The input is a membership set vec-
range of the vector is determined by the number of the solu- tor (memb_var) and the output is the control variable
tion fuzzy sets – it contains an 8 bit membership degree for (out_var) 8 bit encoded. A finite state machine controls
each output fuzzy set. The defuzzifier determines the gravi- five successive additions and multiplications, and then starts
tational center of the solution fuzzy set, and delivers the re- the dividing unit.
sults as an 8 bit output control signal.
7 A VHDL description of the rule base
In implementing the defuzzifier, we have used the method
proposed by Yager [3]. This approach requires 2N additions, The high-level description of the rule base in Statecharts
N multiplications, and one division, where N is the number is translated to synthesizable VHDL code. The conversion is
of output fuzzy sets of a single output variable. We have re- performed because of the following reasons: having all parts
duced the hardware to two adders, one multiplier, and one of a system in the same language makes the verification of
divider. The adder and the multiplier are multiplexed in time the whole system possible, and logic-level synthesis tools do
to perform 2N additions and N multiplications. not support synthesis from a graphical description.
In our application with one output variable and five fuzzy A part of the code generated from the Statecharts descrip-
sets, we have to perform five additions and multiplications, tion of the rule base is given in figure 6: This code evaluates
before the division can start. The division unit is imple- rule R21 from the rule base. In process Rule_21, the cal-
mented to be fast, at the cost of chip area. We have imple- culation of the minimal membership degrees of the premises
Rule_21: PROCESS (memb_temp, memb_qual, state_large_1)
BEGIN
CASE state_large_1 IS
WHEN S21b =>
min21<= min(memb_temp(COOL), memb_qual(MEDIUM));
WHEN others => null;
END CASE; END PROCESS;
Out_calc: PROCESS(..., min21, min22, out_large, ...)
BEGIN
CASE out_large IS
WHEN o2 =>
memb_ang(1) <= max( min21, min22 );
WHEN others => null;
END CASE; END PROCESS;
of rule 21 is performed. Rule R21 together with rule R22 The proposed method has several advantages:
belongs to the rule group with the conclusion “large”. In
process Out_calc, the maximum calculation for this rule the designer is obliged to spend more thought on the en-
group is performed. vironment of the system, almost as much as in a design
The generated VHDL code is easy to read, and is simi- method based on formal semantics. As he does so in an
lar to hand coded VHDL code. A difference is the usage early design phase, the costs of searching for an optimal
of case statements for encoding rules, instead of an if - solution can be kept small,
then statement, which may be a more natural choice in the
coding process. From the hardware efficiency point of view, high level design tools encourage the use of Statecharts
both coding styles result in the same hardware realization. models not only for the design itself but also for simu-
Another difference is the partitioning of each rule in distinct lation testbenches,
processes.
when reaching the FPGA prototype level, it is much
A graphical presentation of a rule base is much easier to
cheaper to test the system prototype by connecting it
understand, as well as to model, than VHDL. The usage of
to another FPGA prototype of the system environment.
a high-level modeling approach reduces the design time sig-
Especially in an industrial environment where expen-
nificantly.
sive machines are controlled by electronic devices, er-
roneous behavior in the integration test stage may have
8 Simulation and testbench creation
disastrous consequences.
Statecharts are not only suitable for designing state-based
reactive systems themselves but can also be used for specify- 9 Synthesis and technology mapping
ing their working environment and thus may serve as a basis
for testbench development. Instead of developing case stud- After design verification, the Synopsys design compiler
ies and/or test vectors, the designer creates a model of the en- [7] is used to perform logic synthesis. The result of synthesis
vironment and steps down the design process in parallel with is a gate-level description of the controller.
the controller itself. Table 2 shows the results of synthesis of the example fuzzy
The testbench as well as the controller are modeled in the controller with two input and one output variables, and a rule
same way. Like for the controller development, Statecharts base consisting of nine rules. The number of fuzzy sets of in-
can be used as a design front-end for the rule base testbench. put variables is three, and for the output variable is five. The
The controller is then simulated directly in Statecharts or – resolution of all variables is 8 bits.
after VHDL generation – in the VHDL environment. The implementation of the fuzzifier instantiates two fuzzi-
There is a significant improvement in design time and fault fication units, one for each input variable. Each unit contains
coverage compared to standard testing methods. Using the three comparators, an adder and a multiplier. The number of
described method, we were able to implement our design comparators depends on the number of input fuzzy sets. If
controller in a couple of days. The most time consuming area constraints are critical, only one fuzzification unit can be
process was the encoding of the fuzzifier and defuzzifier in used, multiplexed in time, for fuzzifying several input vari-
VHDL. Especially when designing the rule base, the interac- ables. In our design, we have used a separate unit for each
tive testing and observation of the external behavior is eased input variable. The realization is scalable to any number of
considerably. variables.
Synopsys Fuzzifier Rule Base Defuzzifier was captured and verified by simulation using the SPeeD-
Number of gates 1756 1062 2025 CHART design and simulation environment. A simulation
Number of CLBs 136 72 193 under a graphical environment makes it easy to see which
Time delay (ns) 4.75 6.24 4.75 rules are applied. The Statecharts description of the rule base
is translated into VHDL, and integrated with the hand-coded
Table 2. Synthesis results. Number of gates is given VHDL code realizing fuzzification and defuzzification com-
for the LSI 10k library. ponents. Finally, the system model is synthesized to logic
level and mapped to FPGAs.
The most distinctive problem coming up when using the
introduced method is the lack of back-annotation facilities
The defuzzifier calculates one output variable for five
between Statecharts and VHDL. Once the VHDL code has
fuzzy sets. Thus, this implementation performs five multipli-
been generated, there is no way back to the Statecharts level.
cations and additions, multiplexed in time, and one division.
One of the advantages of the proposed method is the sim-
The implementation contains two adders, a multiplier, and a
plicity of constructing and experimentally fine-tuning the
divider. We have implemented a fast divider unit at the cost
rule base. Taking the standard language VHDL as backend
of chip area.
opens all facilities to make use of synthesis tools. Thus, we
A defuzzifier for handling several output variables can be receive all benefits of rapid prototyping and shortening time-
implemented on different ways: a single defuzzifier can be to-market requirements.
multiplexed in time, separate defuzzifiers can be used for
each output variable, or some combination of two. The se- 11 Acknowledgment
lection of the hardware configuration depends on the area and
performance constraints of the particular design. The authors wish to thank to Michael K. Gschwind for his
We have compiled our models targeting two technologies: help with various issues related to VHDL and optimization
Xilinx FPGAs and the LSI 10k ASIC library. For FPGA for FPGAs, and in preparation of this article.
implementation, the measure area efficiency is expressed in
number of CLBs (configurable logic blocks), whereas for References
ASIC in number of gates. [1] A. Costa, A. de Gloria, P. Faraboschi, A. Pagni, and G. Riz-
Comparing our results with the ones of Costa et al. [1] for zoto. Hardware solutions for fuzzy control. Proceedings of
a simple problem (a fuzzy controller with 2 inputs and one the IEEE, 83(3):422–434, March 1995.
output, a rule base with seven rules, and 8 bit resolution) our [2] S. Dart. SPeeDCHART Reference Manual. SPEED S.A.,
implementation is significantly smaller. For the implementa- Neuchâtel, Switzerland, 1993.
tion of a fuzzy controller of comparable complexity, we have [3] M. Figueiredo, F. Gomide, A. Rocha, and R. Yager. Com-
parison of Yager’s level set method for fuzzy logic control
needed only 4843 gates, versus 9392 gates used in the imple-
with Mamdani’s and Larsen’s methods. IEEE Transactions
mentation by Costa. Costa et al. have described their model
on Fuzzy Systems, 1(2):156–159, May 1993.
in VHDL as hand design. [4] D. D. Gajski, L. Ramachandran, P. Fung, S. Narayan, and
Surman et al. [6] have implemented a fuzzy controller F. Vahid. 100-hour design cycle: A test case. In Proc. of the
in FPGAs using hand-optimized CLB-level functional map- European Design Automation Conference Euro-DAC, Greno-
ping. The design shows better results in CLB count, but in- ble, France, September 1994. ACM.
volves more design effort and is thus more error-prone. Full- [5] IEEE. IEEE Standard VHDL Language Reference Manual.
custom reconfigurable solutions such as presented by Watan- IEEE, NY, 1988. IEEE Standard 1076-1987.
[6] H. Surmann, A. Ungering, and K. Goser. Optimized fuzzy
abe [9] make heavy use of repetitive structure elements, but controller architecture for field programmable gate arrays. In
are only feasible in a high number of pieces, offering no flex- S. Verlag, editor, Field - Programmable Gate Arrays, number
ibility. 705 in Lecture Notes in Computer Science, pages 124–133,
1993.
10 Conclusion [7] Synopsys. Design Compiler Family Reference. Synopsys
Inc., Mountain View, April 1995. Version 3.3a.
[8] Synopsys. System Simulator Reference Manual. Synopsys,
In this paper, we have presented a modeling approach for Inc., Mountain View, April 1995. Version 3.3a.
describing fuzzy controllers using Statecharts and VHDL. [9] H. Watanabe, W. Dettloff, and K. Yount. A VLSI fuzzy logic
We have outlined a modeling scheme for designing a rule controller with reconfigurable, cascadable architecture. IEEE
base of a fuzzy controller using Statecharts, whereas the Journal of Solid-State Circuits, 25(2):376–382, April 1994.
fuzzifier and defuzzifier parts of the system were coded in [10] Xilinx. The Programmable Logic Data Book. Xilinx, Inc.,
VHDL. San Jose, CA, 1994.
[11] Xilinx. XACT Xilinx Synopsys Interface FPGA User Guide.
Using the Statecharts formalism for capturing the rule base Xilinx, Inc., San Jose, CA, December 1994.
of a system has been shown to be powerful. The rule base