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.
Just a general comment: so many messages on this forum emanate from people who seem to be so careless about details. They make typos. They "forget" important facts. It's like they got out of class, posted something and went to eat a sandwich...
and went to eat a sandwich...
Good thing we don't have to deal with digital grease stains on the postings then. ;)