PDA

View Full Version : 18f452 ADC config



iw2fvo
- 1st August 2009, 12:58
Hi to all,

I am going to set up the PIC18F452 having a clock speed of 40 Mhz in order to read the follwing analog inputs:

> analog input connected to AN0 pin_2
> Vref+ connected to AN3 pin_5
> Vref - connected to AN2 pin_4

Question_1:
How do I have to set ADCON0 register and ADCON1 register to achieve this set up ?

Question_2:
Do I have to read ADRESL and ADRESH relevant to AN0 ? or I do have to read AN2 and AN3 register in addition to AN0?

Thanks a lot for any help
Regards,
Ambrogio

mehmetOzdemir
- 1st August 2009, 13:32
you dont need to set adcon0 register if you are using picbasic.

Use Adc defines ;


DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
DEFINE ADC_CLOCK 3 ' ADC clock source (Fosc/8)
DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)

YOU HAVE TO SET ADCON1 REGISTER TO CHOICE WITCH PORT ANOLOG OR DIGITAL.



ADCON1.7 = 1 ; Right justified.

ADCON1.3 = 1 ; PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
ADCON1.2 = 1
ADCON1.1 = 1
ADCON1.0 = 1

MAIN :

ADCIN 0 , ADVAL

PAUSE 10
GOTO MAIN

iw2fvo
- 1st August 2009, 17:37
Hi ,
Thanks very much for adc setting help.
Now it is working well.
Could you please spend few words for me about the following :

DEFINE ADC_CLOCK 3 ' ADC clock source (Fosc/8)
DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)

I am working with a 40 Mhz clock speed: does those defines affect the accuracy of the measure ( in some way ? Fosc/2 or fosc/32 ... sampleus=150 ... ).

Thanks again
regards,
Ambrogio

mehmetOzdemir
- 1st August 2009, 17:53
i think mister-e's great program will help you.

program cointains a adc-calc.

http://www.picbasic.co.uk/forum/showthread.php?t=4994&highlight=mister-e