Shop OBEX P1 Docs P2 Docs Learn Events
How to deal with dying battery? — Parallax Forums

How to deal with dying battery?

ClintClint Posts: 95
edited 2010-01-18 18:18 in General Discussion
Is there a way to detect a dying battery with the SX?

I am running a circuit with the SX that operates on 4-AA batteries.·I would like to be able to do something in my program prior to a brown out·reset·to indicate to the user that the batteries are dying. What can I do?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-01 22:37
    RB1 and RB2 are comparator inputs. On one, put a resistive divider to your battery voltage; on the other, a divider to Vdd. The latter serves as a reference voltage for the former. Once the comparator detects that the battery voltage has fallen below a certain level, the comparator will "trip" and can even interrupt the processor if you like.

    -Phil
  • ClintClint Posts: 95
    edited 2009-05-01 23:05
    Can you explain with a diagram? In my case since I'm powering it from a battery, aren't Vdd and battery voltage the same?
  • ClintClint Posts: 95
    edited 2009-05-02 05:07
    Would something like this work using a Zener diode as a voltage reference? I could use a voltage divider on Vdd for one input and the Zener for a reference voltage for the other.
    225 x 183 - 5K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-02 05:37
    Clint said...
    ... aren't Vdd and battery voltage the same?
    Yikes! Hopefully not! The SX isn't designed to run from 6V, so you need a 3.3V or 5V regulator to keep Vdd within spec. But, yes, your circuit would work if "Vdd" in the schematic is replaced with "Vbat". Instead of the zener, you could also use a precision voltage reference, like the LM336.

    -Phil
  • ClintClint Posts: 95
    edited 2009-05-02 05:55
    Thank you for the suggestion Phil. I looking at the voltage reference right now. *EDIT* I stumbled on the LM385. It looks like it might be better suited for this and would replace the Zener in the above diagram. What do you think? *ENDEDIT*

    Yes you're right my circuit has a 5v regulator. Everything goes through the regulator. The problem is if I dip below about 4volts (Vdd, after the regulator) the circuit starts to misbehave.

    I don't understand your original suggestion:
    Phil Pilgrim (PhiPi)·said...
    On one, put a resistive divider to your battery voltage; on the other, a divider to Vdd.
    Even if my battery voltage dipped below 5volts, the voltage after the regulator (Vdd) would always be less than the voltage before the regulator (Vbatt), wouldn't it? Is there something I'm not understanding about your suggestion that would let this tell me when Vbatt·is too·low?

    Post Edited (Clint) : 5/2/2009 6:15:56 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-02 06:17
    I was assuming that you were planning to signal a "low battery" condition before your regulator dropped out of regulation and dipped below 5V. Since that's not the case, an external reference is your best bet. An LM385 is also a good choice.

    -Phil
  • pjvpjv Posts: 1,903
    edited 2009-05-02 18:26
    Hi All;

    Something that twigged me a while ago from what BEAN said...... the TTL levels in the SX are 1.4 volts regardless of the supply voltage. Therefore I believe one could use that fact as a reference (perhaps not too precise) and simply have a voltage divider from the battery to ground, and the tap to a TTL level input on the SX. Nothing further required, not even the comparator, just two resistors.

    If that works, then to make it even better, do not ground the bottom end of the divider, but connect it to a low level·SX output instead to effect the ground. Now, under software control.·you can switch that output to an input and effectively disconnect the circuit, preventing battery drain through the divider. Then under software control, every once in a while, effect the output condition again, take a reading, and switch it off again.

    Pretty neat if that all works.

    I have not tried this, but it sounds like a pausible solution.

    Cheers,


    Peter (pjv)

    Post Edited (pjv) : 5/2/2009 6:33:50 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-02 19:13
    Another option here is a three-pin voltage detector (supervisor). These are available in a whole range of voltages and output polarities, typically require microwatts of power, and are invulnerable to microsecond voltage glitches. Microchip's TC54- series draws only 1uA and includes a voltage reference, divider, and comparator. It's available in a TO92 package, as well as SMD.

    -Phil
  • ClintClint Posts: 95
    edited 2009-05-03 00:07
    Peter that is a really interesting suggestion. I like the minimization of additional components.
  • ClintClint Posts: 95
    edited 2009-05-13 20:31
    pjv said...
    Something that twigged me a while ago from what BEAN said...... the TTL levels in the SX are 1.4 volts regardless of the supply voltage. Therefore I believe one could use that fact as a reference (perhaps not too precise) and simply have a voltage divider from the battery to ground, and the tap to a TTL level input on the SX. Nothing further required, not even the comparator, just two resistors.
    Do I understand correctly that this is based on the TTL input threshhold? In other words, applying anything over 1.4volts to a TTL input will be considered a·logic "high" while anything below 1.4volts would be considered logic "low"?

    As an example, if I wanted the input to go logic "low" when Vdd is below 4 volts, I could use the following circuit and resistor values:
    595 x 418 - 19K
  • BeanBean Posts: 8,129
    edited 2009-05-13 23:43
    Yep, that should work.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • ClintClint Posts: 95
    edited 2009-05-14 00:30
    Where did you find the 1.4v value for the threshold for logic high/low? I could not find that information in the SX datasheet on the Parallax downloads. Did I miss something? Do you know how accurate that threshold would be?
    *EDIT* I see in the SX/B Online Help that when configured for TTL, the input threshold is indeed 1.4volts. Do I need to configure anything using an SX28 or are inputs automatically TTL when I used the "INPUT" command?

    I will try this out on my development board and see how well it works.

    Post Edited (Clint) : 5/14/2009 12:51:20 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-14 03:59
    The logic threshold may be temperature-dependent. 'Something to consider if temperature extremes are a factor.

    -Phil
  • BeanBean Posts: 8,129
    edited 2009-05-14 11:32
    Clint,
    · The default threshold is TTL (or 1.4V). If you want to make the input CMOS (1/2 Vdd) then add do it like so:

    VSense  PIN RB.0 INPUT TTL
    Switch1 PIN RB.1 INPUT CMOS
    

    [noparse][[/noparse]edit] Of course for your purpose you would want TTL mode NOT CMOS mode.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...



    Post Edited (Bean (Hitt Consulting)) : 5/14/2009 4:40:47 PM GMT
  • pjvpjv Posts: 1,903
    edited 2009-05-14 15:19
    Hi;

    No, Terry..... I think CMOS defeats the concept because its switching threshold is half of the supply, rather than a fixed voltage. It is a fixed voltage that is required to be able to infer the supply (battery) voltage. Of course, if there is a regulator involved, then many options become available.

    Cheers.

    Peter (pjv)
  • BeanBean Posts: 8,129
    edited 2009-05-14 16:37
    Peter,
    Oh yeah. I was just showing HOW you would specify cmos mode if you wanted it.
    Sorry for the confusion.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • ClintClint Posts: 95
    edited 2009-05-14 17:24
    Since the default is TTL, I will not do anything in my programing other than monitor the input. If it's high, I will assume the battery is good. If it is low, I will latch a bit and do some sort of low battery routine.

    Thanks for the help. I'll report back after I try it out.
  • ClintClint Posts: 95
    edited 2010-01-15 20:04
    Is there any reason this circuit would cause problems if it's connected and powered while programming?

    attachment.php?attachmentid=60883
  • Shawn LoweShawn Lowe Posts: 635
    edited 2010-01-15 21:27
    No, it should not. What problems are you having.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • ClintClint Posts: 95
    edited 2010-01-15 22:51
    It may be entirely unrelated, but I am getting "Chip Connection Failed" about 4 out of 5 times when connecting the SX Blitz to my custom printed PCB which contains the above circuit. It's not the only circuit on the board, but it is the only one that applies voltage to any of the input pins while programming. When I connect my SX Blitz to the SX-Tech board containing one SX chip and no other circuits, it connects reliably every time. *EDIT: this may simply be a problem with the straight header I'm using on my custom PCB

    Another thing I've noticed is that if the board is completely unpowered and I measure the resistance across R1·OR the resistance across·R2, they both show about 33kohms·on the voltmeter even though they were definitely 51k and 100k resistors (measured before·soldering onto·the board). This makes me think the SX chip is allowing a path to Vss or Vdd or both.

    Furthermore, with this circuit connected and powered, I get an intermittant low signal on the pin (RB#) even with a steady good voltage from a battery source. I think I know this because if I have a simple program which sets an output high for an LED when the pin RB# goes low, the LED will flicker. If I use any sort of logic in my program that latches based on input pin RB# going low,·it will latch. I put a voltmeter from Vss to the pin RB# and it shows a steady voltage above the 1.4v logic threshold, but perhaps I would need an oscilloscope to see if it's actually going below the threshold intermittently or if the voltage isn't the culprit.

    Post Edited (Clint) : 1/15/2010 11:13:43 PM GMT
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2010-01-16 01:19
    I think you're going to need some kind of transient tolerance in your software. Say start a counter when you sense that input going active and then after a short period if it's still active, then trigger your response. Also, have you measured how much current your two resistors are pulling from your batts? You may want to do as suggested above and only "enable" them when you want to test the batt level.
  • ClintClint Posts: 95
    edited 2010-01-18 18:18
    Shmoopy said...
    I think you're going to need some kind of transient tolerance in your software. Say start a counter when you sense that input going active and then after a short period if it's still active, then trigger your response. Also, have you measured how much current your two resistors are pulling from your batts? You may want to do as suggested above and only "enable" them when you want to test the batt level.
    For transient tolerance I put a counter in my program that increments every scan that the input is low. If the input is high the counter resets. Once the counter reaches some high threshold, it latches a bit that indicates a low battery. This seems to work okay, but I still question the flickering low signal. Why would it bahave that way?

    I haven't measured the current through the resistors, but I will do that.
Sign In or Register to comment.