DEFINE ADC_CLOCK for 16F PICs


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263

    Question DEFINE ADC_CLOCK for 16F PICs

    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
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,

    This might help a little ...

    http://www.picbasic.co.uk/forum/show...62&postcount=4
    <br>
    DT

  3. #3
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Question

    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
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Russ

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

    no link between.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    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
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Exclamation

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    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>
    DT

  8. #8
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    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?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    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>
    DT

  10. #10
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    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>
    DT

  12. #12
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The power supply voltages I have to read are never ratiometric.
    Charles Linquist

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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.
    DT

  14. #14
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  15. #15
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    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.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  16. #16
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    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?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  17. #17
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

Similar Threads

  1. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 17:42
  2. PIC16F877A analog problem
    By DeViLa_Q8 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 30th July 2009, 20:19
  3. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13
  4. PIC HSERIN problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 20th July 2008, 11:08
  5. Replies: 8
    Last Post: - 17th September 2006, 17:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts