​ ​ ​ ​ ADC anomaly - HELP
Results 1 to 10 of 10

Thread: ADC anomaly - HELP

  1. #1
    New Member
    Join Date
    Feb 2014
    Location
    Perth, Western Australia
    Posts
    3

    Default ADC anomaly - HELP

    Hi. I have a strange problem with ADC. I have spend many hours trawling thru the forum & have implemented a number of various suggestions, however the anomaly remains. I am trying to monitor the battery voltage of a 12V SLA battery connected to a solar charging panel. The solar panel is diode connected to the battery. The output of the battery is directly connected to the voltage monitoring divider and an LM7805 regulator. The divider is currently 3k & 500 (exactly) ohms, with there having been many iteration of larger values. Up to 100K & 5K. The 08M2 runs from the 5V output of the regulator and is heavily decoupled. The divider tap is connected to C.4. I have tried decoupling the the ADC input with a number of different caps - .001uF to 100uF and combinations of those (currently .02 & 10uF). The ripple on the divider tap is less than 0.1mV on my scope. The battery voltage is stable at 12.57V & the voltage divider tap point is stable at 1.78V on my Fluke multimeter. Total current draw from the battery is 97mA and stable. The ripple on the 5V rail @ the 08M2 is less then 10mV. Code follows:-

    #picaxe 08m2
    #no_data

    FVRSETUP FVR2048
    ADCCONFIG %011

    init:
    symbol voltin = C.4
    symbol voltsraw = b1
    symbol voltscaled = b2
    symbol hunvolts = b3
    symbol tensvolts = b4
    symbol onesvolts = b5
    symbol tenthvolts = b6
    serout C.1, N2400,(254,1)
    serout C.1, N2400,(254,128)
    main:
    FVRSETUP FVR2048
    ADCCONFIG %011
    readadc10 voltin,voltsraw
    voltscaled = voltsraw * 14/10
    gosub voltlog
    debug
    pause 2000
    goto main


    voltlog:
    bintoascii voltscaled,b4,b5,b6
    serout C.1, N2400,(254,1)
    serout C.1, N2400,(254,128)
    serout C.1,N2400,("Volts ",b4,b5,".",b6," ")
    return

    Debug shows the raw ADC value in C.4 fluctuating between 63 and 144 - a huge swing. I have tried using an accumulator and averaging over a few minutes, but it is the huge fluctuation in the raw input that has me flummoxed. Thoughts please. Thanks.

    Tony

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,308

    Default

    Welcome to the PICAXE forum.

    symbol voltsraw = b1
    symbol voltscaled = b2

    readadc10 voltin,voltsraw
    voltscaled = voltsraw * 14/10
    The problem could simply be that you are using byte variables instead of word variables. A quick fix for that is to change all the 'b' for 'w' in your variable names in the SYMBOL definitions. You can sort out a better choice for which are word and byte later.

    ---

    12.75V into a 3K over 500R voltage divider should deliver about 1.796V

    1.78V on your Fluke is pretty close.

    ---

    1.78V read with a 2.048V votage reference read with READADC10 will be ...

    Nadc = Vin * 1023 / Vref

    1.78 * 1023 / 2.048 = 889

    ---

    voltscaled = voltsraw * 14/10

    889 * 14 / 10 = 1244 --> 12.44

    Which is somewhat close, probably just an inaccurate maths issue.

    ---

    Using a byte variable for READADC10 that 889 is becoming 889 Modulo 256 = 121, which is in your 43 to 144 range beeing seen.

    That 121 * 14 / 10 = 169 --> 1.69 which is what it's possibly showing.

    ---

    Added : You probably want to expand the BINTOASCII and your SEROUT to handle the larger 4-digit number your 'voltscaled ' variable is holding ...

    BinToAscii voltscaled, b11,b12,b13,b14,b15
    serout C.1,N2400,("Volts ", b11,b12,b13, ".", b14,b15)
    Last edited by hippy; 17-05-2018 at 15:22. Reason: Correct maths, tidied layout

  3. #3
    Senior Member
    Join Date
    Feb 2010
    Location
    Don't Mess With My Texas!
    Posts
    2,545
    Blog Entries
    7

    Default

    Probably should move to regular forum.

  4. #4
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,308

    Default

    Well spotted. Done.

  5. #5
    New Member
    Join Date
    Feb 2014
    Location
    Perth, Western Australia
    Posts
    3

    Default

    Quote Originally Posted by hippy View Post
    Welcome to the PICAXE forum.



    The problem could simply be that you are using byte variables instead of word variables. A quick fix for that is to change all the 'b' for 'w' in your variable names in the SYMBOL definitions. You can sort out a better choice for which are word and byte later.

    ---

    12.75V into a 3K over 500R voltage divider should deliver about 1.796V

    1.78V on your Fluke is pretty close.

    ---

    1.78V read with a 2.048V votage reference read with READADC10 will be ...

    Nadc = Vin * 1023 / Vref

    1.78 * 1023 / 2.048 = 889

    ---

    voltscaled = voltsraw * 14/10

    889 * 14 / 10 = 1244 --> 12.44

    Which is somewhat close, probably just an inaccurate maths issue.

    ---

    Using a byte variable for READADC10 that 889 is becoming 889 Modulo 256 = 121, which is in your 43 to 144 range beeing seen.

    That 121 * 14 / 10 = 169 --> 1.69 which is what it's possibly showing.

    ---

    Added : You probably want to expand the BINTOASCII and your SEROUT to handle the larger 4-digit number your 'voltscaled ' variable is holding ...

    BinToAscii voltscaled, b11,b12,b13,b14,b15
    serout C.1,N2400,("Volts ", b11,b12,b13, ".", b14,b15)
    Hi hippy. Thanks for that, but it didn't solve my problem.

    The voltage monitor is part of a much larger project where I am fighting for variable space anyway. I had just transferred the voltage monitor section of the project to an 08 to simplify sorting out the problem.

    I have subsequently discovered that if I disconnect the solar panel, which includes a charge regulator, the swinging value from the ADC goes away. I now assume there is something going on at an rf level that is causing the issue. I will have to find an alternate solar panel & charge controller.

    Thanks anyway.
    Tony

  6. #6
    Senior Member
    Join Date
    Jan 1970
    Location
    Colorado USA
    Posts
    3,190

    Default

    That sounds a bit extreme ... perhaps a ground loop... show a picture of your setup... shouldn't be any rf in play but often ground currents from V- connections give trouble...

  7. #7
    Senior Member
    Join Date
    Jun 2010
    Location
    Australia
    Posts
    117

    Default

    Tony,

    Check the voltage on your 12v battery and the midpoint at your 3K over 500R voltage divider after you hae disconnected the solar panel.

    In order to charge a battery the voltage applied to the battery teminals by the charger will be higher than the at-rest battery voltage. When you disconnnect the charger that is actively charging from a battery the battery voltage will drop. It is possible that the lower battery voltage means the voltage at the mid-point of your voltage divider with the charger disconnnected could have dropped low enough that the ADC value now fits into a byte variable.
    “If you think you know it all, you are not listening.”
    — Marsha Johnson Evans U.S. Navy (Retired)

  8. #8
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,308

    Default

    Quote Originally Posted by tonymillar View Post
    Hi hippy. Thanks for that, but it didn't solve my problem....

    I have subsequently discovered that if I disconnect the solar panel, which includes a charge regulator, the swinging value from the ADC goes away.
    It would be worth checking whether the updated code is giving results which are in the expected ballpark or not when just the battery is measured, solar panels are disconnected.

    That will help determine if code related issues have been resolved or if any remain.

  9. #9
    Senior Member
    Join Date
    Jan 1970
    Location
    Perth, Western Australia
    Posts
    4,445

    Default

    Quote Originally Posted by tonymillar View Post
    I have subsequently discovered that if I disconnect the solar panel, which includes a charge regulator, the swinging value from the ADC goes away. I now assume there is something going on at an rf level that is causing the issue. I will have to find an alternate solar panel & charge controller.
    While I don't rule out the possibility of RF interference, there are more possible DC influences to your problem. As alluded to by premelec, please post some images of the wiring of your setup. It is important that the PIC's supply ground wiring is not sharing a wiring path shared by heavy charging currents. If the paths are shared, the -ve reference point for the ADC readings is being compromised.

  10. #10
    New Member
    Join Date
    Feb 2014
    Location
    Perth, Western Australia
    Posts
    3

    Default

    Thanks for all the input guys. The problem is definitely the charge controller in the solar panel. I have substituted a different solar charging system and the problem does not recur. When I switch the old charger back in, swinging ADC happens again. Pointless posting images - project is currently breadboarded & birdsnestish. However, the immediate problem is solved & I don't have sophisticated enough instruments to try to find out what is unusual about the flaky charge controller. Maybe an investigation for the future, or I'll use the charger on a different project. Thanks again.

Bookmarks

Posting Permissions

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