1
\$\begingroup\$

I'm trying to make a voltage sensor (battery input[0-12v] ) with an output of 0-5v with a voltage divider. I'm gonna read the voltage through a microcontroller and I'd like to know if there is something else in the process I have to add in the circuit.

\$\endgroup\$
10
  • \$\begingroup\$ What is the sensor connected to? What (or who) uses this sensor's output? That said, yes you can use a pair of resistors to convert a 0-12V input source (if you know the impedance of that source) into a 0-5V output (if you know the impedance its driving and these details don't all conflict with each other.) \$\endgroup\$
    – jonk
    Commented Aug 7, 2016 at 4:30
  • \$\begingroup\$ I'm gonna sense the voltage of a battery that's used to energize a solenoid valve. \$\endgroup\$
    – Yudop
    Commented Aug 7, 2016 at 4:32
  • \$\begingroup\$ What is it that now observes the 0-5V output? A micro? \$\endgroup\$
    – jonk
    Commented Aug 7, 2016 at 4:33
  • 1
    \$\begingroup\$ I'm reading the voltage of the battery to know if its level is too low. \$\endgroup\$
    – Yudop
    Commented Aug 7, 2016 at 4:38
  • 1
    \$\begingroup\$ If this is a car battery, then you probably need some serious input protection against load dump events. \$\endgroup\$
    – jonk
    Commented Aug 7, 2016 at 5:00

3 Answers 3

2
\$\begingroup\$

Most microcontroller inputs are protected by diodes to each rail. These diodes aren't very big, so they can't take a lot of current. You want to be sure that the input pin's protection diodes aren't accidentally subjected to currents that exceed their maximum specification. If you design your divider appropriately and don't make any other mistakes, then this is pretty easy. You just make sure your divider's node voltage doesn't go much lower than GND and doesn't go much higher than \$V_{cc}\$. I tend to prefer to add another resistor, though, going from the divider midpoint node to the input pin on the micro. Just in case one resistor is accidentally shorted for a moment. In the case of the MSP430x2xx family, this absolute maximum diode current value is \$\pm\$2mA.

Leakage current of the I/O pin used for an ADC (or comparator, I suppose) needs to also be consulted. In the MSP430x2xx family case, this is often around \$\pm\$50nA, worst case.

Here's an example circuit I might try:

schematic

simulate this circuit – Schematic created using CircuitLab

I started out assuming that I wanted the absolute maximum diode current to be well under 2mA -- let's call it 1mA. Assuming the battery voltage might accidentally get up to 14V or so, and assuming that somehow \$R_1\$ is momentarily shorted, I want \$R_3\$ to be more than \$\frac{14V-V_{cc}}{1mA}\$. With \$V_{cc}\$ of 5V, this means perhaps 10k\$\Omega\$. Just as a check, the worst case leakage current through \$R_3\$ leads to a drop of 500\$\mu\$V (which is an acceptable accuracy error, I think.)

The leakage of 50nA also suggests that if I want to keep errors under 0.1V or so, that I could tolerate a divider impedance of about 2M\$\Omega\$. So I decided that a 470k\$\Omega\$ is fine for \$R_1\$.

What remains is \$R_2\$. I decided that the center node voltage at \$V_x\$ should be about 2.5V when the battery voltage is at that arbitrary over-voltage value of 14V. So this set \$R_2\$ to 100k\$\Omega\$. At 12V, \$V_x\$ will be closer to 2.1V or so. Well within range of many ADCs.

You could do more. Or you could do it differently. I used higher resistor values because you asked about current consumption. This divider won't consume much power. But you could also consider a way to disable the divider entirely when it wasn't in use for even less power. Or you could lower the values of \$R_1\$ and \$R_2\$ to provide more load (against static.) Or you could try and use a timed RC constant to make your measurements, instead. You could also add external diodes from either the \$V_x\$ node or the ADC pin to both rails. There are more ideas, I'm sure.

\$\endgroup\$
0
\$\begingroup\$
  1. Unless the solenoid valve is not loading your battery, you are ok first cut.

  2. As you are going to sense the voltage inside micro, it has to be with ADC. And generally, ADC's inputs have very high impedance hence there is no chance that chip will sink huge current.

  3. Still to be on safer side, when unknowingly you make the sense pin of microcontroller as output and make it zero, this is worst case that can happen. So you connect upper resister in voltage divider with value greater than (12/10mA) = 1.2K. Better be around 10K and accordingly you calculate the bottom resistance.

\$\endgroup\$
0
\$\begingroup\$

There will be a maximum allowable input impedance for a microcontroller ADC (or an on-chip comparator). A typical maximum recommended value for some 8-bit micros is 10K.

So if we assume the actual voltage is 0-12V (a lead acid battery will be more like 14V when charging), you need a voltage divider with a 7:5 ratio for R1:R2 and R1 || R2 <= 10K. Let's assume we want the highest safe value.

Solve that and check for standard E96 values and you get R1 = 23.7K and R2 = 16.9K. Ratio is 7:4.991 and R1||R1 is 9.86K, which is < 10K. It will draw 300uA from the battery. To reduce that you'd need to add an active amplifier, assuming the 10K is a valid number.

If you want to protect against transients you can add some clamping. Suppose you reduce the divider values to about half, and add a 4K99 in series with the input. Then add clamping diodes to the supplies.

schematic

simulate this circuit – Schematic created using CircuitLab

The 1N4734 zener prevents the supply voltage from rising above 5.6V (nominal) even with large positive transients (most regulators won't sink current). Even with +/-120V spikes, the current through the diodes will be around 10mA, which is quite easy to deal with. If your circuit is guaranteed to draw more than 10mA (maybe you have an LED indicator) and 120V spike resistance is okay, you can leave out D3.

R4 is allotted half the total source impedance to keep the current through the microcontroller input protection networks under fault conditions relatively low- it will likely be in the hundreds of uA worst case.

R3 is a resistor (5% is okay) that makes the divider ratio exact for nominal (standard) resistor values. Note that this modified circuit draws about double the current from the battery (about 0.6mA). If there is a lot of noise on the signal you can parallel R2 with a capacitor, preferably a low leakage type such as a 1uF X7R ceramic.

If you are using the microcontroller power supply as your ADC reference the reading will only be as accurate and stable as the 5V supply.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.