## Documentation Center |

On this page… |
---|

Stateflow^{®} software includes example models with applications
of fixed-point data. For this example, load the model by typing `sf_boiler``sf_boiler` at the MATLAB^{®} command
prompt.

When you simulate the model, you get these results:

To explore the model, follow these steps:

Double-click the Boiler Plant model subsystem block.

The subsystem appears.

The Boiler Plant model subsystem simulates the temperature reaction of the boiler to periods of heating or cooling dictated by the Stateflow block. Depending on the Boolean value coming from the Controller, a temperature increment (+1 for heating, –0.1 for cooling) is added to the previous boiler temperature. The resulting boiler temperature is sent to the digital thermometer subsystem block.

In the Boiler Plant model subsystem, double-click the digital thermometer subsystem block.

The subsystem appears.

The digital thermometer subsystem produces an 8-bit fixed-point representation of the input temperature with the blocks described in the sections that follow.

The sensor block converts input boiler temperature *(T)* to
an intermediate analog voltage output *V* with a
first-order polynomial that gives this output:

*V* = 0.05 × *T* +
0.75

Double-click the ADC block to reveal these contents:

The ADC subsystem digitizes the analog voltage from the sensor
block by multiplying the analog voltage by 256/5, rounding it to its
integer floor, and limiting it to a maximum of 255 (the largest unsigned
8-bit integer value). Using the value for the output *V* from
the sensor block, the new digital coded temperature output by the
ADC block, *T _{digital}*,
is given by this equation:

*T _{digital}* =
(256/5) ×

The Linear fixed point conversion block informs the rest of
the model that *T _{digital}* is
a fixed-point number with a slope value of 5/256/0.05 and an intercept
value of –0.75/0.05. The Stateflow block Bang-Bang Controller
receives this output and interprets it as a fixed-point number through
the Stateflow data

The values for *S* and *B* are
determined from the general expression for a fixed-point number:

*V = SQ + B*

Therefore,

*Q* = (*V* – *B*)/*S* =
(1/*S*) × *V* + (–1/*S*)
× *B*

Since *T _{digital}* is
now a fixed-point number, it is now the quantized integer

(1/*S*) × *V* +
(–1/*S*) × *B* = (256
× 0.05/5) × *T* + (256/5) × 0.75

Since *T* is the real-world value for the environment
temperature, the above equation implies these relations:

*V = T*

and

1/*S* = (256 × 0.05)/5

*S* = 5/(256 × 0.05) = 0.390625

and

(–1/*S*) × *B* =
(256/5) × 0.75

*B* = –(256/5) × 0.75 ×
5/(256 × 0.05) = –0.75/0.05 = 15

By setting *T*_{digital} to
be a fixed-point data as the output of the Linear fixed point conversion
block and the input of the Stateflow block Bang-Bang Controller,
the Stateflow chart interprets and processes this data automatically
in an 8-bit environment with no need for any explicit conversions.

Was this topic helpful?