ADCIN Problem


Closed Thread
Results 1 to 34 of 34

Thread: ADCIN Problem

  1. #1
    Join Date
    Dec 2008
    Posts
    21

    Default ADCIN Problem

    Hello everyone,

    I am using a PIC18F4620 to read voltages but I am having aproblem where if I read anything in between 0 or 5 volts, the voltages readings are erratic or oscillate. I have tried using resistors or capacitors on the ADCIN pin but nothing seems to work. I have been trying to solve these for weeks now I have done a lot of research but can't find anything that gives light to what the problem is. I am powering my project with a USB port.

    I also noticed that if I disconnect the cable that goes to the ADCIN pin, I still get erratic numbers instead of reading 0. I have tried with code to get an average reading but this makes the code run slow.

    Any help on this will be highly appreciated.

    Following is an exctract of my code that am using separately to solve the problem with the ADCIN:

    DEFINE LOADER_USED 1 'Bootloader Used
    @ __CONFIG _CONFIG1H, _OSC_HS_1H
    DEFINE OSC 8
    ' OSCCON=%01110000
    Define ADC_BITS 10
    Define ADC_CLOCK 3
    Define ADC_SAMPLEUS 50
    adval var word
    TRISA = %11111111
    ADCON1 = %00000010
    ADCON2.7 = 1
    'ADCON0 = %11000001
    Pause 500
    Serout2 PORTD.0,16468,[$1b, $2a, $ff]
    loop:
    ADCIN 1, adval
    pause 50
    Serout2 PORTB.7,16468,[dec adval] ' to PC
    Serout2 PORTD.0,16468,[$fe, 1]
    Serout2 PORTD.0,16468,[dec adval] ' to LCD
    Goto loop
    End

    Javier.

  2. #2
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile Do you have any references?

    Hi Javier,

    Quote Originally Posted by JavPar View Post
    Hello everyone,

    I am using a PIC18F4620 to read voltages but I am having a problem where if I read anything in between 0 or 5 volts, the voltages readings are erratic or oscillate. I have tried using resistors or capacitors on the ADCIN pin but nothing seems to work. I have been trying to solve these for weeks now I have done a lot of research but can't find anything that gives light to what the problem is. I am powering my project with a USB port.

    I also noticed that if I disconnect the cable that goes to the ADCIN pin, I still get erratic numbers instead of reading 0. I have tried with code to get an average reading but this makes the code run slow.

    Any help on this will be highly appreciated. ....

    Javier.
    Don’t forget that the A/D module relies on an accurate, known, reference voltage, to compare to an unknown voltage. If your reference is your supply voltage then your supply voltage has to be rock solid. If you are switching loads attached to the supply / reference then the supply has to switch these loads without changing voltage.

    You still can use A/D input filters but if the reference voltage is not stable your readings will reflect the variations.

    Edited to add: Be sure your DEFINES are in Upper Case
    -Adam-
    Last edited by Pic_User; - 16th December 2008 at 17:14. Reason: Added: Be sure your DEFINES are in Upper Case
    Ohm it's not just a good idea... it's the LAW !

  3. #3
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Hey Adam,

    Thank you for your help. I am scratching my head over the reference voltage. From all the ADCIN samples I have seen, I haven't seen one that says anything about a reference voltage. Is this done by setting a register?
    I am reading the datasheet right now to see if I find something about that. My defines are in capital letter in my program.

    Javier.

  4. #4
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    From the datasheet, I am using:

    ADCON1 = %00001101

    which specifyes that I am using the project's voltage internally from VDD and VSS for voltage reference. I also tried using external voltage for reference but I get the exact same results.

    I tried putting a .1uF cap at the voltage in pin but no change.

    I am going to tried with another sorce of 5v and not use the USB to see what happens.

    Any suggestions will be appreciated.

    Javier.

  5. #5
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    I tried using a 5V power supply, but I still get the erratic voltage readings.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    WHAT are you measuring and how have you got it connected?

    Have you tried using a plain old meter?

    What is this 5v power supply you speak of? A wall-plug type supply? Benchtop supply?

    How much other stuff do you have connected to your '4620?

    How about posting a bit of a schematic...

  7. #7
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    I have made a separate project just to clean it. I am reading voltage from the project or voltage from a ac/dc wall power supply sending 3V. Also I have tried reading a angular rate sensor and last tried reading nothing and still get erratic readings.

    I use a digital multimeter to read the voltages and the readings are 100% stable on the meter.

    For supply I have been using the 5 volts from my PC's USB port. I also tried using a wall-plug type supply suppliying 5V.

    I cleaned my project so now I only have an LCD, a 4.7K resistor at pin 1 MCLR/VPP, on/off switch, reset button, 8 Mhz crystal with two 15pF from the crystal to ground.

    Even with the new clean project, I still get erratic readings.

    This is crazy. Will continue trying tomorrow. Thanks for your help.
    Last edited by JavPar; - 17th December 2008 at 04:29.

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


    Did you find this post helpful? Yes | No

    Default

    Try adding an LED and make it blink at a steady rate. Give the PIC a heart beat.

    Does the LED blink as expected?

    Also try the ADC at 8 bit resolution.

    Let us know what happens.

    When you tried a capacitor on the ADC, did you have it from the ADC pin to ground? Was the value at leat 1uf ? l use 22uf myself.

    Like skimask said, post a schematic. A picture of you setup might help too.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Hi guys, arriving late from work. I loaded a little schematic I hope is clear. On my project I have 4 LEDs. On this clean one I will use one. Will try 8 bits. I have used caps .1uF and 10uF connected to GND.

    Let you know tomorrow about the 8 bits.

    Javier.
    Attached Images Attached Images   

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    I would suggest bypass caps on the Vcc / Vss and a choke in series with the adcin line to kill off any RF which might affect your circuit. I would ask if you are working near RF sources like Fluorescent lights, microwave ovens, televisions etc . . .
    Last edited by Archangel; - 18th December 2008 at 05:35.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JavPar View Post
    Hi guys, arriving late from work. I loaded a little schematic I hope is clear. On my project I have 4 LEDs. On this clean one I will use one. Will try 8 bits. I have used caps .1uF and 10uF connected to GND.

    Let you know tomorrow about the 8 bits.

    Javier.
    From the picture...
    There's a Vdd and Vss on each side of the PIC, 11-12 and 31-32. I only see one of each hooked up. I don't see any cap's across Vdd and Vss on each side.

  12. #12
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post

    When you tried a capacitor on the ADC, did you have it from the ADC pin to ground? Was the value at leat 1uf ? l use 22uf myself.
    I'd second that; except, I use 0.1uf, with a 100K resistor in parallel with the capacitor.

    Regards,

    Anand

  13. #13
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Ok guys,

    1.) Changed to 8 bits.

    2.) Put caps 1uF on each side of the pic on the Vdd and Vss.

    3.) No microwaves, no TVs, no fluorescent lights close to my project. I scanned my desk for any possible interferences but there is nothing.

    4.) Put a .1 uF parallel with a 100K resistor at the ADCIN pin. Tried with different caps.

    5.) Added a LED and it blinks ok. Do not see any skips or changes on the blinking rate.

    6.) The only thing is that I could not find RF chokes locally (I'm in Panama Central America). I put a ferrite on the cable to the ADCIN pin just in case.

    All of the above and problem still persists. I have not seen a single change on the way the erratic readins of voltage behave. I tried to see if there is a pattern to the erratic readings but can not see one.

    Is this problem with erratic voltage readings something usual or rare? I have continued searching the web and I don'yt see anything that really talks about this.

    Could this be a problem with the PIC18F4620? Or maybe I should not be using a breadboard?

    Javier.
    Last edited by JavPar; - 21st December 2008 at 05:42.

  14. #14
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    With what you describe, I feel certain the issue is not of hardware. I have used the ADC on a breadboard, with a far cruder supply (no RF chokes/filters) without a problem.

    I have never used a PIC18F4620, though. Which is why I suspect perhaps its to do with some settings specific to that chip.

    Could you temporarily replicate that with another PIC, say a 16F877?

  15. #15
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Unfortunatelly, I only have the 4620. I can not find pics locally. I am already looking to order more different pics from the states.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    How erratic are the readings? Could you post a 'stream' of the readings?

  17. #17
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default

    Just to rule out the basics, if you ground the input, do you get a consistent '0'? and connect it to +5, do you get a consistent '255'?

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ardhuru View Post
    Just to rule out the basics, if you ground the input, do you get a consistent '0'? and connect it to +5, do you get a consistent '255'?
    Or a consistent 1023...

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


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I didn't see the " CMCON = 7 " ... Default value ... yes, but, just to be sure of .

    Also, did you try to tie RA.0 to ground or to RA1 ... it makes a superb noise input, as left floating !
    Note unused portA pins should be tied to ground through 10 k resistors ...

    - or use RA.0 as input !!! and other RA pins as outputs, if unused.

    Alain
    Last edited by Acetronics2; - 21st December 2008 at 10:19.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  20. #20
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by skimask View Post
    Or a consistent 1023...
    ADC set to 8 bits, remember?

  21. #21
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ardhuru View Post
    ADC set to 8 bits, remember?
    Which way are those 8 bits justified? Left? Right? Inverted?

  22. #22
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Test results:

    1.) Didn't see any change when changed to 8 bits, so I'm back to using 10 bits.

    2.) I edited my code so only RA0 is being used for input analog.

    3.) When connect ADCIN pin to any GND on the project, I get steady 0V readings. When connect pin to 5V I get erratic 5V readings BUT, noticed that when connect pin to 5V before my on/off switch, then I get 5V steady. Noticed also that when connected to 5V before on/off switch, this makes the PIC kind of work because my green LED connected to PORTD.2 starts to blinks like if my project is running but LCD stays off. Nothing happends when connect ADCIN pin to 5V after on/off switch. Removed the on/off switch, 5V voltage readings are erratic anywhere in the project.

    4.) Erratic readings are less npticeable when in 5V ranging from 1020 to 1023. When connect an angular sensor for example I get ranges from 480s to 540s aproximately. Other things I have connect ot ADCIN pin are a 1.5V battery and a 3V wall ac/dc adapter. I get erratic readings from both also.

    DEFINE LOADER_USED 1 'Bootloader Used
    @ __CONFIG _CONFIG1H, _OSC_HS_1H
    DEFINE OSC 8
    Define ADC_BITS 10
    Define ADC_CLOCK 3
    Define ADC_SAMPLEUS 50
    adval var word
    TRISA = %00000001
    ADCON0 = %00000001
    ADCON1 = %00001110
    'ADCON2.7 = 1
    ADCON2 = %10001011
    CVRCON.4 = 0
    'CMCON = 7
    Pause 1000
    Serout2 PORTD.0,16468,[$1b, $2a, $ff]
    loop:
    HIGH PORTD.2
    ADCIN 0, adval
    pause 50
    Serout2 PORTB.7,16468,[dec adval] ' to PC
    Serout2 PORTD.0,16468,[$fe, 1]
    Serout2 PORTD.0,16468,[dec adval] ' to LCD
    LOW PORTD.2
    pause 50
    Goto loop
    End

  23. #23
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Try this setting . . .
    Code:
    ADCON1 = %00001101 ' VREF off A.0 & A.1 as analog
    ADCON2.7 = 1    ' Right justified
    ADCON0.2 = 1    ' Channel 1 enabled 
    ADCON0.1 = 1    ' A/D conversion in process
    ADCON0.0 = 1    ' A/D Module Enabled
    . . . If I read it right . . .
    Edit: you posted while I was working on mine . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  24. #24
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    I tried:

    ADCON0 = %00000011

    as I am using AN0 pin for input now, no change.

  25. #25
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JavPar View Post
    I am using AN0 pin for input now, no change.
    Somehow I missed the change from AN1to AN0.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Wink

    Hi, JavPar

    Could you Post your HEX code ???

    Purpose is to verify the config real settings ....

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

  27. #27
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Hey Alain,

    Noticed I can't attach my hex file. It is very long to copy paste here.

    Javier.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JavPar View Post
    Hey Alain,

    Noticed I can't attach my hex file. It is very long to copy paste here.

    Javier.
    Rename the file to have '.txt' on the end.
    Dave
    Always wear safety glasses while programming.

  29. #29
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Attached my hex file.

    Javier.
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    This is what I get for your configs.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3071&stc=1&d=123046890 9">
    Attached Images Attached Images  
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by JavPar View Post
    Ok guys,

    1.) Changed to 8 bits.

    2.) Put caps 1uF on each side of the pic on the Vdd and Vss.

    3.) No microwaves, no TVs, no fluorescent lights close to my project. I scanned my desk for any possible interferences but there is nothing.

    4.) Put a .1 uF parallel with a 100K resistor at the ADCIN pin. Tried with different caps.

    5.) Added a LED and it blinks ok. Do not see any skips or changes on the blinking rate.

    6.) The only thing is that I could not find RF chokes locally (I'm in Panama Central America). I put a ferrite on the cable to the ADCIN pin just in case.

    All of the above and problem still persists. I have not seen a single change on the way the erratic readins of voltage behave. I tried to see if there is a pattern to the erratic readings but can not see one.

    Is this problem with erratic voltage readings something usual or rare? I have continued searching the web and I don'yt see anything that really talks about this.

    Could this be a problem with the PIC18F4620? Or maybe I should not be using a breadboard?

    Javier.
    Hi, Javier

    Nothing about config.

    BUT Your supply filtering looks to me a bit weak ... ( USB voltage stability ... ahem !!! )

    I have a board with '452 and another with '2520 ... 220µF at the card pow. input + 10 µF Tantalum + 0.1µF ( closest as possible from PIC pins ).

    see scheme attached.

    Some capacitor tank ( > 10µF Tant.) close to your LCD could be useful too ...

    Alain
    Attached Images Attached Images
    ************************************************** ***********************
    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 " !!!
    *****************************************

  32. #32
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Hey guys I really appreciate your help. Alain, that schematic that you posted has made me think. I used my multimeter to test input voltage right at AN0 pin and the voltage is steady at 2.432 with the last gidit sometimes changing to 1.

    I also noticed that measuring voltage in the output pin to my LCD I get oscillating 123mV to 127mV. That makes me think that possibly my PIC is doing something during the A/D convertion that it is outputting oscillating readings? The oscillating readings go out not only to my LCD pin but also to my PC pin.
    Last edited by JavPar; - 29th December 2008 at 04:25.

  33. #33
    Join Date
    Jan 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Had a similar problem my self - turned out to be the inverter for my LCDs backlight. My voltmeter gave no indication of any fluctuations.

  34. #34
    Join Date
    Dec 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    Alektric, I removed the LCD from the project and still the problem persists.

Similar Threads

  1. ADC or ADCIN "bias" problem?
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th February 2010, 19:39
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. electrical problem adcin
    By jcleaver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th March 2007, 22:52
  4. adcin problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 13th February 2005, 17:47
  5. weird 12F629/675 problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th October 2004, 01:08

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