Voltage Divider or Circuit for scaling & measuring 12v battery voltage with a 5
![Zoot](https://forums.parallax.com/uploads/userpics/559/nW4UO23UEIWZ4.png)
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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.
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
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
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!
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)········
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
oops beau explained that above
Post Edited (skylight) : 10/10/2007 1:51:36 PM GMT