Using the A/D for Monitoring a Solor Cell and Battery


Closed Thread
Results 1 to 7 of 7
  1. #1
    chuck.sieveking's Avatar
    chuck.sieveking Guest

    Question Using the A/D for Monitoring a Solor Cell and Battery

    I'm working with circuit that monitors both a Solor Cell Panel output and a lead acid battery. I know that the A/D can only upto 5 volts so I have used a voltage divider in both circuits. my question is How do i get the A/D to output to a LCD that shows a voyage reading from 0 to 25 volts for the Solor Cell and 13 volts for the battery.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Chuck,

    This should help out. I Hope.

    In the sample voltage divider shown below. If the input is 25Vdc then the output voltage will be about 4.38 Vdc.
    With 10-bit A/D you should get an ADCin of around 898.
    If you first scale that A/D value up to match the voltage divider ratio, you can then calculate the voltage the same way you would if you were reading 0-5 V.

    The ratio of the voltage divider is (R1+R2)/R2.
    To scale up the A/D reading you just multiply the value times the total resistance of the divider (R1+R2) then divide that number by R2.

    898 * 5700 / 1000 = 5118
    This is what the A/D would be if it could actually read 0-25 volts directly.

    Now then, for 1 decimal place, multiply that by 50 and divide by 1023.
    For 2 decimal places, multiply by 500 instead.

    5118 * 50 / 1023 = 250 or 25.0Vdc

    The program below is one way to do it in PBP.

    HTH,
    Darrel



    Code:
    Res1   Var Word
    Res2   Var Word
    Rt     Var Word
    Volts  Var Word
    AD     Var Word 
    
    Loop:
       ADCin  0, AD
       Res1 = 4700          ' Change these to match your Voltage divider
       Res2 = 1000          ' resistor values for the Solar Cell
       Gosub CalcVoltage
       LCDout $FE,2,"Solar= ",DEC Volts/10,".",DEC1 Volts Dig 0," Vdc"
       
       ADCin  1, AD
       Res1 = 2200          ' Change these to match your Voltage divider
       Res2 = 1000          ' resistor values for the Battery
       Gosub CalcVoltage
       LCDout $FE,$C0,"Batt = ",DEC Volts/10,".",DEC1 Volts Dig 0," Vdc"
       
    goto Loop
       
    CalcVoltage:
        Rt = Res1 + Res2        ' Total resistance of Voltage Divider
        Volts = AD * Rt         ' Scale the AD reading accordingly
        Volts = DIV32 Res2
        Volts = Volts * 50      ' Convert AD to Voltage
        Volts = DIV32 1023
    Return
    Last edited by Darrel Taylor; - 30th January 2014 at 03:32.

  3. #3
    chuck.sieveking's Avatar
    chuck.sieveking Guest


    Did you find this post helpful? Yes | No

    Smile

    Thanks Darrel.

    I had almost the same idea in the voltage divide, but I was using a 100k resistor and a 50K variable resistor. then adjust for 5v output. What I was having problems with was the ratio between the input voltage, divider and the A/D. I've work with the PIC processor alot but this is the first time using the A/D part of it.

    Also thank you for the code sample. I can modify it work with both the Solor Cell and Lead Acid Battery since the processor has to monitor both and give a read out on the LCD.

    My next question is, I've read that using DIV32 really slow down the processor. Is this correct? If so is there another solution?

    Again Thank you for your time.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Chuck,

    You should use smaller resistors for the divider.
    This is from the datasheet for a 16F877
    The maximum recommended impedance for analog sources is 10 kohm
    Your 100k and 50k are much higher and can cause error in the reading due to the sample and hold time requirements.

    The example I gave already works with both the "Solar Cell and Lead Acid Battery" so, not much to modify.

    And, as far as the DIV32 goes... NO it does not slow things down substantialy. In fact, when you divide 2 WORDs just like you always do in PBP, it actually uses the same DIV32 routine internally to accomplish it. So it doesn't take very much time at all. I've heard that statement before, to the extent of some people saying to "Avoid it at all costs". Rubbish!! Use it as much as possible, and forgive them, for they know not what they say.

    Darrel

  5. #5
    chuck.sieveking's Avatar
    chuck.sieveking Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel

    I've entered the code that you gave me and I getting a error stating "bad expression" on the lines that contain
    Volts = DIV32 Res2 and Volts = DIV32 1023.
    Is this due to my version of my complier being 2.31?

    Chuck Sieveking

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yes it is,

    DIV32 was added in version 2.40

    The current release is 2.45

    You're missing out on a lot of other additions too.

    http://www.melabs.com/support/upgrade.htm#History

    Darrel

  7. #7
    chuck.sieveking's Avatar
    chuck.sieveking Guest


    Did you find this post helpful? Yes | No

    Unhappy

    Dang!

    Looks like I'm going to have to invest $25 to get the upgrade.
    Oh well I'll have to do that next week.

    Thanks

Similar Threads

  1. A/d 16f88
    By Steves in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st May 2009, 02:19
  2. Of battery discharge curves
    By ardhuru in forum General
    Replies: 0
    Last Post: - 21st January 2009, 17:24
  3. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 03:16
  4. Low battery signal from an RTC
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th March 2008, 18:13
  5. Need advice on A/D
    By james in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th August 2007, 20:30

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