This is what i got so far, and im not seeing why it doesn't work.
please excuse the formatting and what not!
@ DEVICE pic16F684, HS_OSC, WDT_OFF, PWRT_OFF, MCLR_ON, BOD_OFF, IESO_OFF, FCMEN_OFF
DEFINE OSC 20
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 11
CMCON0 = %00000111
VRCON = %00000000
ANSEL = %00110100
ADCON0.6 = 0
ADCON0.7 = 0
voltLevBf VAR WORD
voltLevAf VAR WORD
voltLevCk VAR WORD
threshHold VAR WORD
timOut VAR WORD
prgSel VAR PORTC.2
swtOut VAR PORTC.3
CLEAR
PAUSE 1000
autoGainPrg:
ADCIN 2, voltLevBf
PAUSEUS 12
ADCIN 4, threshHold
PAUSEUS 12
ADCIN 2, voltLevAf
PAUSEUS 12
voltLevCk = voltLevAf - voltLevBf
IF voltLevCk > threshHold THEN
HIGH swtOut
PAUSE 60
LOW swtOut
ADCIN 5, timOut
PAUSEUS 12
PAUSE timOut
ENDIF
GOTO autoGainPrg:
the ADC acts as if there are two seperate voltage values present at the pin even if the voltage is the same and doesnt change. like on the first reading it should read 3 volts, and the second reading should be 3 volts or close enough! it shouldn't flash the LED sitting on the output, but its does, over and over like a blinky circuit, like the two readings are never close to equal, no matter what threshold is set at! so that would make me think that the difference between the two readings is somehow always larger than threshold.. what i'd like to know is, what did Jerson mean by "if Error < 0 then Error = -Error ' make absolute error" ?
IF Error < 0 THEN
Error = Error - Error
ENDIF
??? if so, i tried that version of it, and it didn't work either..
Bookmarks