i would go a step back first :
which pic did you use? how is your setup of ANSEL, CMCON? OSC?
best is you post the whole code
i would go a step back first :
which pic did you use? how is your setup of ANSEL, CMCON? OSC?
best is you post the whole code
i know it's only microcontrolling, but i like it!
pic16f688
OSCCON = %01110000
DEFINE OSC 8
trisa = %101111
vin var byte
compvalue var byte
main:
adcin porta.0, vin
if compvalue > (vin + 1) or compvalue < (vin - 1) then serout porta.5,6,[#vin]
compvalue = vin
goto main
CMCON0 = 7 gives me a syntax error for some reason.
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.
Bookmarks