PDA

View Full Version : Picbasic and ADC set_up



iw2fvo
- 12th January 2013, 17:46
Good day to all of you in the forum,
I am going to implemant an AD conversion using the Pic18f252 at 40 MHz clock speed and 10 bit resolution.
I still have problem in understanding how to set up the following parameters to get the most possible AD speed in a close loop :

Define ADC_CLOCK ??
Define ADC_SAMPLEUS ??

There is also a PAUSEUS ?? value to be put in the loop to comply with the settling or acquisistion time restriction: Where to put it ? and what is the minimum time ?

I thank you in advance for any help on the matter.

Regards,
Ambrogio

Darrel Taylor
- 12th January 2013, 19:26
This first thing to do is look in the 18F252 (http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf) datasheet for the minimum TAD.
Go to the "Electrical Characteristics" section, then search for TAD, you should see this ...

http://support.melabs.com/DT/18FXXX_TAD.gif

1.6 uS is the minimum TAD.

Simply multiply the main oscillator frequency (in your case 40,000,000) times the minimum TAD (0.0000016).

40,000,000 * 0.0000016 = 64

Always round UP.
If FOSC = 16,000,000 then (16,000,000 * 0.0000016 = 25.6), so you have to round that UP to the closest prescaler (32).

Now go to the "COMPATIBLE 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE" section and look at the ADCON0 and ADCON1 registers.
The ADCS bits select the A/D clock. There are 2 bits in ADCON0 and 1 bit in ADCON1. Together, they make up a 3-bit binary number.
Look that number up in the table for the ADCON0 register ...
For FOSC/64, it's 110

http://support.melabs.com/DT/18FXXX_ADCS.gif

Convert it to decimal and use ...

DEFINE ADC_CLOCK 6 ; FOSC/64, 1.6uS @ 40Mhz

Different chips have different minimum TAD requirements, and the ADCS bits will change too. Always look them up.

NOTE: If you were using a 16F1 part, the DEFINE ADC_CLOCK has no affect and the ADCONx registers must be set manually.
_____________ ________________________ _____________________

You do not need a PAUSEUS statement for acquisition time.
That's what the DEFINE ADC_SAMPLEUS does.

Exactly how much acquisition time is required is a complicated question that depends on circuit impedance, whether or not you are reading more than one channel and again ... the chip you are using.
mister-e's PicMultiCalc is useful for the impedance part.
If you are only reading 1 channel, you don't need any acquisition time at all.

The Trial and error method usually works well enough though.
Reduce the ADC_SAMPLEUS time until you get bad readings or cross-talk between channels, then double it.

iw2fvo
- 13th January 2013, 09:26
Derrel,
thanks very much for your clear and accurate explanation.
It is great.
Best regards
Ambrogio
IW2FVO
North Italy