Re: A/D converter PIC16F1827
You've selected the FVR as reference for the ADC but I see no code that configures the FVR (it's disabled on POR).
That's how far I got with what's shown.
/Henrik.
Re: A/D converter PIC16F1827
ADCON1 = %01100011
For your ADC Clock to = 3, ADCON1 must be %0011....
You have the ADC Module looking at the FVR for a VREF+ (bits <2-0> of ADCON1). Nowhere in your listing do you mention setting up the FVRCON register so your ADC has its positive reference turned on. You might want to change ADCON1 to %00110000 and use Vdd for your VREF+.
You can use the ADCIN command, ADCIN 0, VAR and PBP will automatically adjust ADCON0 to AN0 for you, or you can work it manually:
ADCON0 = %00000011
DO
LOOP WHILE ADCON0.1 = 1. ;The GO bit
VAR = ADRESH
This gives you an 8-bit ADC value. For AN1, ADCON0 = %00000111, for AN2, ADCON0 = %00001011, and so forth.
Re: A/D converter PIC16F1827
mpgmike Thank you very much
Can you tell me how I will get a 10-bit price in the baty variable
my programm
Code:
baty var word
arxh:
ADCON0 = %00000011
DO
LOOP WHILE ADCON0.1 = 1
adcin 0,baty
if baty > 1050 then
gosub OK
endif
if baty < 1000 then
gosub noOK
endif
goto arxh
Re: A/D converter PIC16F1827
Look from page 142 and after the details of the AD converter. It always makes a 10 bit conversion. It is up to you if you want 8 or 10 bits result.
Anyway, having ADFM=1, the result is Right justified and stored in the ADRESH, ADRESL.
So get your result in the baty variable as:
baty.HIGHBYTE=ADRESH
baty.LOWBYTE=ADRESL
or
baty.BYTE1=ADRESH
baty.BYTE0=ADRESL
In any case for the variable handling (e.g. baty.BYTE1, etc) look at the PICBASIC reference manual.
Ioannis
Re: A/D converter PIC16F1827
You don't have to first do a "manual conversion" (via the GO/DONE bit) and then do a ADCIN (which basically does the same thing for you).
If you're going to use ADCIN then add a DEFINE ADC_BITS 10. If you're going to use the "manual method" just do what Ioannis showed and get rid of the ADCIN command.
And once you DO have your 10-bit resuly this won't work because baty will never be >1050 since the maximum result returned by the 10 bit ADC is 1023:
Code:
if baty > 1050 then
gosub OK
endif
/Henrik.
Re: A/D converter PIC16F1827
There are some 12-bit ADC Modules in a few of the PICs if you want better resolution. Referencing the ADMF = 1, that would be ADCON1.7 = 1. Let us know how you make out.
Re: A/D converter PIC16F1827
Thank you all for the help. Excuse me .I am a novice to PICBASIC
Re: A/D converter PIC16F1827
That's what we are here for. Don't worry being novice. We all are, one way or another!
Henrik caught the over 1023 point that I missed. Be careful on this as the 10 bit might be not enough for what your are after.
But you can always scale the measurements. Tell us more to help.
Ioannis