Simple Stateflow Example

A simple example of stateflow is illustrated. The stateflow models unipolar to bipolar signal encoder.

Matlab simulink has stateflow where you can model your system functionality or algorithm. We will show you simplest example in stateflow. The stateflow models an encoder that transforms binary message in unipolar form into bipolar signal.

A unipolar source outputs 1 and 0 like binary message from a digital circuit. The output can then be encoded into bipolar signal for various reasons, for example, reducing noise. The bipolar signal has signal 1 and -1. In this case, the encoder outputs -1 when it encounters a 0 in the incoming message. When the input is 1 the output remains unchanged.

In Simulink, we can make the following model which includes stateflow chart.

Simple Stateflow Example

The stateflow chart is the middle one which is labelled as Encoder. You can get this from the Simulink library > Stateflow. When you insert it into the simulink model, it will say Chart but here we have renamed it to Encoder.

The Random Integer block outputs 1 and 0 randomly. This is our message signal. These enters the encoder. u is the input and y is the output port of the Encoder stateflow diagram. To view the stateflow diagram just double click it. When you do so you will see the inside of the stateflow chart with a pink background. Inside it you put the states, transition, events etc to model your functionality of desired system. In our case it is a unipolar to bipolar encoder. This is shown below.

Simple Stateflow Example

To put the states click and drag the state(rounded box) into the chart.

Simple Stateflow Example

Similarly you can drag into other stateflow tools such as default transition arrow.

Now by creating two states called A and B and connecting them via transition arrow we can create the encoder. In the first state A, the output is -1 and the 2nd state B the output is 1. This is done with the help of keyword ‘entry’. Then on the transition arrow we write the condition for transition from A to B and vice versa. The transition condition is written inside square brackets. To write you have to double click on the transition arrow. For our purpose, the transition from state A to B should occur when the input u is 1 and transition from state B to A when the input is 0.

By saving and clicking on the Run button you will see how the state transition. This is shown below.

To see the result we can view the scope output as shown below.

As you can see, the output is -1 when the input is 0 and 1 when the input is 1.

Hopefully this illustrated the concept of stateflow in Matlab simulink.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *

Simple ways to convert 5V to 3.3V using diodes

Simple ways to convert 5V to 3.3V using diodes

MPLAB Harmony System and Client Driver Handle

MPLAB Harmony System and Client Driver Handle