How to read a 12V battery voltage with AVR ADC

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

I'm using a simple voltage divider (with resistors) to read a 12V battery voltage with an ATmega128 ADC.

I would like to protect the ATmega128 from connecting a 24V battery, for instance.
The voltage on the ADC pin would be twice and it may damage the ATmega128.

How can I protect it?

Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The simplest way would be to put a zener diode across the lower resistor in the voltage divider. The upper resistor will protect the zener from blowing.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or, because zeners don't have a particularly sharp voltage cutoff, you may wish to use three resistors in series in your divider, V+ R1 R2 R3 Gnd.

The Zener goes across R2 and R3 to Gnd.

The R2 R3 junction goes to the AVR pin.

This allows you to clamp the R2 R3 at a voltage well above the 5 V, (or 3V ?), level you are feeding into the AVR.

Just another option.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put a low current Schottky diode between the ADC input and processor Vcc (cathode to Vcc). This will prevent that node from exceeding the over-voltage input limit. The upper resistor limits current to a fairly small value (probably less than 1ma with 24V source). It should be nice and safe.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Put a low current Schottky diode between the ADC input and processor Vcc (cathode to Vcc). This will prevent that node from exceeding the over-voltage input limit.

Somehow that technique, which used to be the norm a few years ago, is now beginning to scare me. These new chips are so darned power efficient that dumping the excess voltage into the power supply might well raise the power supply above safe limits. :(

Maybe a tranzorb instead of a zener would be best. Expensive, but safe. Fast response, sharp knee.

If you think education is expensive, try ignorance.

Last Edited: Thu. Jun 19, 2008 - 10:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim is as usual 100% correct.

The 'other' Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If your voltage divider is of sufficient resistance then you don't need any additional protection bejond the buil-in protection diodes of the AVR. There is even an official Atmel application note where the AVR is connected directly to the mains with a resistor and no additional parts.

Markus

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Use a high resistanse voltage divider, then connect it to an op-amp used as buffer and then connect it to the adc input.

or
2. Use a low resistanse voltage divider (maximum 10K in series) connect the resistor to an open drain output instead of gnd and the voltage divider output to the adc input. When you wanna take a measurement first you have to enable the open drain. When you finish disable the open drain output. Don't forget to connect a schotky diode from the divider's output to Vcc to protect the adc input from high voltages.

I hope this helps.

Michael

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

markus_b wrote:
If your voltage divider is of sufficient resistance then you don't need any additional protection bejond the buil-in protection diodes of the AVR. There is even an official Atmel application note where the AVR is connected directly to the mains with a resistor and no additional parts.

Markus

Thank you all!

I guess Markus is right, though I couldn't find the app note you've mention (can you tell me which one is it?): avr micros have internal ESD protection diodes.
I've read in the app note AVR040 in the 4.9.1 section. Only the RESET pin needs an external diode (in case you don't use high voltage programming).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm afraid I don't remember which appnote it was. It is a couple of years old and the topic is detecting zero crossing of AC.

Markus

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One critical thing to be aware of with zeners is the previously mentioned 'knee' characteristic. Say you used a 5V1 zener and expect it to conduct at 5.1 volts - it will but it has already started conducting at a lower voltage. When part of a resistor divider, you'll notice that the top end of your analog range is not linear due to current flowing through the zener.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI, logic_bit..I think if you are worried about voltage greater than 12V, then you must put a greater than 12V zener(14V maybe) across Vin. This will make sure that an input voltage greater than 14V will be clipped. Be careful with voltage divider, input to the ADc should have resistance not greater than 10k ohms..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jasperman wrote:
HI, logic_bit..I think if you are worried about voltage greater than 12V, then you must put a greater than 12V zener(14V maybe) across Vin. This will make sure that an input voltage greater than 14V will be clipped. Be careful with voltage divider, input to the ADc should have resistance not greater than 10k ohms..

I guess I've forgotten that:
"The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less" - from ATmega128 datasheet.

So, a large voltage divider is out of the question.

From the datasheet we can check that there are internal diodes that protect from ESD, provided that incoming current is externally limited not to damaged the chip.

Jim:
Even if I put a schottky between ADC input pin and VCC, that won't guarantee that no current will flow into the chip, right?

Maybe a zener or tranzorb to GND would be better?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

So, a large voltage divider is out of the question.

Actually, no. If you remember your Thevenin equations, the effective output impedance of a voltage divider is equal to the value you get by paralleling the two resistors. So if the lower resistor in the divider is less than 10K, you should be fine.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now imagine I want to measure the voltage of a point that is outside the board.
In this situation I must be protected against ESD.

Are a small voltage divider (10K) together with the ATmega128 internal protection diodes enough to protect the circuit against ESD and other EMC issues?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

logic_bit wrote:
"The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less" - from ATmega128 datasheet.

So, a large voltage divider is out of the question

No, I don't think so in your case. If you would want to measure a fast moving AC signal - yes, but to measure your battery - no. The data sheet mentions an 'analog input resistance' of 100MO. If you measure the fairly static battery even a few 100k will work fine.

logic_bit wrote:
Now imagine I want to measure the voltage of a point that is outside the board.
In this situation I must be protected against ESD.

Are a small voltage divider (10K) together with the ATmega128 internal protection diodes enough to protect the circuit against ESD and other EMC issues?

If your voltage divider has enough resistance to keep the current below what the protection diodes can handle at the highest/worst voltage you expect, then you are fine.

Here the pointer to the app note I mentioned: 'AVR182: Zero Cross Detector' http://www.atmel.com/dyn/resources/prod_documents/doc2508.pdf
I features an AVR, directly connected to 230V mains via one 1MO resistor. The appnote mentions that it is not recommended that the protection/clamping diodes get more than a 1mA load. I have not found this number in a data sheet, though.

Markus

Markus