CMCON0 = 7 gives me a syntax error for some reason.......
no it doesn't. I got the patch. This setting has not made a difference though.
CMCON0 = 7 gives me a syntax error for some reason.......
no it doesn't. I got the patch. This setting has not made a difference though.
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
Hey. That works. THis is my code:
start:
low porta.5
adcin porta.0, compvalue
main:
adcin porta.0, vin
if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin] : goto start
goto main
can you explain why this works and the other way doesn't?
Without going into your code in any detail, your original code (below) has a flaw in it's thinking...
if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin]
compvalue = vin
If vin increases by ONE, no change happens, but you replace compvalue with the content of vin.
Next time around, if vin changes by ONE, you do the same.
So vin can slowly change by ONE, you don't get a SEROUT but compvalue starts drifting.
What your code should have done is this...
if compvalue > (vin + 1) or compvalue < (vin - 1) then
serout porta.5,6,[#vin]
compvalue = vin
endif
this way, compvalue is updated ONLY if you've done a SEROUT, no SEROUT so no update of compvalue.
After reading a different post concerning the ADCIN command, I overlooked an obvious mistake. The command should be ADCIN 0,VIN not ADCIN PORTA.0,VIN. Always address the channel name not the port pin number.
Bookmarks