
27
Some blocks have overflow protection. Blocks like Gain block can saturate the
output if the latter increases or decreases the desired maximum or minimum
values. This is not preferred for code protection since it gives an extra amount of
code lines which takes extra time from the CPU. At the same time it is practical
for critical blocks in the model where the user expect overflow.
Real-Time Workshop Embedded Coder has a convenient way for adding custom
code to the generated code. The user can write custom code to be included in the
header file or the C file of the generated code. The user can write the C-code in
the Custom Code pane of the Configuration Parameters dialog. Another way to
incorporate existing code in the generated code is to use Legacy Code Tool. This
tool transforms an existing C code into C MEX S-function for inclusion in the
Simulink model. If the user does not want to build an S-function from scratch, an
S-function can be built automatically by converting a subsystem into an S-
function. Legacy Code Tool can then be used to include the desired custom code
instead of the S-function used in the Simulink model.
A reference model principle can be used in designing a model in Simulink where
some subsystems are designed as separate models and then added as a model
reference to any kind of design. This results in subsystem saving for reuse in
different projects.
6.3 Fixed-Point Support
Fixed-point is used in microprocessors to represent floating values and a loss of
accuracy often occurs. Scaling is used to convert the real floating value to a fixed-
point value and vice versa.
A value can be, for example, represented as an 8-bit unsigned integer, which
correspond to a range between 0 and 255 (= 12
8
). If the represented value is
between 50 and 150 then almost 60% of the unsigned integer range is unused and
all decimals are ignored when they occur, see Figure 7 below.
Figure 7: Representing a value without scaling
For example the integer representation of 75.7 is, according to the representation
above, 75. A loss of 0.7 can be large depending on the design and the type of the
Commentaires sur ces manuels