Im having problems with reading two analog voltages from two different pins.I am supposed to read e first incoming voltage from pin 1, blink an led based on that value, and unless that value is within the desired range it will continue to loop.
Heres the problem, the first voltage read out works fine, however when i switch to the next pin(pin3) and read its incoming voltage, it tells me its not within the desired value i had already set. Im quite sure abt the values im checking the voltages with.If i read only either voltage in seperate programs, they work fine.Only when combined as a single program does the second checking go haywire.I think the new a/d value at tml2 is not being stored as the new adresh. How do i clear adresh from e first value and store the new value from pin 3, to do the second checking? Any assistnce would be greatly appreciated.
This is a sample of e program i wrote for the pic12f675.
PS CON 2
LED2 CON 5
Vin VAR BYTE
Vin2 VAR BYTE
FxVin VAR BYTE
FxVin2 VAR BYTE
K VAR BYTE
L VAR BYTE
M VAR BYTE
ANSEL = %00111010
TRISIO = %010010
FxVin = %01001101
FxVin2 = %00011001
GPIO = %000000
k = 0
L = 0
STEP1: FOR M = 1 TO 5 ; BATT CHECK
HIGH LED2
PAUSE 100
LOW LED2
PAUSE 100
NEXT M
GOTO check
CHECK: ADCON0 = %00000101
HIGH PS ; send a high to pin
ADCON0.1 = 1
Vin = ADRESH
Compare: ; COMPARING VOLTAGES
IF Vin > FxVin THEN
GOTO TML2 ;Enough Light
ELSE
GOTO TLL ; Too Little Light
ENDIF
TML2: ADCON0.3 = 1 ;check analog voltage on pin 3
ADCON0.1 = 1
Vin2 = ADRESH
Compare2:
IF Vin2 < FxVin2 THEN ; compare with new adresh value
GOTO allgd
ELSE
GOTO TLD ; too little distance
ENDIF
TLL: gosub a
low ps
Pause 2000
GOTO CHECK
TLD: gosub b
low ps
pause 2000
GOTO check
ALLGD: HIGH LED2
PAUSE 250
LOW LED2
PAUSE 250
GOTO check
A: FREQOUT GPIO.0,500,311
PAUSE 10
FREQOUT GPIO.0,250,233
PAUSE 10
RETURN
B: FREQOUT GPIO.0,500,311
PAUSE 20
FREQOUT GPIO.0,500,311
PAUSE 20
FREQOUT GPIO.0,500,311
PAUSE 20
RETURN
END