A/D conversion problem in 18F2520, 2523, 2550 etc.


Closed Thread
Results 1 to 10 of 10
  1. #1
    selimkara's Avatar
    selimkara Guest

    Unhappy A/D conversion problem in 18F2520, 2523, 2550 etc.

    Hello again everybody,

    I have successfully studied with PIC18F252 and its easy to use 10-bit A/D conversion. I'm designing some temperature controller stuff to use in our university labs.
    New generation 18F pics (2520, 2523(12-bit), 2550 and 4550 (with USB). I have never achieved to any precise measurement level with these pics. There's always a difference in the results of Keithley multimer and Pic, to the contrary of "lovely" 18F252, in the levels of 10-20 mV. This difference is sometimes linear or non-linear depending on the addition of capacitors and/or RC filters at the voltage and ref. inputs. (I've never needed to use these precautions on 18F252). I've tried to fix the parameters of ADCON registers, tried many combinations of timing, but it's useless. My reference voltage is provided from Maxim's precision ICs (4096 mV or 2048 mV).
    Today, finally I've desperately tried to develop the A/D conversion process of USB demo program written by Mister E and Darrel Taylor (Thanks to them for their great USB comm. example program). I've changed the 8-bit (0-255) resolution of potentiometer voltage to 10-bit (0-1023) by dividing ADREAD variable to low and high bytes, and succesfully combined them in VB6 program to produce the 10-bit result. But the result is still different with this program code.
    I'm using picbasic pro 2.47 and latest version of MPASM. I also tried to write the code in assembler according to the timing diagrams of Microchips manual.
    I never encountered any problem in 18F252 (no capacitor, no filter, a simple reference source from op-amp buffered voltage divider, max. of 1-2 mV error). But I need to use A/D conversion within a USB Pic and/or in a 12-bit Pic (Unfortunately, all of these pics' A/D conversion procedures are differs from 18F252).
    As a summary, can anybody explain where I made mistake(s).
    If you've experienced with that kind of millivolt precision application on these Pics, can you provide me the picbasic code of A/D conversion.
    (sorry about my English)
    Thank You..

    Dr Selim Kara

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by selimkara View Post
    As a summary, can anybody explain where I made mistake(s).
    Nope! Can't see any of your code!

  3. #3
    selimkara's Avatar
    selimkara Guest


    Did you find this post helpful? Yes | No

    Default

    Here is the code (one of many configurations),


    W0 VAR WORD
    W0=0

    define OSC 40
    DEFINE LCD_DREG PORTB
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    define LCD_EREG PORTB
    DEFINE LCD_EBIT 5

    TRISA=%111111
    TRISB=%00000000
    TRISC=%00001111

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 7
    DEFINE ADC_SAMPLEUS 50

    ADCON0=%00000000 ' CH0 as analog channel
    ADCON1=%00011110
    ADCON2=%10000111

    Start:
    ADCON0.0=1 ' A/D enable
    PAUSE 2

    Conversion:
    ADCON0.1=1 ' Start (Go/Done)

    SubC:
    PAUSEUS 20
    IF ADCON0.1=1 THEN SUBC

    W0.LOWBYTE=ADRESL
    W0.HIGHBYTE=ADRESH

    LCDOut $fe, 1, "Counts ", #W0
    lcdout $fe, $C0, "Result ", #(W0*4) ' 4096 mV ref.

    PAUSE 500

    GOTO Start

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


    Did you find this post helpful? Yes | No

    Question Hardware design fault ???

    Hi,

    While carefully reading your Datasheets ...

    Did you notice the ADC input impedance had slightly changed ??? ... take care to the voltage source impedance !!! ( in your RC filters ... there's a series resistor !!! )

    Your "symptoms" make me think it's a source impedance problem ...

    Also consider the voltage offset of your buffers ... An AOP gives easily 10 mV offset !!! and from a batch to another, it can widely differ.

    Could you show us a scheme of your input circuits ???



    I Use a 2520 for my Honda Lawn tractor ( read air and oil temp - LM335 , plus oil pressure - MPX 5700 , with the inboard ADC) and readings are rock steady ...
    My ref is a 4.096v from a TL431a ... trimmed with a 4.5 digits multimeter ...

    The initial project was built around a 18F452 ... and I didn't notice any change.

    Alain
    Last edited by Acetronics2; - 8th March 2008 at 18:01.
    ************************************************** ***********************
    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
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Also in the datasheet for a 2550/4550...

    The internal AD/RC oscillator is not a good idea on PIC chips if you want extreme accuracy.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2395&stc=1&d=120499947 4" />

    Try a different AD clock setting ...
    Code:
    ADCON2=%10100110  ; 64 TOSC, 8-TAD sample
    Also, since you're not using ADCIN, the ADC_ DEFINE's don't do anything.
    <br>
    Attached Images Attached Images  
    Last edited by Darrel Taylor; - 8th March 2008 at 20:23. Reason: .
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default Improving ADC repeatability

    High ADC accuracy and repeatability takes dedication at the PCB layout stage. There must be analog ground right beside the analog input and overall copper pour ground planes. Keeping all analog circuitry within its own fenced are of copper usually helps quite a bit.

    Another good technique (thanks Melanie) is to take 16 readings, sort them, throw out the top 4 and the bottom 4 then average the eight values that are left. That technique eliminates the outliers and tames the last one or two counts.

    I have also found several ADC ticks of noise/variability can be eliminated by locking the sampling point to the mains. I bring low voltage AC to an optocoupler and use that to trigger the ADC conversion. Varying the delay after the mains zero crossing will usually show a sweet spot where the fluorescent lights and other electrical loads are fairly quiet. I NEVER attempt 16 bit ADC without mains locking.

    Sloppy techniques that are invisible with 8 bit conversion start showing up with 10 bits and can make the transition to 12 or 16 bit ADC a worthless expedition.

    HTH
    BrianT

  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 BrianT View Post
    Another good technique (thanks Melanie) is to take 16 readings, sort them, throw out the top 4 and the bottom 4 then average the eight values that are left. That technique eliminates the outliers and tames the last one or two counts.
    Might help.
    I think she's said it several times, here's one of them.
    At least the sorting part.
    http://www.picbasic.co.uk/forum/showthread.php?t=134 <-- 134
    <br>
    DT

  8. #8
    selimkara's Avatar
    selimkara Guest


    Did you find this post helpful? Yes | No

    Default

    Many Thanks to everybody for their supports,

    Yes Alain, it may be impedance problem or Offset voltage drift in Op-Amps but it is not.
    As I said before, I tried many techniques and schemes, I used OP27 (very low offset) with symmetrical power supply and I always precisely check that kind of voltage drifts. Then I used MAX6241 (4096mV ref with a single supply). Sometimes I used a series resistor(1-4,7k) in analog inputs and/or/not capacitors (100-470 nF) between these pins and GND.
    May I ask you, did you ever precisely measure the voltages with a 1 mV (or lower) resolution voltmeter? If everything is okay may I see the summarized ADC section of your
    code (if it is in PBP)? Because I'll be insane soon.

    Thanks Darrell Taylor, I know, this code was one of the test code combinations.
    I read the manual's A/D section and desperately tried many clock setting parameters and
    also ADCIN command. These definition lines should be forgotten to be deleted.
    Staistical sort method is the last way, I used this technique only on the Maxim's high speed
    (100-200 kHz) 12-16 bits A/D converters. There was no need to use in 18F252.

    There must be a structural difference between 18F252 and 2520 to affect their using technique and resulting difficulties.

    BrianT, you are right, analog ground distribution is very important to prevent the voltage drops. I use protoboard for now but 18F252 was direct working in every condition. I don't understand this.

    Namely, I compare everything with 18F252 comfort and then getting angry.

    Can anybody write me a simple summarized code including definitions, settings and ADCIN usage. (I don't need high speed conversions. I want slow but stable and true results )
    (for 2520,4520, 2550 or 4550, all they have same A/D structure).
    And talk about differences between 18F252 or F452 and other new versions of these chips?

    Then, once again, I will try it on a PCB.

    Thank you

    Selim

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


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Selim

    First, I'd like to raise the problem data ...

    - Your scale is 1 - 4.096v with 10 bits resolution.
    - You want to read 10-20 mV

    That means you read with 4 mV per Bit ...
    The ADC count is always +/- 1 LSB ( rollover error ) ...

    So, your result is 1 to 5 +/- 1 ... I do not think you want to seriously regulate something with a +/ 20% input data error...

    Now, generally speaking, I always use a mean value - Nb of samples are a function of the measuring allowed time - and, to get rid of the rollover ... I then swap the LSB ...

    Moreover, when tracking the mV ... Ground Guard rings around the PIC inputs are to be used ( remember the inputs are "not so far" from the Xtal ... ).
    You'll notice the input leakage current has been reduced from +/- 500 nA ( '252) to +/- 100 nA ('2520) ... which means a much greater noise sensitivy ...

    I'd lead you to use a ground plane on the component's side, ADC section ...

    It would be interesting to know exactly what you want to do ... and how you do it ( input data range, sensors used, ...).

    I do not want to be rude ... but tracking 0 -20 mV with a 4v reference is a nonsense without "superior" PCB design skills ... as BrianT told.

    " May I ask you, did you ever precisely measure the voltages with a 1 mV (or lower) resolution voltmeter? "

    My multimeter is a 4.5 Digits ... so, 1 mV resolution.

    I really do not think the solution is in the code lines ...

    Regards

    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 " !!!
    *****************************************

  10. #10
    selimkara's Avatar
    selimkara Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Alain,

    You analyzed all situations. Thank you. Let me try to explain all story.
    I'm a physics researcher at University. I study on polymer physics. I also graduated from Electronics technical high school, from now on, electronics is a hobby for me. I'm trying to make some controller devices to use in our polymer lab. We have a special hand made oven to anneal some polymer thin films at some constant temperatures (0-500 C). I transformed its "antique" (from 1990's) controller to a modern pic circuit. An E-Type (chromel-constantan) thermocouple is embedded in the oven, thermocouple temperature-voltage conversion table is loaded in the pic18F252. Approx. 60 uV/C x 100 times with OP27 opamps = 6 mV/C *500 =3500 mV max. Voltage reference is 2048 mV, so 1 step=2 mv. Resolution is approx. 2/6=0.3 C/step. At 500 C, Tcouple voltage is about 3700 mV. Namely, I can't reach the temps. above 2048 mV(approx.280 C) and my resolution is 0,3. If my ref. voltage was 4096 mV (with a 12-bit ADC), my resolution would be 1/6=0.16 C/step and also one can measure beyond 500 C.
    İncreasing the resolution is important for fast detecting of changes in temp. to keep the desired oven temperature.( I have written a "smart" code to fix it.). Data appears on the 6x led-displays and also transferred to a PC via RS232. It has many more features (clock, timer, alarm, statistics, scrolling menus, user programmable tcouple tables...30kB of 32kB is Full). I've attached the photos. I did specially not designed it with LCD screen and USB communication. My aim was produce a cheap, easy-to-make device for distrubute it other experimental workers. I successfully designed similar circuits with Maxim's 12-16 bit ADCs. But they are expensive and hard to be made.
    PIC18F2523 is a 12-bit pic. It's ADC module is same with 18F2520 or other new USB pics (18F2550, 4550..). First, as a beginning, I replaced the 18F252 with 18F2520 and changed the ADC code, but there's always a non-linear difference (10-20 mV at best condition), then I tried other new pics on a protoboard with many additions (filters etc.) and many different combinations in AD registers' parameters in the code, did not work.
    Anyway, I think I'll give up.
    I hope you understand my English. Thanks everybody.

    Selim
    Attached Images Attached Images   

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem with 18F2455
    By abdy37 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 7th May 2007, 14:53
  3. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  4. A/D conversion problem with pic16F88
    By Tapio Linkosalo in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th August 2006, 11:42
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57

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