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.
You figured the issue out, you say.
So, was the problem part of what you posted? Or something you didn't post?
Remember that you can't really complain about the answer you get, if the quality of the answers is highly affected by the quality of the question.