Author Topic: Battery Voltage Monitoring  (Read 35051 times)

NixHydra

  • NewMember
  • *
  • Posts: 41
Re: Battery Voltage Monitoring
« Reply #15 on: March 18, 2014, 05:24:28 AM »
Just an observation concerning the "secret Arduino voltmeter" stuff. Works really well if wanting to see how rock-solid the Vcc supply is but really isn't that helpful as far as battery depletion is concerned. Please see attachment. Parameters being monitored on node 111 are , Vcc, battery voltage, LDR (di-urnal cycle), temp, humdity, wireless module temperature, wireless module power level setting and RSSI.

cheers,


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #16 on: March 18, 2014, 06:59:58 AM »
Right, it's a secret voltmeter of .. itself.

Spexx

  • NewMember
  • *
  • Posts: 30
  • Country: de
Re: Battery Voltage Monitoring
« Reply #17 on: March 18, 2014, 09:18:30 AM »
If I understand it correct, I could use for battery sensing the Aref pin if the supply voltage is not more than 5V. But on higher voltages, e.g. with a 9V battery, this won't work. I could use a voltage divider, but this would drain all the time a little bit power from the battery.

As described in the link in post #11, probably the best would be to use a P-FET, which can disable the voltage divider. Does anyone has tested this? I'm thinking about to implement this to the Moteino board. I have tried to find a P-FET at Digikey, but I'm not so familar with FETs and I don't know which one to choose. I think I need one with a logic level, which can be used with a 3.3V voltage?
Can anyone help me to find a suitable SMD P-FET at Digikey?

A

  • NewMember
  • *
  • Posts: 43
Re: Battery Voltage Monitoring
« Reply #18 on: March 18, 2014, 01:35:48 PM »
Can anyone help me to find a suitable SMD P-FET at Digikey?

I used a Diodes Incorporated DMG3415U-7 on my Weather Shield project for this purpose and while I haven't done extensive testing, simple on and off testing shows things are working as expected.

Another option to consider (and what I used a footprint/schematic symbol for on my board) is the BSS84.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #19 on: March 18, 2014, 11:12:42 PM »
Looking on digikey I see these have a rather high Rds: http://www.digikey.com/product-search/en/discrete-semiconductor-products/fets-arrays/1377094?k=bss84
Would you not want to reduce that to a minimum?
High density FETs with low Rds are more expensive though, so a little hard to justify that plus an extra DIO just to turn on/off a voltage monitor circuit.
In my opinion the simple multi mega ohm resistors+0.1uF cap solution works quite well and the leak current is very small compared to other stuff you might be doing.

NixHydra

  • NewMember
  • *
  • Posts: 41
Re: Battery Voltage Monitoring
« Reply #20 on: March 19, 2014, 07:32:45 AM »
Hi Spexx,

If you have a look at reply#13 of this thread, you should find a link which describes just the application you were referring to. This uses a cheap as chips, BSH203 PFET and a BC547 transistor, plus a couple of resistors. Draws probably nanoampere levels when switched off, as opposed to the 11 microamperes when the divider is switched on. May be it will be of some help to you?

Felix, maybe it's just me but I tried that JeeLab's 10Mohm, 4M7ohm, 0.1 uF cap trick and when I tried checking the divider voltage as a 10 digit integer value, I found too big an error for my comfort zone. Pity because I would really have liked to get that divider current down low. That's why I ended up using a 110kohm, 220kohm divider for my little Moteino Shield v1.1. Whether the 0.1uF cap was installed made no difference. As I said, maybe it's just me!

cheers,

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #21 on: March 19, 2014, 07:38:37 PM »
I would go with 1meg+470k, that seems to be quite stable and consistent values.

Spexx

  • NewMember
  • *
  • Posts: 30
  • Country: de
Re: Battery Voltage Monitoring
« Reply #22 on: March 20, 2014, 04:30:07 PM »
I have done some simple tests with the voltage divider and measured the current with a multimeter. With 1M + 470k I have an additionally power drain of 3µA in case of using a power supply with 5V (7µA in power down  without the voltage divider and 10µA with it)... So I would say nearly nothing :)

 In a short test the values were relative stable, so I think you are right, this would be the easiest way of measure the voltage. I have also tested it with 2x 10M and I don't see any big differences to the measured values. The current drain was in this case only ~0,5µA.

ColinR

  • Full Member
  • ***
  • Posts: 176
Re: Battery Voltage Monitoring
« Reply #23 on: August 26, 2014, 04:30:03 PM »
Very interesting topic.

For reference, a 9V battery with 1.47M will dissipate approximately 6uA. For a typical 9V battery (550mAh), this gives about 10.25yrs battery life. In other words, not a big deal.

Colin
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

oric_dan

  • Jr. Member
  • **
  • Posts: 64
Re: Battery Voltage Monitoring
« Reply #24 on: August 26, 2014, 04:52:50 PM »
One thing to keep in mind is that Atmel recommends using rather "low" value source resistances on the ADC channels. From section 24.6 of the mega328 d/s:

"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 (which, duh!) can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer (time) to the S/H capacitor".

The source resistance of your voltage dividers will be the 2 Rs in parallel.

However, I think you can still use large R-values as long as you are certain to tie an external cap, like 100nF, on the ADC pin. Then, this will easily transfer the necessary charge current into the S/H cap.
« Last Edit: August 26, 2014, 04:54:52 PM by oric_dan »

ColinR

  • Full Member
  • ***
  • Posts: 176
Re: Battery Voltage Monitoring
« Reply #25 on: August 26, 2014, 04:57:11 PM »
This is good information. A key phrase there is 'slowly varying'. The time constant is, in essence, infinite, as the thing sits at a relatively constant voltage forever as it discharges. It will reach steady-state, as far as we are concerned.

Colin
CuPID Controls :: Open Source browser-based sensor and device control
Interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

Charly86

  • Jr. Member
  • **
  • Posts: 74
  • Country: fr
Re: Battery Voltage Monitoring
« Reply #26 on: August 27, 2014, 04:39:20 AM »
You're right hi resitor not recommended by Atmel but as this is battery, level is very stable and you can add 100nF cap's on // of the bottom resitor to stabilize voltage without any problem, this is what I'm doing.

By the way, I found extremly more reliable and accurate results doing ADC conversion into Lownoise mode and doing 8 samples and average the value. This is also true for any ADC conversion (NTC, Luminosity, .. whatever) and I'm doing this for any ADC sensor reading

Here is sample and working code (using LowPower library for sleep mode)

Code: [Select]

volatile uint8_t  adc_irq_cnt;

/* ======================================================================
Function: Interrupt routine for ADC
Purpose : Fired when ADC interrupt occured (mainly end of conversion)
Input   :
Output  :
Comments: Used by readADCLowNoise
====================================================================== */
ISR(ADC_vect) 
{
  // Increment ADC sample count
  // will check after wake up
  adc_irq_cnt++;
}

/* ======================================================================
Function: readADCLowNoise
Purpose : Read Analog Value with reducing noise for more accuracy
Input   : true return the average value, false return only the sum
Output  : average value read
Comments: hard coded to read 8 samples each time
          ADMUX Channel must have been set before this call
====================================================================== */
uint16_t readADCLowNoise(bool average)
{
  uint8_t low, high;
  uint16_t sum = 0;
 
  // Start 1st Conversion, but ignore it, can be hazardous
  ADCSRA |= _BV(ADSC);
 
  // as we will enter into deep sleep mode, flush serial to avoid
  // data loss or corrupted
  Serial.flush();

  // wait for first dummy conversion
  while (bit_is_set(ADCSRA,ADSC));

  // Initialize ADC sample counter
  adc_irq_cnt = 0;

  // Want to have an interrupt when the conversion is done
  ADCSRA |= _BV( ADIE );
 
  // Loop thru samples
  do
  {
    // Enable Noise Reduction Sleep Mode
    set_sleep_mode( SLEEP_MODE_ADC );
    sleep_enable();

    // Wait until conversion is finished
    do
    {
      // The following line of code is only important on the second pass.  For the first pass it has no effect.
      // Ensure interrupts are enabled before sleeping
      sei();
      // Sleep (MUST be called immediately after sei)
      sleep_cpu();
      // Checking the conversion status has to be done with interrupts disabled to avoid a race condition
      // Disable interrupts so the while below is performed without interruption
      cli();
    }
    while (bit_is_set(ADCSRA,ADSC));

    // No more sleeping
    sleep_disable();
    // Enable interrupts
    sei();
   
    // read low first
    low  = ADCL;
    high = ADCH;
   
    // Sum the total
    sum += ((high << 8) | low);
   
  }
  // Hard coded to read 8 samples
  while (adc_irq_cnt<8);
 
  // No more interrupts needed for this
  ADCSRA &= ~ _BV( ADIE );
 
  // Return the average divided by 8 (8 samples) if asked
  return ( average ? sum >> 3 : sum );
 
}

/* ======================================================================
Function: readVcc
Purpose : Read and Calculate V powered, the Voltage on Arduino VCC pin
Input   : -
Output  : value readed in mV
Comments: ADC Channel input is modified
====================================================================== */
uint16_t readVcc()
{
  uint16_t value;
 
  // Read 1.1V reference against AVcc
  // REFS1 REFS0          --> 0 1, AVcc external ref. -Selects AVcc external reference
  // MUX3 MUX2 MUX1 MUX0  --> 1110 1.1V (VBG)         -Selects channel 14, bandgap voltage, to measure
  ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);

  // Take care, changing reference from VCC to 1.1V bandgap can take some time, this is due
  // to the fact that the capacitor on aref pin need to discharge or to charge
  delay(10); 

  // read value
  value = readADCLowNoise(true);
 
  // Vcc reference in millivolts
  // can be adjusted 1100L if 1V1 reference but has tolerance of 10% so you can measure it
  // and change it there, or better use it as parameter
  return ( (( 1023L * 1100L) / value) );
}

Full code and sketch available at https://github.com/hallard/RFM12B_arssi under example RFM12B_Struct_node_arssi

Antony

  • NewMember
  • *
  • Posts: 12
Re: Battery Voltage Monitoring
« Reply #27 on: August 27, 2014, 09:37:40 AM »
As a real-world use case, I've been using the voltage reader circuit described in Felix's mailbox mote for nearly three weeks. The same 9v battery also runs an anemometer AD amplifier circuit which has it's own variability of power consumption and complicates battery-life expectations. I calculated I'd get 5 weeks, but I just had to change the battery. From voltage logs, it appeared that once the battery dropped below 7.5v, power consumption increased non-linearly. I had not accounted for the non-linearity, and I guess that is where I lost at least some of the estimated time.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #28 on: August 27, 2014, 10:37:02 AM »
I have been using that circuit (1M+470K+0.1uF) for many different projects. But to put this to rest, the mailbox notifier can run at least 6 months on it from both a 9V and a Lipo.

oric_dan

  • Jr. Member
  • **
  • Posts: 64
Re: Battery Voltage Monitoring
« Reply #29 on: August 27, 2014, 01:05:57 PM »
The external R and internal S/H capacitor form a basic RC charging circuit, so if R is too large the cap will charge slowly, and will take a long time to "settle" at an accurate voltage reading. That's what the d/s is saying. This will be more of a problem when quickly switching between multiple ADC channels, as the S/H cap needs to be recharged  from the previous channel value, and settle at the new channel value.  This is also why 'unterminated' ADC channels will show a non-zero reading, as you're really measuring residual charge on the S/H cap from a previous reading.

Having the 100nF on the pin allows the S/H cap to quickly pull the necessary charge.