SinelaboreRT Header Logo


It's better when it's simple!

User Tools

Site Tools


UML-Tool specific Intro

Language Backends



Designers Toolbox

Integrated state-chart editor with auto-layout

Focus on modeling and not on moving states around to create a nice looking diagram! Syntax aware text fields offer a comfortable way to specify actions, guards etc. When the diagram passed the model checker it can be directly simulated. Connect the diagram to the real hardware to monitor the state machine in action.

There are better ways to model state machines than using spread sheets!

In the past different μC manufacturers have published application notes about the benefit of using state machines for the design of embedded software. An example is the application note SLAA402 from Texas Instruments (TI). It suggests to generate source code based on a spread sheet table. Nowadays several affordable UML modeling tools are available supporting the efficient design of state machines in a graphical way. SinelaboreRT generates production quality source code from state diagrams created with many different UML tools. Give it a try!

Latest Changes

Model-based testing of state machines 2020/02/23 19:32 Peter Mueller  
DCF77 Radio Clock 2020/02/23 19:27 Peter Mueller ,
Getting started with a Traffic Lights example on MSP430 - part 1 2020/02/23 19:26 Peter Mueller , , , ,
Astah SysML 2020/02/23 19:22 Peter Mueller  
Generate production quality code from state diagrams created with Enterprise Architect 2020/02/23 19:20 Peter Mueller  
Features 2020/02/23 19:18 Peter Mueller  
Generate efficient source code from UML state diagrams and activity diagrams! 2020/02/22 20:00 Peter Mueller  

Electric Window Lift Controller Example

The following example describes an electric window lift as it can be found in most modern cars today. The example is based on a requirement specification that is provided from Fraunhofer IESE and can be downloaded here. In the document it is stated that the specification has a similar complexity and level of detail as it can be found in real specifications written by car manufactures. But it does not describe a real existing system.

The specification describes a complete door controller. One small part of it - the window lift unit - is modelled here. In fact only the opening of the pane was realized. The closing part is very similar and was left out to make it easier to follow the example. Unfortunately the specification is available in German language only. Therefore the window lift related parts are presented below in English.

Besides showing how the requirements are transfered into a state machine it also shows how to integrate a state machine into a real-time operating system. In this example the Windows emulation of embos from Segger was used.

Electric Window Lift Specification

The movement of the pane is controlled through keys in the car doors. Pane movement continues as long as the stimulus is present or the pane has reached its end-position (either open or close). While closing the pane it is controlled if a barrier disturbes the movement. If yes, the closing operation is stopped and the pane is opened totally (clamping protection).

In reality the number and kind of stimuli depends a lot on the car type. Here the implementation of just one type is shown.

Opening a pane

When receiving an opening command the opening starts if the battery voltage is above 10V. Below this level a “LowBatt” message is sent to the central control unit.

The following cases needs to be considered for moving:

If the command is “pane down manually” the pane will be moved downwards. Downwards movement will be stopped under the following conditions:

  • the down command is not anymore present
  • the pane is totally open
  • there is a new command
  • the movement sensor detects no movement anymore although the window is not totally open and the motor was switched on (an error message is sent in this case)
  • The total traveling time is longer than 3 sec but the pane is not totally open (an error message is sent in this case)

When receiving the command “pane down automatically” the pane will be moved downwards until it is completely open. Downwards movement will be stopped under the following conditions:

  • the pane is totally open
  • there is a new command
  • the movement sensor detects no movement anymore although the window is not totally open and the motor was switched on (an error message is sent in this case)
  • The total traveling time is longer than 3 sec but the pane is not totally open (an error message is sent in this case)
  • It is not necessary that the “pane down” command is pending
  • during the complete traveling time.

Mechanically it is not possible to move the electric window lift command key directly from “pane down auto” into the “not pressed” state. Therefore the command “pane down manual” is ignored up to 0.5sec if the previous position was “pane down auto”. If the command key is present longer than 0.5 sec the mode will be changed to manual moving mode. Releasing the command key afterwards stopps the movement immediately.

The Sample Solution

The figure below shows a possible state chart of the window lift.

The generated state machine is executed in an embos task. Therefore it blocks until an event was recieved. Embos provides several mechanisms for inter task communication. In the example events were used to signal timeouts, pane movement and new key commands. The event selection code is specified in an 'action:' note (see image at the top). The action code is executed at the very beginning of the generated state machine function.

/* action code */
evt = OS_WaitEvent(0xff); // wait blocking
if(evt==1) msg=evTimeoutLongMove;
else if(evt==2) msg=evTimeoutMoving;
else if(evt==4) msg=evTimeoutInter;
else if(evt==8) msg=evMotion;
else msg=keybMsg;

Important! SinelaboreRT does not restrict you in any way on how to send events to a state machine.

The motor is simulated in a second task (see motor.c / motor.h). If the motor is switched 'on' the task sends evMotion events every 20ms. As long as the motor is 'off' the task is suspended and does not send events.

For the supervision timers (long move, moving, inter) embos software timers were used. In their callback functions they simply send the according timeout event to the state machine task.

// Timer handler for the long move timer.
// On timeout send the message to the statechart
void TimerLongMoveFct(void) {

A third task realizes a small test bed by sending commands like (manual down, auto down, …) to the state machine. Several test cases are realized to test the machine. For example entering the manual mode from the auto mode. Another test case tests the 'long movement' requirement.

// This tasks sends simulated user commands.
void SimulatorTask(void){
  extern TUSIGN8 pos;
    Trace("\n\nFirst test. Must result in long move error.");

Running the Example

The example comes pre-built. The executable start.exe can just be started. If started it does not display any output but writes its output to trace.txt which is located under c:\. After execution all test cases (takes about 30s) the program finishes automatically.

File main.c contains the simulation - and the state machine task as well as the code to initialize all tasks, timers etc. In files motor.* the simple motor simulation was realized. All files starting with window_lift.c/h were automatically generated from the state-chart window_lift.cdd. In folder embos the Visual C++ project as well as the embos library can be found.

To rebuilt the state machine files execute

java -jar codegen.jar -p CADIFRA -o window_lift  window_lift.cdd' 

To rebuilt the executable file you have to install Microsoft C++ 2005 Express Edition (or later) which you can download from Microsoft.

Thanks to the people from Segger allowing us to use the windows evaluation version of embos in this example.

If you have comments or questions just send an email to

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
wiki/examples/car_window_lift_controller.txt · Last modified: 2015/11/28 14:52 by pmueller