here is where i am now, and it still doesn't work, no matter.. also, if I were to set my current reading and previous readings equal, the next loop through would set them to what ever the ADC says at sample time anyway.. so it would be pointless wouldn't it?
PreviousADC = CurrentADC ?
@ 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 ' variable for first reading or "previous"
voltLevAf VAR WORD ' variable for second reading "current"
voltLevCk VAR WORD ' variable for holding the difference
threshHold VAR WORD ' variable for the threshold
timOut VAR WORD ' variable for holding the timeout
prgSel VAR PORTC.2 ' not in use yet
swtOut VAR PORTC.3 ' output to LED
CLEAR
PAUSE 1000
autoGainPrg:
ADCIN 2, voltLevBf ' sample voltage on ADC 2
PAUSEUS 12
ADCIN 4, threshHold ' get threshold from pot set up as volt. divider on ADC 4
PAUSEUS 12
ADCIN 2, voltLevAf ' sample voltage on ADC 2 again, to check for difference
PAUSEUS 12
IF lghtlevAf > lghtlevbf THEN ' IF the second reading is higher than the first,
voltLevCk = voltLevAf - voltLevBf ' subtract the first reading from the second to get the Dif.
IF voltLevCk > threshHold THEN ' IF there is a difference, and it is greater then threshold
HIGH swtOut ' set the LED high
PAUSE 60 ' pause for 60 mS
LOW swtOut
ADCIN 5, timOut ' check volt. div pot on ADC 5, use number as time out - 0 to 1023
PAUSEUS 12
PAUSE timOut ' Pause for the time out setting, determined by ADC 5
ENDIF
ENDIF
GOTO autoGainPrg:
Bookmarks