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.
Maybe I miss something, but isn't it true that 0x64 - 0 = 0x64 ? Why do you expect 0x65?