Fuzzy Application Library/Technical Applications/Motorola 68HC12 MCU

Demonstration Model of fuzzyTECH Implementation on Motorola 68HC12 MCU

by Philip Drake and Jim Sibigtroth of Motorola AMCU Division, Austin, plus Constantin von Altrock and Ralph Konigbauer of Inform Software Corp., Chicago (8/96)

Citation Reference: The Fuzzy Logic Application Note series is published by Inform Software Corporation on its Internet server to promote the use of fuzzy logic technologies in applications.

This paper presents a demonstration model that demonstrates the usage of fuzzy logic on a Motorola microcontroller (MCU). The 68HC12 MCU was introduced in Q3/1996 by Motorola as a successor to the 68HC11 MCU, one of the most widely used microcontrollers in the world. The HC12 has been enhanced in a number of ways over the HC11 and is the world's first standard MCU that includes a complete fuzzy logic instruction set. The "background debug mode" of the HC12 supports the real-time remote cross debugging (RTRCD) without interfering with the MCU's operation. To support systems design, Inform Software Corp. and Motorola created the fuzzyTECH MCU-HC12 Edition, which supports both the HC12's fuzzy logic instruction set and the HC12 background debug mode. To demonstrate both the usage of the fuzzy logic instruction set and the use of the background debug mode with the fuzzyTECH development system, Inform and Motorola have designed an autonomously guided tank as a demonstration model. This paper discusses the tank's fuzzy logic controller design, as well as the fuzzyTECH implementation on the HC12 MCU.

1. Motorola 68HC12 MCU

This new 16-bit microcontroller family includes four fuzzy logic instructions in addition to the memory and on-chip peripheral functions you would expect in a general purpose microcontroller. The fuzzy logic instructions use existing CPU logic to perform computations including addition, subtraction, multiplication, multiply-and-accumulate, and comparisons, so the speed and efficiency of fuzzy logic programs is greatly improved without increasing the cost of the MCU. A fuzzy inference kernel on the HC12 takes 1/5 as much code space and executes more than 10 times faster compared to an HC11 general purpose MCU.

The MEM instruction computes one fuzzy input based on a trapezoidal membership function in 625 ns. This instruction automatically stores the computed result and updates two pointers so several membership functions can be evaluated without executing any other instructions between labels of a system input. REV performs unweighted min-max rule evaluation on a complete rule list for a fuzzy logic system. REVW optionally allows the user to specify a per-rule weighting factor between zero and one. Since rule lists may include any number of rules, these instructions allow interrupts.

WAV computes a sum-of-products and a sum-of-weights needed for weighted average defuzzification. These sums are left in the correct CPU registers so that an EDIV instruction immediately after WAV completes the final divide to get the weighted average result. Since WAV processes all labels of a system output, it is designed to allow interrupts. The new background debug interface uses a single dedicated MCU pin for bi-directional communication. Memory can be read or written while the MCU is executing an application program. The CPU can also be stopped to allow access to CPU registers and for TRACE and GO commands.

2. fuzzyTECH MCU-HC12 Edition

fuzzyTECH is a family of complete software development systems based on fuzzy logic and NeuroFuzzy technologies [1]. For MCU implementations, fuzzyTECH offers assembly code generation to ensure maximum computational performance using as little memory resources as possible.

fuzzyTECH MCU-HC12 Edition Figure 1: The fuzzyTECH MCU-HC12 Edition is a complete graphical development and debugging environment (large)

The fuzzyTECH MCU-HC12 Edition is a version of fuzzyTECH dedicated to the Motorola 68HC12 family of microcontrollers. In close cooperation with Motorola, Inform's fuzzy logic experts have generated a HC12 code generator that optimally utilizes the fuzzy logic functions of the HC12 ALU.

In many fuzzy logic applications, an implemented control strategy can best be optimized on the running process. fuzzyTECH supports this "on-the-fly" optimization of a running fuzzy logic system with its RTRCD-HC12 Module, an add-on to the fuzzyTECH MCU-HC12 Edition. The RTRCD Module uses the background debug mode of the HC12 MCU to:

  1. Visualize the complete fuzzy logic inference in real time in fuzzyTECH's analyzers and dynamic editors (Figure 1).
  2. Carry out any modification done in fuzzyTECH on the HC12 in real time without interfering with the running process.

3. The Tank Demonstration Model

To demonstrate the implementation and RTRCD optimization of a fuzzy logic system using the HC12 and fuzzyTECH, Motorola and Inform designed a tank model. This tank model guides itself by following a light source using three optical sensors. The tank uses the following periphery:

Figure 2 shows the schematics of the tank demonstration model. The three optical sensors are used by the tank to detect the direction of the light source is shall follow. The sensors are simple light dependent resistors (LDR) coupled to a current source as a voltage divider. The resulting voltage is fed into the analog inputs of the HC12 MCU.

Schematics Figure 2: Schematics of the Tank Demonstration Model (large)

To move and turn the tank, two chains are powered by independent motors. The motor's power and direction are controlled by the pulse width modulation (PWM) outputs of the HC12 MCU via a power stage.

Implementation Figure 3: Implementation of the Tank Demonstration Model (large)

After the mechanical design of the tank was completed and the electrical periphery (sensor signal conditioning and power stage) was completed, the tank's control software was developed. The software of the tank was written in C code using the COSMIC toolkit. The main routine consists of a loop which is called periodically every 10 milliseconds. Within this loop, first the sensor signals are fetched, then the fuzzy logic computation is called, and finally the output of the fuzzy logic computation is fed into the PWM registers.

4. The Fuzzy Logic Controller

The fuzzy logic computation routine is completely generated by the Edition. The C header of the generated function is:

FLAGS TankCntrl( int SensorLeft, int SensorRight, int
SensorBack, * int PowerLeft, * int PowerRight);

Figure 4 shows the graphical design of the fuzzy logic tank controller in the fuzzyTECH development system. The upper left window shows the structure of the fuzzy logic controller. The three inputs of the fuzzy logic system, SensorBack, SensorLeft, and SensorRight, are the light intensities measured by the optical sensors. They feed into the rule block that contains the linguistic control strategy. The two output variables of the fuzzy logic system, PowerLeft and PowerRight, feed directly into the PWM registers of the HC12 MCU.

Controller Development Figure 4: Fuzzy Logic Controller Development using fuzzyTECH (large)

The upper right window shows the membership functions and the defuzzification process of the output variable "PowerRight". The lower window shows the five fuzzy control rules of the system in a spreadsheet-type representation. fuzzyTECH produces the entire system as ready-to-use code for the HC12 by selecting the "Compile" menu item. For a complete development guide for fuzzy logic systems and sample software, refer to [4].

5. Real-Time Remote Cross Debugging

Fuzzy logic provides designers with a technique to use engineering experience and experimental results directly for a system's design. Thus in most applications, a fuzzy logic system can best be tuned, optimized, and verified while running with the real process.

fuzzyTECH supports this development "on-the-fly" with its RTRCD add-on module. The development steps are:

Cross Debugging Figure 5: Real-Time Remote Cross Debugging (large)

6. Conclusion

While the control objective implemented in the tank is not overly complex and could have been solved using different techniques, its fuzzy logic solution, involving only five fuzzy rules, is strikingly simple and transparent. Even more, adding more sensors and actuators in the fuzzy logic controller for more complex operations can be done in very short time.

The new Motorola HC12 MCU is the world's first standard MCU with an embedded fuzzy logic instruction set. Using this instruction set, the fuzzyTECH MCU-HC12 Edition can implement even highly complex fuzzy logic systems using only a few hundred bytes of ROM that compute in less than a millisecond. Such high performance renders the use of dedicated fuzzy coprocessors unnecessary in most applications. Considering the fact that the fuzzy logic instruction set of the HC12 does not come with any price tag attached, the HC12 will enable the use of fuzzy logic in mass-market high-speed applications, such as car engine control, anti-skid brakes, traction control, inter-vehicle dynamics control, hard disk drive control, servo motor control, and cellular phones.

The complete FTL source code of the tank controller and a demo version of fuzzyTECH can be downloaded from the Inform web server [1] to view, test and analyze the fuzzy logic system. On this web server, you also find additional app notes on fuzzy logic in automotive engineering and other application areas. For a complete introduction to fuzzy logic design, refer to [4].

7. Literature

[1] fuzzyTECH Home Page at: "http://www.fuzzytech.com"

[2] Motorola, "CPU12 Reference Manual", CPU12RM/AD.

[3] Motorola, "MC68HC812A4 Technical Summary", MC68HC812A4TS/D.

[4] von Altrock, C., "Fuzzy Logic and NeuroFuzzy Applications Explained", Prentice Hall, ISBN 0-13-368456-2 (1995).