Hello, welcome to our forum.

It looks like you have registered but you have not yet posted and messages. Our requirements are that you must post at least two messages, to allow the moderators to review your registration, before you will be allowed access to the full range of forum areas.

Please make a couple of posts, until then you may see a notice that says you are banned from certain forum areas.

Thank you.

# Thread: Voltage monitor for car battery

1. ## Voltage monitor for car battery

Can one use the ADC converter of a pic to measure the voltage of a 12V car battery?
I know one can use the ADC to monitor voltages on small batteries but I am scared of the high
currents involved with a car battery.
If one can use the pic itself, what additional measures should be put in place or should I rather
go for a dedicated voltage transducer to monitor the car battery?

2. Yes you can, but first you have to lower the supply voltage for the picprocessor. This can be done by using a LM78L05 and some capacitors.
Then you have to build a voltage divider for the measuring of the 12 volts, because the adc in the picprocessor may not come above the supply voltage.
Say bluid a divider of 3 so that 4 volts measuring is 12 volts of the battery.
In the software you can multiply than by 3 again.

3. Originally Posted by mat janssen
Yes you can, but first you have to lower the supply voltage for the picprocessor. This can be done by using a LM78L05 and some capacitors.
I don't think that would work. The regulator will simply give you a 5v supply from the 12v battery, it will never fall below 5v because the car battery would never get this low. The simple way is to use a voltage divider made by connecting two resistors accross the 12v line and then connect the pic to the junction between the two.

If you used a 58K and 41K with a 12v supply you would get 5v, however the state of a car battery is such that it's voltage will vary under charge and drain, so you would need to make allowances for that. You might find that under charge the voltage could be around 13.8v, falling to 10v under load.

4. use an op-amp set up has a devider you can then put upto 20v in and get 0-5v out and for safety tie a 5V zener diode to prevent damage to the pic or just a resistor devider

I personal use op-amp has i can measure up to 60V

5. Hello. I've been using the attached circuit and the following code to measure the battery condition on a 12V sealed rechargable gell cell. The code goes like this:
batterycondition var byte

if batterycondition < 192 then beep

Perhaps tweaking the adcin value would work for lead acid. It may have a different discharge curve.

6. Originally Posted by malc-c
I don't think that would work. The regulator will simply give you a 5v supply from the 12v battery, it will never fall below 5v because the car battery would never get this low. The simple way is to use a voltage divider made by connecting two resistors accross the 12v line and then connect the pic to the junction between the two.

If you used a 58K and 41K with a 12v supply you would get 5v, however the state of a car battery is such that it's voltage will vary under charge and drain, so you would need to make allowances for that. You might find that under charge the voltage could be around 13.8v, falling to 10v under load.
The OA didn't say use the regulator for the sensed voltage, but for the supply voltage. He also recommended a 3:1 voltage divider for the sense. Personally, I'd use a 4:1 because the car battery can get up into the mid-14 volt range with some charging systems.

I have no idea where you get 58k and 41k resistors; these aren't standard RETMA values. I'd use a 100k and a 22k-10k variable in series to set the voltage accurately, or do some other tricks in software for calibration.

Jim

7. passion1, Use a 10.2K 1% and a 2.55k 1% for the voltage divider. This gives you 25.00 volts full scale or a 20% division. I often use these values when not being concerned about the 1mA. current draw @ 12 volts.

Dave Purola
N8NTA

8. I will but in here
I use a 3 to 1 divider to monitor my solar battery bank. Two 10Ks in series from (+) and one 10K from (-). if peak voltage is 15 you get 5. Voltage drops to 10, you get 3.3.
This works for me.

9. Hi All

Thank you very much for the advice!

10. Originally Posted by weirdjim
The OA didn't say use the regulator for the sensed voltage, but for the supply voltage.

Originally Posted by weirdjim

I have no idea where you get 58k and 41k resistors; these aren't standard RETMA values.
Whislt not standard a quick google will show that they do exist, or simple enough to make up the value.

11. Hi,

Don't forget to suppress the voltage spikes! A cars electrical system can generate spikes easily above 50v. Try to take the measurement points as close to the battery as possible. Also damp the takeoff point from the resistor divider with a small capacitor (10uF). I would also use some inductors in the supply line to protect the regulator and PIC.

Bob

12. I would suggest that you wire your battery monitor circuit the other side of the ignition switch. Otherwise, it will will be slowly draining the battery all the time it is connected - it is (reasonably) unlikely that you would want to monitor the battery while you are not in the car.

13. I wired three 10K ohm resistors in series (because I had lots of 10K resistors!) to form a simple voltage divider. After double checking with a multimeter, I connected porta.0 of a 16f877 to the resistor node that was less than 5 volts, and used the following code to read and display the battery voltage;

/code
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 0 ' Set clock source (Fosc/2)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
ADCON1 = %10001110 'Right justify, channel 0 is analog
bat_volts = (bat_volts */500)>> 2
lcdout \$fe,\$80+15,dec(bat_volts/100 *3),".",dec1 bat_volts
/endcode

Please note that the Pic itself is powered via a 7805 regulator as suggested in an earlier post, with appropriate capacitors, and a fuse just to be safe. I didn't use precision resistors, I didn't need great accuracy. You might add a zener diode for extra protection.

I hope this helps get you started.

Jerry.

14. Originally Posted by chuck
use an op-amp set up has a devider you can then put upto 20v in and get 0-5v out and for safety tie a 5V zener diode to prevent damage to the pic or just a resistor devider

I personal use op-amp has i can measure up to 60V
Chuck / Jerry

Thanks for the advice! Could you be specific with regard to where the 5V zenere diode must be placed. (I'm rather new to electronics!)

THANKS!

15. Originally Posted by BobP
Hi,

Don't forget to suppress the voltage spikes! A cars electrical system can generate spikes easily above 50v. Try to take the measurement points as close to the battery as possible. Also damp the takeoff point from the resistor divider with a small capacitor (10uF). I would also use some inductors in the supply line to protect the regulator and PIC.

Bob
Bob

Thanks for the advice! Could you be specific with regard to where the capacitor must be placed as well as the inductors. If possible, inductance values would be appreciated. (I'm rather new to electronics!)

THANKS!

16. Passion1

here is web link with values and op-amp

http://www.winpicprog.co.uk/pic_tuto...ogue_board.htm

Has for the zener diode you just put the block end to say PORTA.0 and the ohter to ground.

hope this helps,

chuck

17. Hi,

As per your request please find attached a quick and basic suggestion for values I would use.
As you have 10k resistors I used these.

Bob

18. Bob , Chuck and other

Thank you all for the advice. I really appreciate it!

19. > Has for the zener diode you just put the block end to say PORTA.0 and the ohter to ground.

No!

A Zener starts to draw current long before it gets to it's stated voltage... it doesn't just suddenly 'turn-on' at it's rated voltage. As soon as the Zener starts to draw current (a 5V6 Zener might start as low as 3v!!!) then it will throw your Resistor Voltage Divider out and you will no longer have the ratio voltage drop you expect!!!

A Zener is good for protecting Digital ON/OFF inputs but not for precise measurement ADC or Comparator inputs.

20. ## simple Inputs extra protection ...

Just need to paste µChip built-in input protection by adding two low leakage diodes ( BAW62 i.e.) to clamp input voltage to the Pic supply rails ...

1N4148 also will fit for the here-required specs ...

Alain

21. Bob

I just noticed that circuit CarVoltage.jpg specifies 10nf caps while you previously said I should use a 10uf cap? Which one is it?
Thank you again.
Last edited by passion1; - 2nd August 2007 at 11:48.

22. Originally Posted by Melanie
> Has for the zener diode you just put the block end to say PORTA.0 and the ohter to ground.

No!

A Zener starts to draw current long before it gets to it's stated voltage... it doesn't just suddenly 'turn-on' at it's rated voltage. As soon as the Zener starts to draw current (a 5V6 Zener might start as low as 3v!!!) then it will throw your Resistor Voltage Divider out and you will no longer have the ratio voltage drop you expect!!!

A Zener is good for protecting Digital ON/OFF inputs but not for precise measurement ADC or Comparator inputs.
Melanie

How should I modify Bob's circuit CarVoltage.jpg if I should not use a Zener?

23. Thanks Melanie,

As always you are correct (damm! I would love to be a male chauvinist. But I always need a woman to keep me out of trouble!).

For cheap and effective protection I willingly sacrifice a bit of accuracy (or compensate in software). The resistor divider values can be reduced and a better choice of zenner to minimise the effect.

Alternative is to suppress the supply line and bit more capacitance on the analog input and miss out the zenner and ensure the resistor divider will NEVER give more than 5v. It all depends on the accuracy and speed you need from the circuit?

An extreme example I once had an alternator go on a company car and it pushed 18volts around. Don't know how long it was like that as it was only noticed when it managed to destroy a lot of the electronics on the car.

Bob

24. ## Excellent idea

Excellent divide by three idea (10k 10k 10k) given by Dave (mackrackit).
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1900&stc=1&d=118606737 9" />

25. Originally Posted by Pic_User
Excellent divide by three idea (10k 10k 10k) given by Dave (mackrackit).
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1900&stc=1&d=118606737 9" />
The automotive environment can be very nasty, as someone has already said. Here is how I go about it:

First of all, put a diode in series with the 7805 regulator for reverse polarity protection. The one you have now will burn out the 10ohm resistor if you connect it up backwards.

It is always a good idea to use a Transorb (instead of the zener) - they are much better at catching nasty spikes. On a 12v system, an 18v Transorb should be ok.

I would also add some inductance before the 7805 - somewhere around 1mH works for me.

For maximum reliability, I always try and isolate or buffer the micro from the "real world" signals as much as possible. Try to make it and "island", if you like. For digital inputs, this means using opto-isolators. For analog inputs I buffer the signals with RRIO op-amps powered from the +5v rail. Doing this greatly reduces the chances of nasty spikes reaching your micro. Outputs are usually buffered anyway through drivers, transistors, fets, relays etc. Adding 1nF ceramic decoupling capacitors to every i/o on your pcb can also be worthwhile.

The other important point is to take care when joining the ground connections together on your pcb. Keep analog and digital grounds separate. Try to use a "star" type connection where all the grounds join at one place - usually at the filter capacitor/regulator. This point should have the lowest impedance path for noise/spikes.

There are many more "tricks" to combat the nasties found in the automotive environment. A a quick google using "automotive interference suppression" or similar will probably produce some worthwhile results.

Hope I was of some help.

Regards,

Andy

26. I guess it all comes down to how much protection should be used on a \$10.00 device. As Bob pointed out the alternator burned other electronics in the vehicle.

Now to build a device so the vehicle can go up in flames but we can still read the voltage.

The polarity protection diode is a good idea.

I am talking from many years of building control systems for spray rigs mounted on tractors with 12 and 24 volt systems. Pressure transducers, automatic valves, etc. So far the problems mentioned have not been a problem.

The 7805 is good for 35 volts, I think. The resistor network could be 4 to 1 instead of 3 to 1 for protection at the ADC if you are worried.

Add the polarity diode to the schematic by Pic_User and call it done.

27. ## a circuit designed by a committee

I feel like this is a circuit designed by a committee.

The idea of the 10 Ohm resistor was to put a “bungee cord” protection for the Zener. Something to absorb a small surge for a short time to soften the blow on the Zener.

I was hoping Melanie would come to my defense about the reverse polarity diode. The idea is to burn out the 10 Ohm “fuse”, if someone installs the instrument with the polarity revered. It works okay on equipment that gets installed once and stays hooked up. Not a good idea on a portable tester that has to be hooked up a lot.

If the series diode is put inline in front of the measurement “tap-off”, it affects the accuracy by the forward voltage drop. Even though this “band-gap” voltage is considered to be steady for many purposes, it does change by temperature and current flow. This is the reason the reverse polarity diode (dead short) is sometimes used.

I put Alain’s “low leakage”, good idea in too. Diodes to shunt the over voltage to plus (Vdd) and the reverse voltage is shunted to (Vss) ground (“wraparound diodes”).

What else do we need? As Dave said it is a “cost spent to cost protected” ratio fine line. But fun to discuss!
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1905&stc=1&d=118609804 3">

28. I was hoping Melanie would come to my defense about the reverse polarity diode.
You don't need me to defend you Adam *smiles* just asbestos underpants...

Your original circuit was good - as long as it's a fuseable Resistor (only problem they're expensive). Most amateurs wouldn't know what one of them was so they'd be fitting normal Resistors... then you've got a potential flame-out in a vehicle... mounted next to the flexible plastic piece of gasoline hose they've just fitted whilst parked at the filling station...

Geee... I think I missed my calling - should be writing disaster movie scripts in Hollywood...

For cheap and effective protection I willingly sacrifice a bit of accuracy (or compensate in software). The resistor divider values can be reduced and a better choice of zenner to minimise the effect.
It's not a 'bit' of accuracy, it's a shed-load of it. There's no way of calculating other than manually calibrating your product. Zeners aren't consistent. 5.6v Zener is probably +/- 5% (or even 10%) - well you do the math. To protect the PICs ADC input you need a 5.6v Zener max. That could start conducting at about 3v... therefore your useable ADC input on a PIC is between 0 and 3v tops! Above 3v it's going to be inaccurate because of that Zener. Better to have a larger Resistor Ratio, plan for things going wrong... plan for some twerp putting your device across a 24v truck battery and calculate your Resistor chain accordingly.

For those that are wondering what I'm talking about, and have been taught at college that Zeners conduct at their rated voltage, put your DVM set to mA in series with one and wind a PSU up slowly (via a current limiting Resistor). You will discover they start conducting long before you actually expect them to. Believe nothing - trust no-one (especially college lecturers!)... whatever happened to Mulder & Scully?...

29. Hi Everyone

Thank you all for the excellent advice!!

30. Originally Posted by Pic_User
I feel like this is a circuit designed by a committee.

The idea of the 10 Ohm resistor was to put a “bungee cord” protection for the Zener. Something to absorb a small surge for a short time to soften the blow on the Zener.

I was hoping Melanie would come to my defense about the reverse polarity diode. The idea is to burn out the 10 Ohm “fuse”, if someone installs the instrument with the polarity revered. It works okay on equipment that gets installed once and stays hooked up. Not a good idea on a portable tester that has to be hooked up a lot.

If the series diode is put inline in front of the measurement “tap-off”, it affects the accuracy by the forward voltage drop. Even though this “band-gap” voltage is considered to be steady for many purposes, it does change by temperature and current flow. This is the reason the reverse polarity diode (dead short) is sometimes used.

I put Alain’s “low leakage”, good idea in too. Diodes to shunt the over voltage to plus (Vdd) and the reverse voltage is shunted to (Vss) ground (“wraparound diodes”).

What else do we need? As Dave said it is a “cost spent to cost protected” ratio fine line. But fun to discuss!
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1905&stc=1&d=118609804 3">

Just one more thing to be aware of - check the datasheet of your intended PIC for the ADC source impedance. Most PIC's have a maximum recommended analog source impedance of somewhere in the range 2k to 10k. To stay within these specs you will obviously have to decrease the value of the voltage divider resistances or buffer the divided voltage with an op-amp.

Regards,

Andy

31. ## asbestos protection

Originally Posted by Melanie
You don't need me to defend you Adam *smiles* just asbestos underpants...
... then you've got a potential flame-out in a vehicle... mounted next to the flexible plastic piece of gasoline hose they've just fitted whilst parked at the filling station...

Geee... I think I missed my calling - should be writing disaster movie scripts in Hollywood...
> flame-out in a vehicle... mounted next to the flexible plastic piece of gasoline hose!

Now THAT is a second good reason to keep wearing asbestos underpants!
Does asbestos protect one from whip lashes?

32. Impedance of a DC voltage divider.

If I remember right

R or (Z) = (R1*R2) / (R1+R2)

Using the 3 to 1 example with 10K resistors - Z = 6.6K
Using the 4 to 1 example with 10K resistors - Z = 7.5K

No problem here, Besides that, I use the 3 to 1 example, It does work.

Asbestos <> RoHS Compliance

33. Originally Posted by mackrackit
Impedance of a DC voltage divider.

If I remember right

R or (Z) = (R1*R2) / (R1+R2)

Using the 3 to 1 example with 10K resistors - Z = 6.6K
Using the 4 to 1 example with 10K resistors - Z = 7.5K

No problem here, Besides that, I use the 3 to 1 example, It does work.

Asbestos <> RoHS Compliance
The OP hasn't specified a device. If using the popular 16F88, the maximum recommended analog source impedance is only 2.5k. It is always best to stay within the specifications of the device for reliable results.

Regards,

Andy

34. Originally Posted by Andy Wood
The OP hasn't specified a device. If using the popular 16F88, the maximum recommended analog source impedance is only 2.5k. It is always best to stay within the specifications of the device for reliable results.

Regards,

Andy
Are you sure you have the correct data sheet. Section 12.1, paragraph one in the data sheet titled PIC16F87/88 clearly states "The maximum recommended impedance for analog sources is 10K."

I do agree one needs to stay within the specifications if you do not want to see the magic smoke

35. Originally Posted by mackrackit
Are you sure you have the correct data sheet. Section 12.1, paragraph one in the data sheet titled PIC16F87/88 clearly states "The maximum recommended impedance for analog sources is 10K."

I do agree one needs to stay within the specifications if you do not want to see the magic smoke
Now there's a trap - the current datasheet from Microchip states 10k:

However, the (older) datasheet on the melabs site states 2.5k:

http://melabs.picbasic.com/devicedata/30487a.pdf

A good lesson - always ensure you have the latest datasheet!!!

Regards,

Andy

36. And to make sure you are not using old parts. MicroChip seems to make improvements every so often. With all of their products it is hard to keep up.

But I have to wonder, impedance being an AC term, does this apply more to an ADC source that is switching? Like an old load cell driver?

But as far as the original question on this thread, I think it has been answered and designed. Thanks to Adam.

37. ## Circuit Design Committee

Thanks goes to the Circuit Design Committee for the input and to passion1 for asking the all important question.
Great job nailing down the 2.5k 10k discrepancy, I replaced my old PIC16F88 sheet with the newer one.

38. Circuit Design Committee

I like that.

39. ## Thanks Melanie!

I did not know that about zeners. I like many others have been taught that a zener doesn't conduct until you reach or exceed the avalance voltage. After reading your post I pulled out one of my textbooks, which states that this is the case. I then put together a little test circuit, and just as you predicted, my 5.6 volt zener diode was conducting at right around three volts! I had always assumed they would be within twenty percent or so.

Thanks again for sharing your hard won knowledge and experience.

Jerry.
Last edited by b1arrk5; - 6th August 2007 at 02:25. Reason: typo

40. Hi Everyone