ST AN677 Application note

AN677

APPLICATION NOTE

Painless microcontroller code by graphical application description

INTRODUCTION

Some electromechanics and automatics engineers hesitate to use microcontroller (MCU) solutions despite their recognised advantages: High integration and flexibility for enhanced features. Their main worry is the unpleasant aspect of MCU application development: Learning, code writing, debugging through quite unconvivial tools.

Fortunately, it is possible today to use these tools (and to keep the genuine integrity of the code issued) through a graphic interface. This new complete toolbox, the ST6-Realizer ®, allows a graphical description of the system, automatic code generation, simulation and debugging.

June 2008

Rev 2

1/14

1 A SMART SENSOR EXAMPLE

An application development is described here as an example which covers general items such as analog data acquisition and treatment with peripheral activation and with operation sequencing. The ST62 family of microcontroller is chosen as target device since it provides all the features needed for this kind of application: A/D convertors, high output current capability and a small package.

The application shown consists of an analog sensor input associated with data treatment issuing two types of information: The relative position, lower or higher, versus a meanpoint or reference value and the amplitude of the difference. This smart sensor can be used in a positioning controller, temperature regulator or any other system requiring as parameters a direction and amplitude.

A basic version reduced to a simple, straightforward data treatment is described. Its main purpose is to present the methodology used and main features of the tool.

Application graphical description

Analysis and code generation

Simulation and validation

In a second step, the response of the system is modified to be compatible with non linear input signals or non linear interfaces.

Finally a self calibration feature is implemented to compensate for imprecision on the input sensor.

These last examples highlight the easy upgrading capability for an application.

2/14

2 A SIMPLE SMART SENSOR

In its basic form, the application features the minimum data treatment: a subtraction is performed between an entered analog value and a constant reference to control an output signal generator. This last circuit drives two external I/O pins according to the subtraction result: Whether the value is positive or negative, only one of the two outputs is activated issuing a squarewave signal with a frequency function of the amplitude of the difference.

2.1 Graphical description

The core of this development methodology is the graphical description of the application. This description uses a standard library allowing a system oriented description; Included are:

Input / Output symbols

Logic / Arithmetic symbols

Oscillators / Pulse generators

State machine for sequencing

With such a library, it is possible to cover most application requirements as long as the time resolution require for the oscillators and pulse generators remains over 10ms, the value used as the time unit. This value defines only the minimum calibrated timebase available and not the speed of the application which is fixed by the MCU quartz crystal frequency and the complexity of the application.

The graphical description follows a decomposition of the application into such basic functionalities; In the present case our needs are for:

One analog input with an A/D convertor

One constant reference

One subtraction operator

One wave generator

Two output pins

No sequencing is required.

The analog input and digital outputs are described by placing the appropriate symbols proposed in the main library of the object menu. The software proposes the MCU I/O pin available in each case: digital or analog inputs, current sink capabilities for output pins, insuring a full compatibility with the selected hardware (Figure 1).

3/14

ST AN677 Application note

Figure 1: Pin Assignment In St6-Realizer Environment

By choosing an 8-bit resolution for the A/D convertor, any analog input value is digitalized into a number between 0 and 255. The constant reference used as meanpoint is described by placing a specific symbol with the value 127.

The subtraction operator and the wave generator are obtained through the same object menu and placed into the schematic.

Eventually, the graphical description is represented in Figure 2.

4/14

Figure 2: Simple Smart Sensor Graphical Description

2.2 Analysis / Code generation

After the schematics capture, an analysis of the graphical description must be launched with the analyse menu. This process first checks the integrity of the description, verifies I/O assignments and connectivity providing on-line information in the case of an error, guiding the user in the development work.

If this first analysis step is successful, all the files related to the ST62 target are automatically generated: The source file in macro-assembler language, the symbol table, the binary executable code. The code generation uses a library of predefined macro-instructions associated to the graphical symbols; thus the time needed from the graphical description to the binary executable code is considerably reduced.

Finally a report file is provided with the Input/Output assignments and the used ROM and RAM. This can help to choose the most suitable MCU for the application. In the present case the report shows 27 RAM bytes and 434 ROM bytes are used, informing the developer about the memory requirement for the MCU and the memory space available for further developments.

5/14

Loading...
+ 9 hidden pages