State Flow C Action Language Bitwise Operators

17 ビュー (過去 30 日間)
Tyler Duffy
Tyler Duffy 2024 年 4 月 26 日
編集済み: Yash 2024 年 5 月 7 日
I am trying to use bitwise operators to AND as well as OR an uint value with an int value in stateflow with C action language. I need to use 32 bit values but the results appear to be incorrect with 32 bit values, while 8-, 16-, and 64- bit values all seem to give correct results. Image below shows the stateflow chart and correct results using 16 bit values vs incorrect results with 32 bit values. Am I missing something? Or is this a known issue?
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2024 年 4 月 26 日
It makes me worried. int, uint, and, or, all keywords.

サインインしてコメントする。

採用された回答

Yash
Yash 2024 年 5 月 6 日
編集済み: Yash 2024 年 5 月 7 日
Hi Tyler,
The incorrect results in 32 bit are obtained due to saturation on integer overflow. Upon executing the model, you should notice two warnings in the Diagnostic Viewer, which are as follows:
  1. "Chart containing object '...' has both C-bit operations and saturation on integer overflow enabled. To avoid unexpected results when bitwise operations produce an overflow, disable saturation on integer overflows. For more information, click here."
  2. "Saturate on overflow detected."
Both warnings highlight the same concern regarding saturation on integer overflow. To resolve this, kindly proceed with the following steps:
  • Open the stateflow chart.
  • Right-click on the blank area within the chart and choose "Properties...".
  • Uncheck the "Saturate on integer overflow" option.
  • Run the model again, you should get the correct output now.
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDecision Logic についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by