I am trying to do a straight forward subtraction and am getting the wrong result every time. The code is as simple as
if(SetPoint>PulseCountLast) { error = SetPoint-PulseCountLast; }
All three variables are defined as uint16.
As you can see I ensured that I dont get a negative error value. Although I did try using error as signed number but still the faced the same issue. In any case the issue is when debugging is that SetPoint has a value of 0x0064 and PulseCountLast has a value of 0x0000 so I would expect an error value of 0x0065, however, the code always results in an error value of 0x0001 no matter what value the operands have.
I am really confused at this point what it might be...I would appreciate some help.
Are you sure that your _real_ code doesn't do: error = SetPoint > PulseCountLast
That must be it!