ADCIN problems with PIC16F73


Closed Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    May 2007
    Posts
    66

    Default ADCIN problems with PIC16F73

    I am using a PIC16F73 with a 20MHz crystal. The 16F73 has a 8 bit A/D converter.
    I have a current transducer connected to the RA3 pin

    I am using the folling code:

    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3-internal clock)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time

    result var word


    TRISA = %00001011 ' Set RA0, RA1, RA3 to input, rest is output
    ADCON1 = %00000100 ' Set RA0, RA1, RA3 to analog input, RA2, RA5 to digital I/O
    ' reference voltage = Vdd, left adjusted
    ADCON0 = %11011001 ' A/D clock is internal RC, select RA3/AN3, turn on A/D



    Within a loop I am calling ADCIN as follow:

    ADCIN 3,result ' Read RA3 ADC channel


    My problem is:
    The transducer outputs a constant value of 2.54V which is right given the sensored current value, thus I know the
    transducer is working properly.
    However, ADCIN converts the constant 2.54V to a value that varies between 95 and 110?
    If would be expecting the converted result to equal a value of +-130 (2.54/5*255=129.54)?
    What bothers me most is why the ADCIN result is fluctuating between 95-110 while my voltmeter confirms a constant
    2.54V as output from the transducer?
    Any help or suggestion is appreciated.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    (2.54/5*255=129.54)?
    Should be 256 instead of 255. 0 to 255 = 256

    What are you using for a reference voltage?
    The results you are getting looks like the reference is swinging from 5.91 to 6.84 volts.
    256 x SIGNAL / ADCresult = REF VOLTAGE

    Do you have another volt meter?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Mackrackit

    ADCON1 = %00000100 sets reference voltage to Vdd
    I have measured the ref voltage going to the pic as +5.15V, thus I believe my voltmeter is accurate.
    2.54/5.15*256=126.3 which is still far away from the reading of 95?
    Last edited by passion1; - 25th July 2007 at 12:07.

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    What is the output impedance of your transducer (is it < 10kOhms)?

    Try converting the low rail and see if you get 0
    Try converting the high rail and see if you get 255
    If these work, try a simple voltage divider and see what you get.

    Long Shot - You also are using a 20MHz XTAL and not putting the PIC to sleep while sampling ... you may want to try using the TAD of the XTAL rather than the TAD of the internal RC - you are "supposed" to use minimum TAD possible.

    If no luck above, what is your power source? Do you have decoupling caps between VDD and VSS? How about a cap on RA3?

    Let us know
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by mackrackit View Post
    Should be 256 instead of 255. 0 to 255 = 256
    I believe it to be correct as originally written - the largest output from the ADC is 255, which should match AVDD....

    IF the input is the upper rail ...

    255/255 * AVDD = AVDD
    255/256 * AVDD <> AVDD

    my 2 cents
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi Paul,

    I missed the RA3 as the ADC input on this one, but I will stick to the idea that to get to 255 there are 256 steps.

    What if there is a 5v ref and a 2.5v sig.

    2.5/5*256=128

    I thought this digital stuff started at 0?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Paul

    Thank you for the suggestions.
    Could you please suggest values for the decoupling caps between VDD and VSS and the cap on RA3?


    I have also searched all the other threads and have come across some comment for related problems.
    The suggestions include:
    1. Try setting the settling time on the ADC to a few microseconds, then initiating a conversion.
    At the same time, make the PIC SLEEP for around the same length of time as the conversion.
    This should SIGNIFICANTLY reduce the noise across the PIC silicon substrate and give you a lot better accuracy.

    2. As a start, increase your Sample Time and/or change your Clock Source.
    It's a good possibility that you are not letting the sampling Capacitor enough time to charge properly before you take your reading.


    3. Have a cap on ADC pin. Try from 10uF to 220uF. (Cap+ to ADC pin, Cap- to GND.)
    and, change Pause 20 to Pause 500.

    4. Input pin require a pullup resistor too.

    5. For 20 MHz OSC; Fosc/32 could be the solution as it helped me solve a similar problem

    Any comments which of the above suggestions would be applicable to my problem?
    Is the settling time and sample time the same thing?
    How do I make the PIC sleep?
    Should I try a cap or a pullup resistor or both, and if so where must the cap and resistor be placed and
    what values would be recommended?
    Thank you in advance!

  8. #8
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Should be 256 instead of 255. 0 to 255 = 256
    So, are there 13 inches in a foot, 37 inches in a yard, etc.?

    0-255 represents 256 values (if you consider 0 is a value) but there are only 255 intervals. It's easier to see this by using smaller scales - e.g. 0-4.

    With GND--1K--1K--1K--1K--5V, each resistor drops 1/4 of 5V.

  9. #9
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    >> missed the RA3 as the ADC input on this one
    I am not sure how this relates to my post??

    >> but I will stick to the idea that to get to 255 there are 256 steps.
    I agree, 0-255

    >>What if there is a 5v ref and a 2.5v sig. 2.5/5*256=128
    no
    256 takes 9 bits to represent 100000000
    255 takes 8 bits to represent 11111111
    127 takes 7 bits to represent 1111111

    255 divided by 2 = 127
    2.5/5*255=127

    clear as mud?

    >> I thought this digital stuff started at 0?
    it does, 0-255
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  10. #10
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Paul

    The resistance of the transducer I am using is:
    RL Load resistance >= 2KOhm
    RM Internal measuring resistance 208 Ohm

    Could you please suggest values for the decoupling caps between VDD and VSS and the cap on RA3?
    Last edited by passion1; - 25th July 2007 at 14:37.

  11. #11
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Passion1,

    Try converting the rails first - what do you get?

    What is the output impedance of your transducer? Can't suggest a cap for RA3 until this is known.

    For VDD and VSS, try a 10uF electrolytic and a .1uF ceramic (in parallel) - but adding these blindly is not your solution - what are you using for a power supply? I cannot believe this (lack of these caps) is your problem if you get 95 or 110 out now.

    What else is going on in the circuit?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  12. #12
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by passion1 View Post
    Could you please suggest values for the decoupling caps between VDD and VSS and the cap on RA3?
    I'd use 100 pF or so (5 time periods * 100e-12 * 2000 = 1uS, way less than your 50uS sample time). This is not your problem either, my thought was you might have had something too big on there slowing the charge. Adding a cap here will help keep the answer solid, but at 8 bits, you should not have a problem without for now.

    the rails?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  13. #13
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Paul

    Please excuse my ignorance , but what do you mean with:
    "Try converting the rails first"?
    The transducer has 3 different settings to allow different ranges of current to be measured:
    Setting Primary_current Output_voltage Primary_resistance Primary_inductance
    1 +-6A 2.5+-0.625V 0.18mOhm 0.013uH
    2 +-3A 2.5+-0.625V 0.81mOhm 0.05uH
    3 +-2A 2.5+-0.625V 1.62mOhm 0.12uH

    Currently I am using setting 1 but in future I might want to use setting 3 because it allows greater accuracy.
    Last edited by passion1; - 25th July 2007 at 15:30.

  14. #14
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    I'd use 100 pF or so (5 time periods * 100e-12 * 2000 = 1uS, way less than your 50uS sample time).
    Paul

    I assume this is the value for the cap on RA3?
    Should it be electrolytic or ceramic?
    Thanks for all the help!

  15. #15
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by passion1 View Post
    Paul

    Please excuse my ignorance , but what do you mean with:
    "Try converting the rails first"?
    Passion,

    The low rail means ground - connect a wire directly from your circuit ground to AN3 and convert (you should get 0)

    The high rail means your PIC supply voltage - connect a wire directly from your 5V supply (the same one connected to your VDD pin on your PIC) to AN3 and convert (you should get 255)

    If you do not get these values, then something else is going on.

    The 100 pF is for AN3 (I use ceramic ). I had replied about the VDD and VSS caps before I saw your next reply giving impedance info and asking again. I followed with the 100 pF recommendation, which is for AN3. However, although good practice to have these, I do not think the lack of these are your problem.

    Let us know how the rails convert.

    Good Luck
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  16. #16
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Paul

    Thank you.
    When I connect the circuit ground to AN3 and convert, I get values fluctuating between 12-18.
    When I connect the +5V supply to AN3, the values initially fluctuate between 248-255 and eventually stabilizes at 255.

    I will be trying some of your other suggestions now and report back....

  17. #17
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Paul & other

    I have increased the sample time to 200 using DEFINE ADC_SAMPLEUS 200 but it did not solve my problem.
    I have also tried Fosc/32 by setting DEFINE ADC_CLOCK 2, but no luck!

    In my program I am using mister_e's matrix keypad routines and Watchdog is disabled.
    I am also running HPWM in the background which is pulsing the current I am trying to measure. The HPWM is switched on/off at defined intervals.
    Can this influence the ADC readings?

    Next I will try a cap on RA3......
    Last edited by passion1; - 26th July 2007 at 07:09.

  18. #18
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by passion1 View Post
    Paul

    Thank you.
    When I connect the circuit ground to AN3 and convert, I get values fluctuating between 12-18.
    When I connect the +5V supply to AN3, the values initially fluctuate between 248-255 and eventually stabilizes at 255.

    I will be trying some of your other suggestions now and report back....
    Passion,
    That is good news - your ADC is working. However, ....
    You should get a solid 0 and a solid 255 - Try turning off the HPWM and other stuff going on and see what you get for these conversions (i.e., leave everything off and convert these two at the beginning of your code and see what you get.)

    Again...what is your power supply?-

    Let us know

    EDIT: Your goal is to make the ADC work alone and then slowly add your other stuff and see what is causing the problem. Then you can address it ... a systematic approach!
    Last edited by paul borgmeier; - 26th July 2007 at 08:09. Reason: more info
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  19. #19
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by passion1 View Post
    Mackrackit

    ADCON1 = %00000100 sets reference voltage to Vdd
    I have measured the ref voltage going to the pic as +5.15V, thus I believe my voltmeter is accurate.
    2.54/5.15*256=126.3 which is still far away from the reading of 95?
    2/5*256=102
    no decimal in pbp
    use multiply x100

  20. #20
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Savnik

    The 2.54 and 5.15 is actual Voltage readings and is not integer variables within PBP. So I believe the calculation using floating point values is right?

Similar Threads

  1. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 20:27
  2. adcon problems with adcin
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd January 2007, 22:15
  3. ADCIN - AD settings are wrong
    By teverett in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th December 2006, 16:32
  4. Problems with MicroCode Studio ICD
    By Muzza in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th July 2006, 02:37
  5. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07: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