Writing code for battery operated projects


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Can anyone help me?

    Hello, My program is functioning good now for the better part, the milliamp draw is down considerably which is great. Thanks again Steve! Now I need a kick start to: figuring out a way to set up a variable (if it's at all possible?) that I can use in an IF...Then statement to sound an alarm when the battery voltage (that powers the pic) drops to the level that the user can set using push buttons to change that variable. I did hear that there are voltage regulators that have a low voltage alarm built in so that's an option too.

    For now I'm using a 5K pot connected to an ADC input in a 10 bit mode to simulate the batteries output voltage. Later I'll set up a voltage divider for the batteries and tap it off to the adc input. The code below that I'm using seems to be functioning as expected thanks to the PBP Archives.

    The_Battery_Voltage = (The_Battery_Voltage */ 500)>>2
    LCDOut $fe, 1,"DC Volts = ",DEC (The_Battery_Voltage/100),".", DEC2 _
    The_Battery_Voltage

    With the above code my 5K pot adjusts from 0.00 to 4.99 volts which as far as I can figure so far, should be good. I did a print to another screen without the math to show The_Battery_Voltage variable and it showed 1023 while the one with the math above was printing 4.99.

    Would anyone know the math involved to create a word variable to accomplish this? Another option I have is to use another adc input using a 5K pot and use that variable in my IF...Then but I would like to go with push buttons. Any help would be greatly appreciated.

    Thanks jessey

  2. #2
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Smile Volt Read

    KK:
    gosub GetVolt
    SerOut LCDScreen, N2400, [LCDCmd, LCDLine1,"T= c"," V=",#LCDVHigh,".",#LCDVLow]
    goto KK

    GetVolt:
    'For global reference to system voltage, use the Voltage variable, which is based on a
    'scale of 1 to 1000, with 775 = 7.75 volts. Remember that the resistors on the board
    'divide the actual battery voltage in half so the ADC can "digest" it without damage.
    'ADCIN voltages are limited to 5. Voltage are compared with the onboard
    'precision voltage reference which delivers a perfect 5V.


    '**Voltage**
    LCDVLow=0
    LCDVHigh=0
    Voltage=0
    ADCIN VoltChannel, Voltage 'Take just 1 voltage sample. 7.6V = 194
    Voltage = Voltage * 4 '194 * 4 = 776
    LCDVHigh = Voltage / 100 '776 / 100 rounds to 7
    LCDVLow = (Voltage // 100) / 10 '776 // 100 = 76, 76 / 10 = 7
    'Final Display = 7.7

    return
    Last edited by jetpr; - 13th June 2005 at 18:12.

  3. #3
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Question

    Just a thought !
    When using the ACIN command for A/D conversion
    How is this turned off before going to sleep ?
    Does pbp automatically take care of it


    Isaac

  4. #4
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Smile Volt Read

    yes Think automatically take care of it i dot have no problems using the A/D.

  5. #5
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jetpr
    yes Think automatically take care of it i dot have no problems using the A/D.
    Thanks thats what i thought

  6. #6
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Jetpr,

    Thanks for the code you sent, I got it working good and I also managed to write some code using push buttons so I can set a reference to warn when the battery voltage drops to whatever level I want, that way if it works the way I envision it to work then I can use different battery combinations and just set my reference (dependent of pretty much any battery source) to sound an alarm when the batteries voltage drop to a certain level. I managed to find some 1% 10K resistors at my local electronics store and with your code it shows 6.5 volts with 4 fresh AA alkaline batteries, the actual voltage of the batteries is 6.43 volts using an old Micronta DMM to check them but I think that's ok. I connected a 5k pot to the ADC as well and it Max's at 10.0 volts and down to 0.0 volts, I'm hoping that's ok? This is my first time working on a project that uses batteries so it should be interesting. I have the reference push buttons code set up so I can set it to tenths of a volt, just like the code you sent me. I can't wait to get some good voltage regulators to try it out.

    Thanks man..........

    Issac wrote:
    Just a thought !
    When using the ACIN command for A/D conversion
    How is this turned off before going to sleep ?
    Does pbp automatically take care of it

    Hi Issac,

    What I did is to use ADCON1 = 7 statement to turn off the ADC then I set the ADC pin as an output and then set it low with PORTA.0 = 0, that seemed to work good. I noticed that I saved on my milliamp draw by setting the ADC pin low after shutting it off. Before I tried setting it low, the consumption didn't go below (if I remember correctly) about .068mA and would fluctuate (bouncing up and down) up to about.086mA. Then after I set it low it dropped to about .006mA minimum and fluctuates up to about .044 -.060mA and about every 4 or 5 seconds it jumps up to .104mA but just for a ever so brief time, so it did make a big difference forcing it low. To turn the ADC back on I just used Trisa.0 = 1 then ADCON1 = $0E or ADCON1 = 2 but that'll depend on which chip your using..........good thing for me they keep Archives! LOL

    Maybe someone could tell me if that's the proper way of doing it, I would imagine there is more than one way of doing it for sure. I just ordered some MIC2954, 250mA Low Dropout Voltage Regulators. The web site I ordered them from just listed them as MIC2954, I don't know if their MIC2954-02BZ or MIC2954-0B3Z or even what the difference is, I think maybe I read something about .5% and 1% but their suppose to be pretty good for battery operated micro's. I also read you have to play around with the capacitor values to get the minimum amp draw. It looks like their pin compatible with a 7805 in a TO-92 case. It says in the data sheet that (if I'm reading it properly) that it uses a low quiescent current (120mA typical) and that it will operate down to 2 volts and produce a 5 volts output? I'm not very good at reading data sheets, anyone here used these before with any success?

    Thanks jessey

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jessey
    It says in the data sheet that (if I'm reading it properly) that it uses a low quiescent current (120mA typical)
    you probably read correct but paste with error...120uA quiescent... wich is more suitable

    i've never use those but they looks good.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Writing good/proper code
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 00:55
  2. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

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