ADCIN & 16F870 - how to avoid non linear conversion?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    You have ADCON1 set to use porta.3 as an input for a positive reference. Without a reference connected its floating

    Change ADCON1 to this
    Code:
     
    ADCON1 = %10000000
    then your references will be +Vref = vdd and -Vref = vss. Or you can connect porta.3 to +5v without changing adcon1

  2. #2
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    I'm using MAX6126 with output voltage of 4.098v and it outputs that voltage - verified with precision multimeter.
    The +Vref is tied to MAX6126 output and +Vref is tied to GND. So this is why I have ADCON1=%10000001
    When I tie RA0 directly to MAX6126 output, the raw output reads 1023, when I connect it to GND, it reads 0.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    Hi,
    OK, that's a great value because then each bit in the ADC result equals exactly 4mV but your numbers still doesn't add up....

    If you input exactly 3V you should get a value of 750 +/- a couple of bits - not 678 as you're apparently getting.

    Have you checked the VRef voltage with a scope? Perhaps it oscillates or have a lot of noise?

    What if you replace the 10k pot with a 1k pot, and put a 10nF capacitor between the ADC input and GND. Or, what if you increas the sampling time? (I'll admit, I don't really have this sampling time and Tad stuff clear in my head at the moment, need to do a little reading)

    Once you get a correct ADC result for the voltage you're feeding it you can increase the resolution by oversampling. If you take 40 samples, add them together and divide the result by 10 you have a value reading in mV (well, almost - there's 4mV "missing" at the top).
    Code:
    adval = 0
    For i = 0 to 39
      ADCIN 0, adval
      Voltage = Voltage + adval
      PAUSEUS 100
    NEXT
    
    LCDOUT $FE, 1, DEC Voltage/10000, ".", DEC3 Voltage // 10000
    /Henrik.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    Ok I've double checked wiring and so on. When getting 1023, I was connecting the upper end of pot to +5V, not to MAX output. Now, when I connected it to MAX output, it reads 987, instead of 1023, so I assume, there might be some more register settings required?

  5. #5
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    Code:
    Vin	Raw	Delta
    
    0.1	10
    0.5	88	78
    1	213	125
    1.5	335	122
    2	460	125
    2.5	580	120
    3	700	120
    3.5	807	107
    4	927	120
    4.1	960	33
    These are raw ADC reads according to different input voltage.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    Hi,
    First of all. With a VRef of 4.096 you can not input a voltage HIGHER than that, so the 4.1V (although very close) isn't a valid test. With that said something is seriously wrong - either with the code, the setup, or the hardware.

    And again, have you actually looked at the reference voltage AND at the input voltage with a scope to verify that they are clean? Simply measuring them with a voltmeter may not show the error.

    Instead of using the pot across the reference voltage, try using a low impedance source, ie a variable DC supply, to feed the ADC and put a 10nF capacitor from the PIC pin to GND to act as a noise filter. See if that makes it any better. Also, take a couple of readings and average them to further clean any noise.

    If the above doesn't help then try another channel on the ADC or try another PIC. It's possible, but not likely, that something got damaged when you overloaded the input.

    /Henrik.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    It is NOT 4.1V, it is 4.096v, I just wrote 4.1 to save space.

    Yes, looked with scope and precision (3 digits after decimal point) multimeter.

    Will try another channel and another pic, as well as another voltage supply.

  8. #8
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

    Default Re: ADCIN & 16F870 - how to avoid non linear conversion?

    Set scope to 50mV resolution and AC input. Found an 120mv max noise pulses, with 3.35hz following frequency.

Similar Threads

  1. How can I avoid stack corruption
    By BrianT in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2013, 02:45
  2. linear data memory & large data arrays
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th June 2011, 23:21
  3. How to avoid DIV32 command?
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 16th May 2011, 06:11
  4. Help needed with 16F870 ADC
    By srob in forum mel PIC BASIC
    Replies: 1
    Last Post: - 10th May 2008, 13:14
  5. Linear to S Curve conversion
    By luminas in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 22nd May 2007, 14:15

Members who have read this thread : 0

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