Simulink ADD block keeps returning 255

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
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
Andy Bartlett 2022년 12월 13일

0 개 추천

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
idealOutput = -1
actualOutput = mod(idealOutput, 256)
actualOutput = 255
We could also test this theory with Fixed-Point Designer fi objects.
nt = numerictype('uint8')
nt = DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 0
fiOutput = fi( idealOutput, nt, 'OverflowAction', 'Wrap', 'RoundingMethod', 'Floor')
fiOutput =
255 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 0 RoundingMethod: Floor OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 12월 11일

답변:

2022년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by