PDA

View Full Version : DEFINE ADC_CLOCK for 16F PICs



RussMartin
- 10th December 2009, 05:15
Does this define the clock source that is used to determine the actual sampling time?

If so, I see the default of 3 for RC oscillator in the A/D module. For the 16F88, I see also 0, 1, and 2 for OSC/2, OSC/8, and OSC/32, respectively.

Am I correct in my understanding that, if I want OSC/4, OSC/16, and OSC/64, I should use the same 3 options but set ADCON1.6 to %1?

What are the comparative advantages/disadvantages to using the RC oscillator versus a subdivision of OSC?

Thanks!

Russ

Darrel Taylor
- 10th December 2009, 05:43
Hi Russ,

This might help a little ...

http://www.picbasic.co.uk/forum/showpost.php?p=76762&postcount=4
<br>

RussMartin
- 21st January 2010, 05:45
Actually, that helped a lot. It looks like, with the 16F88 at 8 MHz, I should use:

DEFINE ADC_CLOCK 5

According to the table, thats 12 Tad of 24 us.

Do I still need to use:

DEFINE ADC_SAMPLEUS nn

and what is the relationship between that DEFINE and Tad?

Russ

Acetronics2
- 21st January 2010, 08:05
Hi, Russ

NO relationship : sampleus is sampling time, Tad is "conversion unit" time ...

no link between.

Alain

RussMartin
- 21st January 2010, 18:30
Thanks, Alain.

So . . . if I have a Tad of 24us and a sampling time of 12us, the total time required to sample the channel will be 36us, yes?

Russ

Acetronics2
- 21st January 2010, 19:45
NO, Russ ...



Conversion time = TAD + N • TAD + (11 - N)(2TOSC)
Where: N = number of bits of resolution required.


See the "Midrange Databook" $ 23.4 to 7 for details ...

Alain

Darrel Taylor
- 21st January 2010, 20:59
So . . . if I have a Tad of 24us and a sampling time of 12us, the total time required to sample the channel will be 36us, yes?
Yes Russ ...

24uS would be the total for 12 TAD, with each TAD being 2uS, plus the acquisition time of 12uS (the minimum @8mhz).

It may take just a little more for the instruction times within the ADCIN command.
<br>

RussMartin
- 23rd January 2010, 05:34
I looked at the ADC data book, Alain. Thanks. And thanks (again!) to Darrel.

I've done ADC before, with the 12F683 at 4 MHz and 8 bits.

Should I do anything different for the 16F88 at 8 MHz and 10 bits?

Darrel Taylor
- 23rd January 2010, 09:29
I've done ADC before, with the 12F683 at 4 MHz and 8 bits.

Should I do anything different for the 16F88 at 8 MHz and 10 bits?
There are a few things to do differently.

First thing is obvious, DEFINE ADC_BITS 10

And, Right Justify the result ADCON1.7 = 1

Then go here, and start using 12-bits or more. :)
http://www.darreltaylor.com/DT_Analog/
<br>

Charles Linquis
- 23rd January 2010, 16:36
I already oversample on the 12 bit-ers. I use averaging as part of the math. Rather than use something like (sample * 9) >> 4, it is better just to perform 9 conversions, add them together and shift. I typically only need 3 digits of precision.

The thing most people ignore is the quality of their reference and dividers. They try to get 10-12 bits (or more) of resolution when using Vcc as the reference voltage. That just doesn't work. We use an LM4120-4096 (4.096V) reference with 0.2% accuracy. All voltage dividers use 0.1% resistors.

I have code that has to run on 8720s. 8722s and 8723s (the user doesn't know what chip they have in their unit and I have to do field upgrades). I read the processor type and speed (PLL enabled or not - I have chips running at both 20 and 40Mhz) from the CONFIG registers and do a right shift (>>2) on the result if the chip is an 8723. I have to change all the timing, buad rates, A/D clocks as well. It all works well, though.

Darrel Taylor
- 23rd January 2010, 20:15
The thing most people ignore is the quality of their reference and dividers. They try to get 10-12 bits (or more) of resolution when using Vcc as the reference voltage. That just doesn't work. We use an LM4120-4096 (4.096V) reference with 0.2% accuracy. All voltage dividers use 0.1% resistors.

If the thing you are reading also operates with a Fixed Reference, then sure ... you should use a reference on the A/D.

But most things are "Ratiometric" and a fixed reference will transfer any ripple on the power supply straight into your A/D readings. And regulators like 7805's that can't keep a constant voltage will make the readings wander all over the place.

References have their place, but I believe you should not use them unless the right conditions are met.

0.1% resistors ... gotta agree with that though.
<br>

Charles Linquis
- 23rd January 2010, 22:27
The power supply voltages I have to read are never ratiometric.

Darrel Taylor
- 24th January 2010, 00:08
Exactly. Perfect example.

They are their own power supplies.
If VDD to the PIC changes, the other voltages don't necessarily change.
So there is no Ratiometric relationship, and a Fixed reference is required (like you have).

But when reading POTs, many pressure transducers, or any sensor that is resistive in nature, it will likely be ratiometric and a Fixed reference will distort the readings.

I guess I just thought that this was a bit limiting.

They try to get 10-12 bits (or more) of resolution when using Vcc as the reference voltage. That just doesn't work.

It's quite possible to get 12-bits or more without a Fixed reference.
If you are reading a Ratiometric device.

Fortunately, whether or not a reference is used can be changed in the ADCON1 register, so even within the same project you might have some Fixed or unreferenced sources, and other ratiometric devices that change with VDD.

If you know the difference, Use the reference for the fixed sources, and no reference (VDD) for the ratiometric ones.

Charles Linquis
- 24th January 2010, 05:39
I don't think I did a very good job of explaining myself.

I almost always have to read a 4 output EXTERNAL power supply (cPCI, VPX, uTCA or VME). I have to make certain that the voltages are within tolerance. I have to be a voltmeter, and have to be very accurate - regardless of what the PIC supply is.

RussMartin
- 25th January 2010, 15:15
Thanks, Darrel--I had already noted those two statement changes, but I appreciate the reminder.

I'm looking at 2 pots and the output of 5 op amps, but it isn't a problem if the values wander a little. (Probably I don't need 10 bits, either . . . !)

Thanks for the link, too. I'll take a longer look when I next treat myself to a break.

RussMartin
- 26th January 2010, 06:55
Part of what confused me on this matter is the statment in my PBP manual under "ADCIN":

<b>ADC_SAMPLEUS is the number of microseconds the program waits between setting the <i>Channel</i> and starting the analog to digital conversion. This is the sampling time.</b>

Comments, anyone?

Charles Linquis
- 26th January 2010, 12:56
The A/D converters have a FET switch on each input. When you change the channel, the gates on those FETs toggle. There is a finite capacitance between the gate and the drain and source of the FET, so the toggling of the gate signal causes what is called charge injection into the other pins. This causes a glitch at the input and output of the FET switch. If you read the A/D too quickly after you change the channel, you will get an inaccurate reading due to voltage spike caused by the charge injection. The time it takes for this excess charge to bleed away is dependent on your source impedance. If your source is the output of an op-amp (zero ohm source), then you can switch channels and start conversion within 3uSec. If your source is 10K then you should wait at least 11uSec after changing channels before you start a conversion. If you don't wait long enough, your accuracy will suffer.