Try this. Change your serout to HIGH to light an LED as an indicator. Then sample compvalue only once.
start:
low portb.0
adcin porta.0, compvalue
main:
adcin porta.0, vin
if compvalue > (vin + 1) or compvalue < (vin - 1) then high portb.0 : pause 1000 : goto start
goto main
Bookmarks