Author Topic: Microcontroller running 3V3 sense 9V battery voltage with ADC  (Read 9890 times)

0 Members and 1 Guest are viewing this topic.

Offline delmadordTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: sk
Microcontroller running 3V3 sense 9V battery voltage with ADC
« on: February 28, 2014, 06:28:07 pm »
Greetings,
I wold like to sense a 9V battery voltage on a microcontroller (ATmega328) ADC. I have found a guide http://www.w9xt.com/page_microdesign_pt15_battery_ad.html however I am quite suspicious about it. The idea in the article is that, you set P0 low to start measurement, and after it set it HIGH again so the resistor divider is not draining battery.  I am planning on using 10k and 5.4k resistor voltage divider. What concerns me is that when the P0 is high (3V3), ADIN pin is almost on battery potential. Also, some hundreds uA flows into the P0 pin. I was thinking about using P-channel MOSFET (circuit in the attachment) to switch ON the voltage divider for battery voltage measurement only for occasional measurement. Will this approach of putting two more resistors and two more transistors in give me some real advantages like protecting MCU from higher voltage, if it can make some harm in this case or less current drained from battery? Should I just use the circuit shown in that article? Thanks!
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5202
  • Country: nl
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #1 on: February 28, 2014, 06:56:09 pm »
Are you running the microcontroller from the same battery? If so the negative from the battery will already be connected to ground and your circuit makes no sense.

If I read the datasheet correctly the input impedance of the ad converter is somewhere around 100M, so you can make a divider with pretty large resistors, minimizing the current flowing trough them.
« Last Edit: February 28, 2014, 07:04:34 pm by PA0PBZ »
Keyboard error: Press F1 to continue.
 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #2 on: February 28, 2014, 07:16:23 pm »
I do voltage sensing on AVR's all the time. I use a resistor dividing in the 400k range, low quiescent battery drain. The battery supplies the regulator that provides 2.5V or 3V (depending on the design) to the AVR. You could increase the resistance even more - the AVR A/D inputs are quite high impedance... all depends on what accuracy you are after and what quiescent current consumption you can live with.

cheers,
george.
 

Offline delmadordTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: sk
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #3 on: February 28, 2014, 07:26:12 pm »
ATmega328 datasheet: http://www.atmel.com/Images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet.pdf
Part: 24.6.1 Analog Input Circuitry
Quote
The ADC is optimized for analog signals with an output impedance of approximately 10k ohm or less.
What exactly does this mean then?

Also I made correction in a circuit.

 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5202
  • Country: nl
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #4 on: February 28, 2014, 07:59:33 pm »
That works, only change R2 to 100K, that will drop the total current from 1.3 mA to 500 uA.

Keyboard error: Press F1 to continue.
 

Online Andreas

  • Super Contributor
  • ***
  • Posts: 3298
  • Country: de
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #5 on: February 28, 2014, 08:31:36 pm »
If I read the datasheet correctly the input impedance of the ad converter is somewhere around 100M, so you can make a divider with pretty large resistors, minimizing the current flowing trough them.

Hello,

This is only true for room temperature.
At higher temperatures the leakage current limits your accuracy significantly.
1uA * 10kOhms = 10mV error voltage referred to the ADC-Pin.

There is still another possible circuit by using a simple logic level N-FET together with the internal 1.2V voltage reference. (see attachment). For 9V applications you can reduce R2 significantly. R1 is chosen to met the "below 10k" specifications of the A/D-converter.

The only restriction is that you can never get more than about 3.3V-1.5V = 1.8V at the ADC-Pin.
This is because the BSS123 needs a voltage difference of 1.5V between source + gate to conduct.

with best regards

Andreas

p.s. the BSS138 is meant for the 1.5V. But with the internal reference the 1.8V of the BSS123 will work too @ 3.3V.
« Last Edit: February 28, 2014, 08:39:56 pm by Andreas »
 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #6 on: February 28, 2014, 09:06:01 pm »
Input leakage current 1uA spec is for a I/O pin. Disable the digital feature of the pin and use is with the A/D and the input leakage will be much lower. As I wrote, I use around 400kohms as my divider impedance and it works FINE.

"The ADC is optimized for analog signals with an output impedance of approximately 10 k? or less. If such a source
is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will
depend on how long time the source needs to charge the S/H capacitor, with can vary widely."

Above from the datasheet, the 10k is due to having to charge the S/H cap. If you are measuring a battery voltage you don't need to sample it quickly. Adding even a 0.01uF cap in parallel with the uC input (to GND) will provide more than enough charge storage to deal with the S/H and still use a high impedance divider.

I've shipped 10's of thousands of AVR based boards and 400k ohm is NOT a problem for input impedance of the divider when used for measuring slow changing signals like battery voltage.

For Atmel AVR stuff the avrfreaks forum has a LOT of information and folk with specific knowledge - that's where I'd call 'home' if I had AVR questions...

cheers,
george.
 

Online Andreas

  • Super Contributor
  • ***
  • Posts: 3298
  • Country: de
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #7 on: February 28, 2014, 09:29:07 pm »
Input leakage current 1uA spec is for a I/O pin. Disable the digital feature of the pin and use is with the A/D and the input leakage will be much lower. As I wrote, I use around 400kohms as my divider impedance and it works FINE.

Believe what you want.
The datasheet tells somewhat different:

"24.6.1 Analog Input Circuitry
The analog input circuitry for single ended channels is illustrated in Figure 24-8. An analog source applied to ADCn
is subjected to the pin capacitance and input leakage of that pin, regardless of whether that channel is selected as input for the ADC. When the channel is selected, the source must drive the S/H capacitor through the series resistance (combined resistance in the input path)."

The only pins that are specified different from 1uA leakage are the comparator pins.

with best regards

Andreas
 

Offline georges80

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #8 on: February 28, 2014, 09:46:46 pm »
I don't need to believe, I have tested. The 10K specifically states that it is a sampling speed issue. This means, slow the sampling speed or add some external capacitance and it will take care of the S/H issue.

Anyhow, I'm sure you've built/shipped many products using the AVR family...

cheers,
george.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #9 on: February 28, 2014, 11:16:45 pm »
Quote
What concerns me is that when the P0 is high (3V3), ADIN pin is almost on battery potential.

Why would that concern you?

Quote
Also, some hundreds uA flows into the P0 pin.

So?
================================
https://dannyelectronics.wordpress.com/
 

Offline delmadordTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: sk
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #10 on: March 01, 2014, 12:03:38 am »
Quote
What concerns me is that when the P0 is high (3V3), ADIN pin is almost on battery potential.
Why would that concern you?

Isn't absolute maximum voltage on IO pin the VCC + 0.3V ?

Quote
Also, some hundreds uA flows into the P0 pin.
So?

There is a diode for ESD spike forward biased from pin to VCC. If there is a high enough voltage on the pin, the diode starts to conduct. I am not sure if even some uA are healthy.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13971
  • Country: gb
    • Mike's Electric Stuff
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #12 on: March 01, 2014, 01:50:40 am »
Quote
Isn't absolute maximum voltage on IO pin the VCC + 0.3V ?

Why the +0.3v? If you look at the pin structure, you will notice those clamping diodes.

Quote
I am not sure if even some uA are healthy.

The datasheet can help you answer that definitively.
================================
https://dannyelectronics.wordpress.com/
 

Online Andreas

  • Super Contributor
  • ***
  • Posts: 3298
  • Country: de
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #13 on: March 01, 2014, 06:06:15 am »
There is a diode for ESD spike forward biased from pin to VCC. If there is a high enough voltage on the pin, the diode starts to conduct. I am not sure if even some uA are healthy.

Hello,

AVR182 specifies a allowed clamping current up to 1mA (on some other MCUs are only 0.5mA are allowed).
But in some cases it is better not to rely on the internal clamping diodes.

- If you use a low power design with sleep mode using only some uA during sleep together with a voltage regulator which only delivers output current and cannot sink any current (like most regulators). In this case during sleep the supply voltage will go up to nearly the 9V through the clamping diodes.

- In one design I had a bus powered FTDI module with TTL-Levels connected via clamping resistors to a AVR with a LC-Display.
The problem was that after power cycling of the AVR circuit the AVR did not start up correctly because it got current over the FTDI module via clamping diodes. The display was "dark" in this case, except immediately after programming. (In this case there was a correct reset).

- Another design had ADC issues on a neighbour pin of a ADC-pin which was connected via 100k to a RS232 connector. Every time with a negative edge (-12V = -120uA) the input filtering capacitor of the ADC pin was discharged by several 10-100mV disturbing the next ADC conversion. A schottky clamping diode external to the RS232 pin helped in this case.

So you can use the internal clamping diodes as long as you do not violate the absolute maximum ratings. But you have to examine carefully the risks and side effects.

with best regards

Andreas



 

Offline delmadordTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: sk
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #14 on: March 01, 2014, 10:04:52 am »
http://electricstuff.co.uk/picavrstuff.html#Measuring%20battery%20voltage


Thanks Mike! Looks nice. In the text on your page, it says I can use a digital transistor (with integrated resistors too), so I can avoid the 0.7V Vce drop, right? What is the value of that Cap? 10n ?


EDIT:
When I try it in the simulator, it only works with BJT transistor, not with MOSFET. However, there seems to be no error caused by the transistor. Also, I have found that, the voltage on divider stays longer with greater capacitor value, and then gets to the ground. I have observed from simultor that with 10uF it is about 100ms, seems enough. It stops the current drainage through divider automatically, if the control pin on the MCU somehow "forgets"  to do it. I really like this solution!
« Last Edit: March 01, 2014, 10:20:19 am by delmadord »
 

Offline papo

  • Regular Contributor
  • *
  • Posts: 93
  • Country: ch
Re: Microcontroller running 3V3 sense 9V battery voltage with ADC
« Reply #15 on: March 02, 2014, 08:54:27 pm »
Hi

Thanks Mike! Looks nice. In the text on your page, it says I can use a digital transistor (with integrated resistors too), so I can avoid the 0.7V Vce drop, right? What is the value of that Cap? 10n ?

I think that the transistor with internal resistors is just a size thing. The Vce drop is much lower than 0.7 V, you probably confused it with Vbe? The cap has to be sufficiently large to charge the sampling cap inside the micro (this was discussed above). Other than that, I don't think that its value is too cricical.

This is really a neat trick!

Regards
Matt
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf