ARTICLE ELECTRONIC DESIGN (October 23, 1997)
 
UPDATE ON EMBEDDED FUZZY LOGIC TOOLS


Fuzzy Logic Tool Teams With Silicon For Compact Embedded Designs

The combination of a rich graphical development tool, along with specialized instructions added to a 16-bit microcontroller, may make it practical to use fuzzy logic in embedded applications previously not possible. Motorola's 68HC12 includes instructions for fuzzy logic. The fuzzyTECH development tool from Inform, Aachen, Germany, generates 68HC12 assembly code. The combination of the two allows designers to attack fairly complex and nonlinear applications with a well-integrated, low-cost microcontroller.

The 68HC12 is a superset of Motorola's 68HC11. Binary 68HC11 code will run on the HC12, and HC11 source code will be accepted by the HC12 assembler with no changes. Four instructions were added to the HC11 instruction set: MEM for fuzzification, REV and REVW for non-weighted and weighted rule evaluation, and WAV for weighted defuzzification. These four instructions enable a large amount of compact fuzzy processing. A trapezoidal membership function can be defined by four 2-byte values. The first two values represent the beginning point and the slope of the leading edge of the trapezoid, each to 1~ bit resolution. The second two values represent the slope and end point of the tralling edge. The MEM function keeps track of the number of membership functions associated with each variable in the fuzzy rule set. It compares the variable's I value to each assigned membership function, calculates its degree of member-ship, and stores the results.

Rule evaluation on the HC12 uses a fuzzy logic approach called the MIN-MAX method which takes the minimum antecedent in any individual rule as the overall truth of that rule. In cases where rules are assigned weights, i.e., where one rule has more influence on the outcome than others, the REVW instruction multiplies the result of each rule evaluation by a fraction representing its relative importance before sending it to the fuzzy outputs.

Once the outputs of the rule evaluation are combined into a composite output, the WAV instruction computes a single, "crisp" output value. While there are a number of different "defuzzification" methods, the HC12 uses the singleton method. For each membership function in the output, it takes the "singleton" or height of that trapezoid at its center. The crisp output is calculated by averaging the output values of the singletons weighted by their heights.

The software that performs fuzzyfication is the fuzzy inference kernel. The kernel's size depends on the number of rules, the number of antecedents (IF, AND, OR), the number of consequences (THEN) per rule, and the number of input and output variables and member-ship functions assigned.

Using the fuzzy instructions on the 68HC12, a fuzzy control example employing two input variables and one output variable with seven membership functions each, and 17 rules, each with two antecedents and one consequence, is compiled to 54 bytes. It ran an evaluation in about 66 µs at 8 MHz. The same control example on the 8-bit 68HC11 compiled to 262 bytes and ran in about 75O µs at 4MHz. Part of the difference is in the code.

Embedded fuzzy logic has been implemented using a fuzzy coprocessor and a standard microprocessor; but inter-chip communication overhead and costs have been high. Other approaches involve high-speed 32-bit processors, appropriate for some cases but not for small, cost-sensitive applications.

The Motorola/Inform combo is aiming at low-cost, high-speed applications such as anti-lock braking, disk-drive head-positioning control, and auto ignition control. These applications have complex, often nonlinear, problems along with very short control-loop requirements, where a traditional mathematical model would be too slow. Fuzzy logic on a fast, 16-bit microcontroller can often do the job at a speed and cost point that is practical for the application.

The fuzzyTECH development tool provides a completely graphical environment for creating and editing rules, setting up membership functions, implementing inference methods, and selecting defuzzyfication techniques. Some of these steps are enhanced by design wizards. For example, the Fuzzy Design Wizard prompts the user with a series of dialog boxes to generate a fuzzy system prototype. Another wizard, the Fuzzy Variables Wizard, assists in creating complete variable definitions.

The linguistic variable editor lets you assign a name to an input variable and define its membership functions (see the figure). Both the variable and the membership functions have linguistic names. For example, the variable "temperature" might have membership functions called "cold," "cool," "comfortable," "warm," and "hot." Each membership's function is drawn as a graph representing the degree to which any given temperature value satisfies the concept of "cool," "warm," and so on (see "Fuzzy logic makes a decision"). These are the degrees of membership, or degrees of "truth," used in fuzzy inference. Fuzzy logic performs logical operations using degrees of truth rather than absolute ones and zeroes..

Once variables are defined, they need to be combined in logical rules of a form like: "IF Speed is High AND Tree is Near THEN Brake is Hard." The actual values associated with high speed and the nearness of the tree will determine the actual hardness to be applied to the brake. The output of this one rule will then be combined with the outputs of other rules to determine the final, crisp, result. The fuzzyTECH tool provides three different editors for creating and modifying the rule base. One editor uses a spreadsheet format that can provide a good overview of small rule bases. For more complicated applications, there is a matrix rule editor that lets you work with entire slices of the rule base at once. Rules also can be edited in a text format using Inform's hardware-independent Fuzzy Technology Language.

There also is a choice of inference methods, including MIN-MAX described above and MAX-PROD. There also is a set of operators for rule aggregation, including compensatory operators which more closely represent human decision making. Defuzzification techniques include the singleton method described, plus others like the center of gravity and the mean of maximum method used in pattern recognition.

Also included in fuzzyTECH are interactive optimization tools for system tuning. A 3D plot lets you see the behavior of system outputs relative to inputs, and a statistical analyzer shows how frequently individual rules are firing and helps identify redundant or unneeded rules. The debug mode gives access to all the rule editors, membership function editors, and other editors to let you dynamically see the status of any given element while the system is running.

You also can modify a rule or membership function on-the-fly and observe resulting behavior. The fuzzyTECH version for the HC12 has a cross-link debugging mode that uses the chip's background debug mode (BDM) port for accessing memory to fine-tune a running system. This avoids interference with system operation that would occur if you used a serial port. For instance, you can change the shape of a membership function associated with a variable and observe the change in the system's behavior. At the same time, you can see the results in a trace window inside fuzzyTECH.

Motorola supplies a $99 evaluation board (68HC912B32), bundled with a copy of the limited-function Explorer version of fuzzyTECH HC11/12. The full version of plus add-on modules for neuro-fuzzy systems, real-time optimization, and data analysis starts at $2290.

Contacts :Motorola MCU Information, P0. Box 13026, Austin, TX 78711; (800) 765-7795, X985; http://www.mcu.mot-sps.com. Inform Software (U.S.), 2001 Midwest Rd., Oak Brook, IL 60521;http://www.fuzzytech.com.TOM WILLIAMS


Fuzzy Logic Makes A Decision


Many factors can go into deciding how to cool a room. Among them are temperature, humidity, light intensity, and the number of people in the room. Then there are options for accomplishing the goal: how much to run the compressor, fan speed, if and how far to open vents, and so on.

In this simple example, two rules in a fuzzy application have determined, on the basis of their input values, two different fan speeds-5O rpm falls in the "medium" membership functions, while 90 rpm falls into "fast." There could possibly be another category "real fast," if desired.

The two rules in question might have been something like:

  • IF Temp is High AND Humidity is Medium THEN Fan is High
  • IF Temp is High AND People is Low THEN Fan is Medium
Note, however that the degree of truth (the vertical axis) output by each rule is less than 100%. One rule determines a speed of 50 rpm to only 25% while the other recommends 90 rpm to 75%. The latter rule will thus have more influence on the final outcome, but the first rule will also contribute.

The singleton method averages the two output values weighted by their heights. The corresponding outputs for fan speed are resolved as shown (see figure)

 [(50 x 0,25) + (90 x 0,75)] / (0,25 + 0,75) = 80

In this case, the final fan speed would be 80 rpm.


Conclusion