simulink add block wrong output

2 visualizzazioni (ultimi 30 giorni)
기범
기범 il 23 Gen 2023
Modificato: Paul il 23 Gen 2023
Hello, this is my simulink model
and I cannot understand why my add block output wrong answer
How can I fix it?

Risposte (2)

Nikhilesh
Nikhilesh il 23 Gen 2023
This looks like an issue of Variable solver. Please have a look at the following discussion

Paul
Paul il 23 Gen 2023
Modificato: Paul il 23 Gen 2023
Hi 기범
I think the issue here is mixing together different fixed point data types. Using R2021b
Here's the model, with the data types show on the signal line (Debug -> Information Overlays -> Ports -> Base Data Types)
We see that the inputs to the sum block are all different fixed point data types, which then are added by the sum block to result in some other fixed point type, and the bit pattern of that apparently results in the display of -4.
The fix is to either get the sum block to promote all of the inputs to a common data type that yields the expected result, or change the model so that all of the inputs to the sum block are the same data type that can correctly represent the result. For an example of the former, I added a Data Type Conversion Block to the top line to force a conversion to double. Apparently the sum block the promotes the other three inputs to double using their values before adding and we get the expected answer
Note the output of the sum block is now double. We could also put the DTC block on all four inputs to the sum block, or modify one or more of the four gain block to force their outputs to double via the Ouput data type on the Signal Attributes tab. Or, you can force the Output data type on the Signal Attributes tab of the sum block to double (there are other valid options if you want something other than double); that seems to work as well.

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by