This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430F2013: Wrong result on int16 math

Part Number: MSP430F2013

Tool/software: Code Composer Studio

Hi,

I wrote a function to remove an offset from a sample and saturate it if the operation extrapolates the int16 range.

However, apparently when the result off subtraction is "-1" there are some weird behaviors returning "-255", "-256", "255" or "256".

If the offset is sufficient to the result be completely positive or negative there are no spikes (second half of plot).

During the test, I noted that this behavior happens inside the "else" precisely when there is no saturation happening, but there is something affecting the result of subtraction. Other weird behavior is that I can't trigger this behavior inside debugger (running line by line or even putting an "if (sub < -100)" to halt the execution).

I tested the same function (code) on Arduino: Receive the data with offset and then remove it, and there are no spikes.

What is the problem?

**Attention** This is a public forum