Can anyone tell me why this ADC code does not work?
Posted: Fri Oct 03, 2008 6:02 pm
I have made a few changes but it still doesn't appear to convert. Can anyone help me find a soultion? Is the value in ADRESH Binary? If so, how would the If statement work? I am new to this but chugging along.
Thanks
Here is the new code:
Device = 18f1320
//clock = 4
Dim Value As Integer
//Subroutine to read a/d converter
Sub getad()
DelayUS(50) ' Wait for channel to setup
ADCON0.2 = 1 ' Start conversion
DelayUS(50) ' Wait for conversion
End Sub
//Subroutine to get pot value
Sub getvalue()
ADCON0 = $D '(00001101) Set A/D to On, Channel 3, Vdd/Vss
ADCON2 = $b1 '(10110001) Set A/D to Fosc/8, 6Tad, right justified
getad
Value = ADRESH
End Sub
TRISA = $8 '(00001000) Set RA3 as input
ADCON1 = $8 '(00001000) Configure AN3 to Digital
Value = 0
While
getvalue ' Get value
Wend
If Value > 10 Then High(PORTB.3)
EndIf
Thanks
Here is the new code:
Device = 18f1320
//clock = 4
Dim Value As Integer
//Subroutine to read a/d converter
Sub getad()
DelayUS(50) ' Wait for channel to setup
ADCON0.2 = 1 ' Start conversion
DelayUS(50) ' Wait for conversion
End Sub
//Subroutine to get pot value
Sub getvalue()
ADCON0 = $D '(00001101) Set A/D to On, Channel 3, Vdd/Vss
ADCON2 = $b1 '(10110001) Set A/D to Fosc/8, 6Tad, right justified
getad
Value = ADRESH
End Sub
TRISA = $8 '(00001000) Set RA3 as input
ADCON1 = $8 '(00001000) Configure AN3 to Digital
Value = 0
While
getvalue ' Get value
Wend
If Value > 10 Then High(PORTB.3)
EndIf