Wrap/Saturate on overflow

29 Ansichten (letzte 30 Tage)
Giuseppe Galioto
Giuseppe Galioto am 21 Dez. 2019
Kommentiert: Walter Roberson am 13 Jan. 2020
Hi there,
I'm trying to simulate a control algorithm with the fixed point tool. When I apply the fixed point data types and try to simulate the model, I get many wrap/saturate on overflow warnings. What's the right method to avoid overflows and fix them?
Thanks in advance
  1 Kommentar
Walter Roberson
Walter Roberson am 21 Dez. 2019
Bearbeitet: Walter Roberson am 3 Jan. 2020
Typically there are two ways to approach this:
  1. Increase the permitted range for your fixed point objects, so that they do not overflow; Or
  2. Re-examine the mathematics of your equations to figure out why you are getting overflows, and repair the algorithm
It is not uncommon that you need to do both of those -- not uncommon that when you examine your code in detail that you find some mistake in it, but that you also find some reason why it is reasonable for the control values to need to go outside the range you have permitted.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

MathWorks Fixed Point Team
I think it’s important to understand if these overflows are a concern in the context of the numerical behavior of your control algorithm i.e. Is the fixed point response within a reasonable tolerance compared to the floating point response?
If the answer is no, you can try two quick things:
  1. Increase the word length choice in the Fixed-Point Tool to check if greater precision improves the numerical behavior or
  2. Specify a larger safety margin that will accommodate for a larger operating range as Walter suggested (see image below)
safety_margin.png
It might help to check out these how to videos on Fixed-Point Tool:
  3 Kommentare
Evangelos Denaxas
Evangelos Denaxas am 13 Jan. 2020
Hello Giuseppe, if your model is already in fixed-point you can try to collect simulation ranges using the data type override feature offered by fixed-point tool. Data type override is a feature that allows you to quickly override all specificied data types in a model with either double or single for quick debugging of issues similar to yours. When you do that you can use the fixed-point tool's histograms to see where you would potentially have your overflows happening and where your underflows would appear to be most significant.
You can follow the steps below
  1. enter fxptdlg('fxpdemo_feedback/Controller') on your MATLAB command line
  2. Within the fixed-point tool find the green 'play' button and select "Collect Ranges". (If you click on the little black arrow on the bottom right of the green play button you'll see that the default option for the tool is to enforce "Data Type Override to Double" which means even though the fxpdemo_feedback model has fixed-point data types specified, the simulation will run in double).
d1.png
3. Notice how the result "Up Cast" has a histogram that is marked with a red arrow. That signifies that the ranges we collected using double precision would have overflowed if we were to use the specified data type that is currently on the model (hence it is marked as "Potential Overflows" on the right panel). This can help you spot where your overflows might occur.
d2.png
4. Then you can propose a data type using the Propose Data Types button. The fixed-point tool will use the ranges you collected in double and will thus avoid the overflow for the "Up Cast" block.
You can try to follow the same steps with your model and see what you get! Hopefully this helps!
Walter Roberson
Walter Roberson am 13 Jan. 2020
Thanks, Evangelos, that is useful.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by