Anda di halaman 1dari 3

Stateflow a Useful Tool for Developing New Logic Algorithms. Case Study: Building a State Machine for Windscreens.

Software System
Claudiu Munteanu , Gheorghe Livin and Gabriel Chiriac
Department of Electrical Engineering Technical University of Iai 700050, Iai, Romania E-mail: clau_matrix_00@yahoo.com

Abstract - This paper is about how we can develop a new software design without using all standard steps of a V-cycle or to add new methods to test and verify the model against the requirement. For that purpose we chose case study and we reveal how that thing is doing. All subsystems without one exception are built in Stateflow. The microcontroller subsystem has five peripheral implemented and two logical charts for interruption and priority interruption system. Stateflow is a very useful tool to create complex algorithms, to interact with C and C++ and he can predict all feature steps if you now the present state. Keywords - ANSI-C, microcontroller, chart, linearization, ISR, integrate, PID, C programming language and Object Orientated Programming

There are some important subsystems: timer peripheral, input capture peripheral, input-output peripheral, Interrupt Service Routine controller, Interrupt Priority controller, ANSIS chart and windows logic implementation. In Fig. 1 is depicted the requirements word document.

I. INTRODUCTION In the very beginning we can make a short introduction about V-cycle which has a great interest in developing new software. V-cycle has some steps: first of all is the requirements step next is design step, implementation state, testing and the final one is verification and validation stage. The requirements stage needs some documentation received from customers. Based through documentation we can analyze the functional and the non-functional requirements and then to make the linkage between word document and matlab. II. REQUIREMENTS AND C FUNCTIONS Every connection maintains the relation between software model and documentation throughout V-cycle. In our requirements list there are only functional elements but in real software development it is necessary also some non-functional statements like: shape, aesthetics and so on. Our case study is about a windows system which has some functions: up-down window for four passengers, parents control, detect object. The entire system is made of charts in Stateflow.

Figure 1. Requirements

Next step is to develop the model based design and this thing is built with Matlab environment. First step is to implement the ANSI-C code state chart. The state chart is composed from initial state, running state and final state. The purpose of the first state is to initialize the C function. Stateflow has one major feature and that is the C function import. So with this functionality is easy to implement easier and faster our code. It is not necessary anymore to develop the model, to convert into z model and finally to generate code. Init function is made in C programming language, it has a header and a C file. In header there are defined the bit fields which are referred to peripheral registers as we can see depicted below (Fig. 2).

The while loop it`s composed of PID function and fun function. PID function is the C function which implements the behavior of a PID controller. The kp is the proportional gain, the ki is the integral gain, err is the difference between reference and measure values, the I is the integral value which is represented by a sum of errors. The C algorithm is implemented in Fig. 4.

Figure 2. Bus header

For example the ISR register contain four fields. All fields are made to call interrupts when the interrupt enable bit is set. The C source file is showed in Fig. 3 and we can see the definition of struct function and also the initialization of fields of interest.
Figure 4. C PID function definition

The sum of P and I are limited between some maximum and minimum values. The ANSI-C chart act like a C function which then is compiled and linked results an object file. The hex file is used to programming the microcontroller. We use the C program model and the microcontroller hardware model in the same environment. III. MAIN PROGRAM The ANSI-C chart contains the algorithm used to control the microcontroller in the way that we want (to detect object and to react etc.). The brain of model is ANSI-C chart which is depicted in Fig. 5.

Figure 3. Bus C function definition

In the same time all of structures are gathered in one new structure which is named bus. This (bus) structure is a data bus because this one manages and controls the behavior of the bit fields throughout of peripheral simulink systems. Init function is called by reference and is a very useful thing because we work with pointers inside of chart. We can use all of kind of pointers: pointers to structure, pointers to array, multilevel pointers and so on. Stateflow has some control flow pattern but together with pointers, unions, structures and bit operations we can model complex structure for embedded systems.

Figure 5. ANSI-C main chart

The final state is called terminate and is active when the simulation time is two hundred. The while loop is made with Stateflow pattern it is running only for two hundred seconds. When start_program variable is in high position than the state of chart is passing to the next state and after that when simulation time reach the threshold the animation and the simulation is over. The interaction between header definition and bus system from Simulink is made with an interface where user has to make the fields regarding to structures. For example next picture (Fig. 6) details how is made this procedure.

Figure 7. PID Tunning

The above picture describes how tuning process is made. We only has to slide the rapidity of controller and the kp, ki, Ts are generated automatically. In addition the graphical user interface gives us a lot of information of quality parameters: stability, rise time, steady state response, overshot, undershot.
Figure 6. Bus definition GUI

IV. CONCLUSION The interaction between C and Stateflow is a very useful strategy to build complex structure or to represents the behavior of the system. I used a lot of new methods for developing in matlab and I worked in Stateflow tool, Simulink tool.

As we can see the entire bus model is a nested structures which has three layers: the high layer is named bus which contain nine fields and every field contain register fields.In our study case we tried to use different ways for testing and validation than V-cycle standard software development. Matlab offers some benefits like: using physical design instead of mathematic design. So I use as possible I could to use logical model instead mathematical design. Our model is divided into three major parts: the C code, microcontroller part and vehicle subsystem. The vehicle subsystem is the mathematical model of vehicle. This model was initial a physical system formed from physical parts: diesel engine, transmission, torque convertor, gear speed, differential and wheels. This system is linearized to obtain a linear model. Based on this model we tune the PID controller and the constant gain, integral gain and sample time (Fig. 7).

REFERENCES
MATLAB Stateflow Toolbox Users Guide [Online]. [2] MATLAB SimDriveline Users Guide [Online]. [3] www.mathworks.com [4] http://ocw.mit.edu/courses/

[1]

Anda mungkin juga menyukai