Stateflow | ![]() ![]() |
Fixed-Point "Bang-Bang Control" Example
Stateflow includes demo models with applications of fixed-point data. For this example, load the sf_boiler
demo model ("Bang-Bang control using Temporal Logic") into Simulink with the following steps:
The digital thermometer subsystem produces an 8 bit fixed-point representation of the input temperature with the blocks described in the sections that follow.
temperature sensor Block
The temperature sensor block converts input boiler temperature to an intermediate analog voltage output
with a first-order polynomial that results in the following output:
ADC Block
Double-click the ADC block to reveal the following contents:
The ADC subsystem digitizes the analog voltage from the temperature sensor block by multiplying the analog voltage by , rounding it to its integer floor, and limiting it to a maximum of
(the largest unsigned 8 bit integer value). Using the value for the output
from the temperature sensor block, the new digital coded temperature output by the ADC block,
, is given by the following equation:
Gateway In Block
An examination of the Block Parameters dialog for the Gateway In block shows that it informs the rest of the model that is now a fixed-point number with a slope value of
and an intercept value of
. The Stateflow block Bang Bang Controller receives this output and interprets it as a fixed-point number through the Stateflow data
temp
, which is scoped as Input from Simulink and set as an unsigned 8 bit fixed-point data with the same values for and
set in the Gateway In block.
The values for and
are determined from the general expression for a fixed-point number, which is as follows:
Since is now a fixed-point number, it is now the quantized integer
of a fixed-point type. This means that
of its fixed-point type and results in the following identity:
Since T is the real-world value for the environment temperature, the above equation implies the following identifications:
By setting to be a fixed-point data both as the output of the Gateway In block in Simulink and the input of the Stateflow Bang Bang Controller block, Stateflow interprets and processes this data automatically in an 8 bit environment with no need for any explicit conversions.
![]() | Sharing Fixed-Point Data with Simulink | Calling C Functions | ![]() |