Simulink ADD block keeps returning 255
3 次查看(过去 30 天)
显示 更早的评论
So I have two inputs 'Pre-State' and 'Pre-Status'. The values going into the ADD block are '1' and '0' respectively, yet for some reason the ADD block keeps returning 255.
The ADD block is setup so that 'Pre-Status' is subtracting 'Pre-State'. So in theory, the output should be -1. Yet it keeps giving 255 for some reason.
1 个评论
Fangjun Jiang
2022-12-12
Some settings are not right. You have to show it. I guess it is the data type of the output and the saturation flag.
回答(1 个)
Andy Bartlett
2022-12-13
My guess is that Sum block's output data type is uint8, and the block is configured to wrap on integer overflows.
So the output would be module 2^8 of the "ideal output result".
idealOutput = -1
actualOutput = mod(idealOutput, 256)
We could also test this theory with Fixed-Point Designer fi objects.
nt = numerictype('uint8')
fiOutput = fi( idealOutput, nt, 'OverflowAction', 'Wrap', 'RoundingMethod', 'Floor')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!