I've tested the code ; it's OK.
I've used ADCIN pretty much from day one, but I noticed I was getting some *very* jittery readings (255,243,246,255,243,246 etc)...I couldn't get to the bottom of it (spent a good while trying the usual stuff), I'd forgot about this thread but thankfully foiund it with Google)
It's the first time I've used the manual ADC method......but I'm pleased to also report my ADC readings are now solid as a rock.
Just for the record, here's what I used on my 12lf1822 (I'm only using 8 dits ADC)...
Many thanks to you all on this thread...I shall never go back to the ADCIN method!Code:ADCON0 = %00000100 ' select ch1 (AN1 Pin 6) ADCON1 = %00000000 'set ADC +ve reference to VCC ' main: gosub Do_ADC pause 100 hserout [DEC ADC_RESULT,13,10] goto main ' 'ADC sub routine... Do_ADC: PAUSEUS 50 ' Wait for A/D channel acquisition time ADCON0.1 = 1 ' Start conversion WHILE ADCON0.1 ' Wait for it to complete WEND ADC_Result = ADRESH return
Last edited by HankMcSpank; - 26th June 2011 at 19:52.
I wish the edit feature was open longer - I forgot to turn the ADC on above, sohere's the correction....
Code:ADCON0 = %00000101 ' select chan1 (AN1 Pin 6), turn ADC On Bit 0
Hello,
i made this to programm ADC
bmf_comm1 VAR PORTB.0
bmf_comm2 VAR PORTB.1
'Variables
bmfsD VAR WORD
bmfs1D VAR WORD
iled var byte
blink1 var byte 'pour clignotement 1ère led
blink2 var byte 'pour clignotement 2ème led
'configuration du port pour lire l'entrée analogique
TRISA = %00000011 ' RA0 et RA1 en entrée
TRISB = %11111100 ' RB0 et RB1 en sortie
ADCON1 = $10000010 'RA0 à RA3
test_depart:
Low bmf_comm1
Low bmf_comm2
High bmf_comm1
high bmf_comm2
pause 2000
goto mainloop
'lecture de la valeur
getad:
PAUSEUS 50 ' Wait for A/D channel acquisition time
ADCON0.2 = 1 ' Start conversion
WHILE ADCON0.2 ' Wait for it to complete
WEND
Return
' Subroutine to get pot x value
getx:
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
bmfsD = ADRESL + (ADRESH*256)
Return
' Subroutine to get pot y value
gety:
ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
bmfs1D = (ADRESH*256) + ADRESL
Return
val_leds:
low bmfs_comm1
low bmfs_comm2
gosub getx
gosub gety
if (bmfsD > 1000) Then Goto val_leds
if (bmfsD > 750) Then Goto boucle_led
if (bmfsD > 500) Then Goto boucle1_led
if (bmfsD > 250) Then Goto boucle2_led
High bmf_comm1
High bmf_comm2
pause 1500
goto val_leds
boucle_led:
iled = 0
while iled < 5
if iled = 1 or 3 or 5 then high blink1:low blink2
if iled = 0 or 2 or 4 then low blink1:high blink2
iled = iled + 1
pause 1000
wend
goto val_leds
boucle1_led:
High bmf_comm1
low bmf_comm2
pause 3000
goto val_leds
boucle2_led:
low bmf_comm1
high bmf_comm2
Goto val_leds
End
The leds works but always lightning , action on button (RB0 only for the moment) don't change anything.
No blinking .
I don't know what .
thanks.
Salut et Bienvenue sur le forum
I haven't check the whole thing in deep but I think you should modify the boucle_led section to
Probably it will solve your problem though... let me know the PIC you're using and your PBP version.Code:boucle_led: iled = 0 while iled < 5 if iled = 1 or 3 or 5 then high blink1 low blink2 endif if iled = 0 or 2 or 4 then low blink1 high blink2 endif iled = iled + 1 pause 1000 wend goto val_leds
EDIT: Your code have 2 compilation error
1) no mainloop label
2) adcon1: the way you have written it, it's value should start with a % instead of a $
Last edited by mister_e; - 24th August 2011 at 20:07.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Looking at your code, I guess it's your first program, There's quite a few mistakes in and it is also hard to follow what you want to do.
No problem, been there...done that. Tell us what you want to do and we could build something to help you to get started.
Tell us the PIC your're using and post your schematic if you have any, or describe it.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Sorry for double post but i tried many many modifications.
my pic is 16F877A , i desire to put multifunctions buttons of steering wheel and decode for command radio car system .
i make a test with leds for ADC value input .
Oh,oh,oh,
i have just see that i don't put MCLR to any connection , a resistor of 4.7kohms to +5V ?
It is a very simple schematic for test but the entire schematic is for steering wheel command and FIS Tachometer car display modification in live .
example : see the kwp1281 protocol codes of line K (not can bus) like VCDS soft but more simple.
This is the first part ( BMF )
For mainloop , it is because i modify the labels and i forgot it (val_leds) .
For $ , it is a mistake , THANKS.
i will try now
Regards
Last edited by mazoul72; - 24th August 2011 at 22:42.
Bookmarks