Shop OBEX P1 Docs P2 Docs Learn Events
Voltage Divider or Circuit for scaling & measuring 12v battery voltage with a 5 — Parallax Forums

Voltage Divider or Circuit for scaling & measuring 12v battery voltage with a 5

ZootZoot Posts: 2,227
edited 2007-10-10 13:26 in General Discussion
OK, I've got a 'bot that is performing very well, and I'm trying to put the finishing touches on it without a lot of rework, rebuilds, new processsor, etc.

It's differentially steered, and at one point I debated constructing an encoder mechanism and (probably) using an SX to handle the quadrature and motor processing functions.

I'm not going to do encoders (see this discussion: http://forums.parallax.com/showthread.php?p=612763), but I do have a greater problem which is the speed difference as the main battery discharges is pretty vast. At full charge, the (unregulated) motor V supply is about 13v. A low-voltage comparator trips at about 10.9v and the 'bot goes into "hungry" mode (at 10.9v the 'bot has about 20 minutes before it won't be able to move it's motors.

The problem is that "full speed ahead" at 13v is way, way faster than "full speed ahead" at 10.9v. The entire platform is clamped at about 80% of full speed anyway (it's too darn fast beyond that for safety). That gives me some overhead, so my thought is to use an extra 10-bit ADC input I have available and check battery voltage and reduce the clamp amount as voltage decreases. I'm probably not explaining this well at all.. in other words,

pseudo code:

if Vbat > 13.8 then maxSpeed = 80 '%
else if Vbat < 10.9 then maxSpeed = 100 '%
else maxSpeed = 100-(((Vbat-10.9)/(13.8-10.9))*20) '%

So as battery voltage falls, the motors are allowed to run faster. I realize the effect will be somewhat non-linear and pretty coarse, but it will be far better than what I've got now (the platform is probably about 30% faster at full charge). It especially affects my PID routines.

I don't need assistance with code, but not sure how to filter the unregulated battery voltage into the ADC.

Would a voltage divider from, say, 14v down to 5v, work? Should I use very high resistance on both sides so I don't waste battery current on the divider itself? The ADC is 5 channel, 10-bit, I2C. All the channels are referenced against a regulated 5v. Is there a better way?

Thanks in advance.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Comments

  • D FaustD Faust Posts: 608
    edited 2007-10-08 21:54
    Makes sense to me! Cut it down by a third.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • skylightskylight Posts: 1,915
    edited 2007-10-08 22:16
  • ZootZoot Posts: 2,227
    edited 2007-10-08 22:33
    I guess I better state my question more concisely --

    I've already got a 5v referenced 10-bit ADC ready to go. I need to measure max voltage in of ~13.8.

    Should I use a simple voltage divider to cut the voltage measured down to < 5v? How could I reduce the current wasted in the divider? Is there a better way to scale (and possibly offset) the measured voltage before sampling?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • metron9metron9 Posts: 1,100
    edited 2007-10-09 16:48
    Yes use a voltage divider. If you have a spare pin to sink the current instead of going directly to ground you can make that pin low, then read your ADC and set the pin back to tristate input, that shuts off the current. I use this to test my battery voltage on solar panels for a device I made. Use resistors so you get a few mA of current. 3k---1k---sinkpin something like that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • ZootZoot Posts: 2,227
    edited 2007-10-09 22:14
    Hey that's a great idea on using an I/O pin for the ground side of the divider -- and yeah, the ADC I have has 5 extra digital I/O pins that are currently unused, so I can use one of those without any big real estate problems.

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • D FaustD Faust Posts: 608
    edited 2007-10-09 22:29
    I'm confused.· If you ground the other side of the voltage divider with an IO it is still going to ground isn't it?· If not, won't if effect how much the ground intrudes into the 12V?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-09 22:54
    A voltage divider has 3 terminals ... the input (12-15V in this case), the tap (maximum 5V to the ADC), and the ground terminal. When the ground is connected to a digital output that is made low, the ground point becomes a little bit above 0V ... like 0.3-0.6V depending on the design of the I/O pin and the amount of current involved. This voltage is also a bit temperature sensitive. That's why this technique isn't used when accuracy is important. The ADC input will shift upwards when the ground is removed. If the I/O pin is made high, the ADC pin will see a voltage probably a little bit higher than the supply voltage (+5V probably), partly because the I/O pin doesn't quite get to +5V and partly the input (12-15V) is pulling the ADC pin higher. If the I/O pin is made into an input, again the +12-15V input will pull the ADC pin higher, but this will be limited by the protective diodes on the ADC input. These usually limit the voltage to +5V plus 0.6V for the diode drop.

    You have to choose the voltage divider resistors to limit the current in any of these cases to a few milliamps at most. The simplest solution would be to use a 5K resistor and a 10K resistor. That would give a 1/3 ratio so a 15V input would result in 5V at the ADC (minus the I/O pin minimum voltage). The current would be limited to about 1ma and the fault current (through the protective diode) would be less than 1ma (15V - 5V / 10K = 1ma).

    When you use an I/O pin like metron9 suggested, that shuts off the divider current if the voltage to the divider is less than the logic supply voltage. In this case, there will still be current because the protective diode will conduct. The added complexity won't get you the benefit you might think.
  • ZootZoot Posts: 2,227
    edited 2007-10-09 23:10
    Somebody said...
    When you use an I/O pin like metron9 suggested, that shuts off the divider current if the voltage to the divider is less than the logic supply voltage. In this case, there will still be current because the protective diode will conduct.
    OK, bear with me because you've opened up something important that goes beyond my particular need -- the protective diodes on a tristate IC pin protect the internal transistors and circuitry from collapsing magnetic fields, short circuits (for a small time, anyway), overcurrent, etc. Do I have that right? Are the diodes cathode side towards the pin? If so, why will there still be current if the pin is put in a Hi-Z state? I don't doubt you at all, Mike smile.gif, but I'm sure I'm missing something basic here...

    Voltage divider with 1ma draw sounds OK, anyway. The 'bot runs off a small auto-sized L/A battery, so the power to this circuit is the least of things. Accuracy not that critical -- I'm still going to use the pot-tuned comparator for platform "hungry" detection, and I'll be losing nearly 800 steps of resolution anyway (from ~13.9-10.9 input I'll only get about 221 steps of range on the 10-bit ADC). I'm probably only going to sample that every 10 seconds or so and keep a running average to dampen the response.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-10-10 04:50
    Zoot,

    If the Input Voltage to an I/O is greater than the supply voltage to the IC, then the upper protection diode becomes forward biased and starts to conduct.
    If the Input Voltage to an I/O is less than the Ground voltage (i.e. a negative voltage with reference to Ground), then the lower protection diode becomes forward biased and starts to conduct.


    In your case it would be the former and not the latter... If the voltage on the middle terminal of the voltage divider became larger than your supply voltage (5V) plus a diode drop (0.3V to 0.6V) then the upper protection diode would become forward biased and start to conduct. Leaving the Ground connection on the divider actually helps you out, by lowering the voltage divider's output to the I/O pin. If you connect the voltage divider's GND terminal to an I/O, then making it an INPUT will just allow the full voltage on the input of the Voltage Divider through to the I/O (Both I/O's actually since the Voltage Divider's GND is now in the loop).

    This Assumes the GND to the Voltage Divider is also connected to an I/O and made an Input:
    Current1 = [noparse][[/noparse]VDividerInput - VSupplyMicrocontroller - DiodeDrop] / TopResistorValue
    Current2 = [noparse][[/noparse]VDividerInput - VSupplyMicrocontroller - DiodeDrop] / [noparse][[/noparse]TopResistorValue+BottomResistorValue]

    TotalCurrent = Current1 + Current2


    This Assumes the GND to the Voltage Divider is fixed to GND and the voltage divider output stays between VSupplyMicrocontroller and GND:
    TotalCurrent = VDividerInput / [noparse][[/noparse]TopResistorValue+BottomResistorValue]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/10/2007 4:56:08 AM GMT
    1091 x 745 - 212K
  • metron9metron9 Posts: 1,100
    edited 2007-10-10 07:00
    Yikes, my bad, thanks for the reply Mike and Beau, remember I am a do it yourselfer with no formal education in electronics. I forgot the voltage would go above the chips supply voltage when the ground was taken away. In my circuit I was using a 1.2V reference and dividing the supply voltage (Battery at 4V and lower as it discharged) The OPS question was for a much higher voltage. Sorry about that. With the current at a few MA however I know that would not be a problem for an AVR as I have read 110 volts directly to a pin with enough resistance the clamping diodes protect the pin.

    So bottom line though using this method even with 13v to 15v and a 10K-5K won't hurt the pin and the current draw would be voltage in minus supply saving in this case perhaps 40% vs directly to ground?

    Dam its 2am again and I learned quite a bit more today in just those two posts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-10-10 10:03
    Thanks Beau,
    It really is quite wonderful to have someone that can tell you exactly what is going on inside a microchip. The rest of us just have to think in terms of the 'blackbox'.

    The I/O interface has a lot of subtle features. I'm still learning.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • ZootZoot Posts: 2,227
    edited 2007-10-10 12:51
    Thanks. I didn't realize there were TWO protection diodes on an I/O pin. That makes sense. I thought there was only one diode (the lower).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • skylightskylight Posts: 1,915
    edited 2007-10-10 13:26
    with my basic knowledge as to how diodes work would I be right in saying that a negative voltage applied to the I/O pin when an input could cause current to flow from GND through the bottom protection diode and damge it if no resistance is present?

    oops beau explained that abovesmilewinkgrin.gif

    Post Edited (skylight) : 10/10/2007 1:51:36 PM GMT
Sign In or Register to comment.