Stateflow    

Tips and Tricks for Using Fixed-Point Data in Stateflow

Once you specify fixed-point data (see Specifying Fixed-Point Data in Stateflow), you can use it just as you would any data in Stateflow. However, because of the limitations of fixed-point numbers, it is a good idea to follow these guidelines when using them:

  1. Develop and test your application using double- or single-precision floating-point numbers.
  1. Using double- or single-precision floating-point numbers does not limit the range or precision of your computations. You need this while you are building your application.

  1. Once your application works well, start substituting fixed-point data for double-precision data during the simulation phase, as follows:
    1. Set the integer word size for the simulation environment to the integer size of the intended target environment.
    1. Add the suffix 'C' to literal numeric constants.

  1. When you simulate, use overflow detection.
  1. See Overflow Detection for Fixed-Point Types for instructions on how to set overflow detection in simulation.

  1. If you encounter overflow errors in fixed-point data, you can do one of the following to add range to your data.
  2. If you encounter problems with model behavior stemming from inadequate precision in your fixed-point data, you can do one of the following to add precision to your data:
  3. If you cannot avoid overflow for lack of precision, consider using the := assignment operator in place of the = operator for assigning the results of multiplication and division operations.
  1. You can use the := operator to increase the range and precision of the result of fixed-point multiplication and division operations at the possible expense of computational efficiency. See Assignment Operator :=.


  Specifying Fixed-Point Data in Stateflow Offline and Online Conversions of Fixed-Point Data