I know this has been asked and I looked at many of the replies but at 75 years young I am having a bit of trouble wrapping my head around the best way to do this. I have an adc value that I am trying to maintain in a window. I am comparing an adc reading to a reference and trying to decide if it is in a +/- 40 count range. If not, I need to determine the direction to run, i.e. Vadc - Vref is positive or negative result. What I am having trouble with is the possibility of the answer being negative (PBP returning 65536-value) and therefore looking greater than the reference because of the way negative numbers are handled and getting a wrong direction. I suppose I could use Long variables since I am using a PIC18F but I am just looking to understand the logic.
Thanks for helping with my post-retirement education.