I’m sampling two AD channels every 1 second inside the ISR. My Xtal is 4 MHz & my AD conversion clock is set for Int RC.
When doing multiple channels there are some timing parameters required. I want to check my codings timing to get best AD results.
I want to know what I’m missing in my code or what I have to adjust.
When doing multiple channels there are some timing parameters required. I want to check my codings timing to get best AD results.
I want to know what I’m missing in my code or what I have to adjust.
Code:
org 0x0004
Interrupt movwf W_Temp ;save W in a Temp
swapf STATUS,W ;
movwf S_Temp ;save status in a Temp
bcf INTCON,T0IF ;reset T0IF int flag
decfsz Count,F ;count 100 times to make 1 second
goto Exit
movlw .100
movwf Count
Channel1 bcf ADCON0,3 ;turn on first AD channel (RA0)
[COLOR="Red"]call Del_Hold ;make a 40 uS delay after changing the channel[/COLOR]
call Sample ;check the AD value & get a sample
bcf STATUS,C
rrf ADLResult,F ;make the value divide by 2
call BCD ;make the value into decimals
call BCD_Split1 ;convert into segment digits 1 & 2
Channel2 bsf ADCON0,3 ;turn on second AD channel (RA1)
[COLOR="Red"]call Del_Hold ;make a 40 uS delay after changing the channel[/COLOR]
call Sample
bcf STATUS,C
rrf ADLResult,F ;make the value divide by 2
call BCD ;make the value into decimals
call BCD_Split2 ;convert into segment digits 3 & 4
Exit swapf S_Temp,W
movwf STATUS
swapf W_Temp,F ;swap to file
swapf W_Temp,W ;swap to work
retfie
;***************
;AD subroutines
;***************
Sample clrf ADLResult ;clear the result
bsf ADCON0,GO ;start convertion
btfsc ADCON0,GO
goto $-1
[COLOR="Red"]bsf STATUS,RP0 ;switch to bank1[/COLOR]
movf ADRESL,W
[COLOR="Red"]bcf STATUS,RP0 ;back to bank0[/COLOR]
movwf ADLResult ;place the 8 bit AD result
return
Del_Hold movlw .12 ;40 uS holding delay
movwf Hold
decfsz Hold,F
goto $-1
return