-2

I want to ask regarding my z1 motes (msp430 device) that was uploaded a program that tests the battery. It shows the values in the picture below. battery values

But I don't know what the values mean. Does this mean that the battery will be empty the closer the value 254x is to 0?

This the code used:

#include "contiki.h"
#include "dev/battery-sensor.h"
#include <stdio.h>

PROCESS(test_battery_process, "Battery Sensor Test");
AUTOSTART_PROCESSES(&test_battery_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_battery_process, ev, data)
{

  PROCESS_BEGIN();

  SENSORS_ACTIVATE(battery_sensor);

  while(1) {
    uint16_t bateria = battery_sensor.value(0);
    float mv = (bateria * 2.500 * 2) / 4096;
    printf("Battery: %i (%ld.%03d mV)\n", bateria, (long)mv,
       (unsigned)((mv - floor(mv)) * 1000));
  }

  SENSORS_DEACTIVATE(battery_sensor);

  PROCESS_END();
}   

Thanks.

2 Answers2

1

So you have 3.1V in the battery, right?

Check the datasheet of your Z1 mote. It does not really run from 0.2 or 0.1V. http://zolertia.sourceforge.net/wiki/images/e/e8/Z1_RevC_Datasheet.pdf, page 5 tells that you need 2.7V to power all parts, but you can go below if you don't use some parts.

So your battery lasts till 2.7V, not till 0V, since even though the battery has non-zero energy stored, it can not power your circuit any more.

The battery readout is just a number between 0..4095, which is related to the battery voltage, although you need to do some math to convert this to millivolts. In your code example, float mv=(long math) does this, and the value of mv tells the battery voltage in millivolts. One volt is 1000mV, so you have to have mv=2700 (2.7V) to power all modules of Z1 nicely.

It is a good idea to shut off below mv=2700, and none of the Z1 modules works below 1.8V, so mv=1800.

Note that the battery runtime is a different concern, you need to measure the total load profile, and take into account the non-linearity of the battery discharge which differs between different battery chemistries.

Gee Bee
  • 1,036
  • 6
  • 9
  • But the code shows that`battery_sensor.value(0);`is used to give the value of the battery sensor. Does it have anything to do at all with the battery or is it something totally unrelated? – Ahmed Al-haddad Mar 30 '16 at 17:02
  • Oh, now I got your question. It is related, but not scaled as volts. The battery_sensor.value(0) returns a raw number between 0..4095, read from an ADC which reads a fixed reference value. Then you need to do some math to get the actual battery voltage. float mv=(long math) does that, so the mv is the voltage in millivolts. I.e. if mv goes below 2700 then some of the boards will not work any more, if it goes below 1800 (1.8V) then nothing work any more. – Gee Bee Mar 30 '16 at 17:09
  • Oh awesome, exactly what I need. Could you tell me how you found about the 1800 and the 2700 (because I need to be sure of this in case I wanted to change the battery because of these values)? – Ahmed Al-haddad Mar 30 '16 at 17:16
  • It is in the datasheet of your Z1 module :) http://zolertia.sourceforge.net/wiki/images/e/e8/Z1_RevC_Datasheet.pdf page 5 :) – Gee Bee Mar 30 '16 at 17:23
  • @AhmedAl-haddad: You realize that 1800 is NOT 1.8V? GeeBee juts gave an example. He pointed out that you have to calculate the voltage value from the raw value if required. – Rev Mar 30 '16 at 18:05
  • battery_sensor.value(0): 1800 is NOT 1.8V, it is a raw value. float mv=xxxx, 1800 is 1.8V, that is the point of the calculation. – Gee Bee Mar 30 '16 at 18:39
0

All we see in your screengrab is noise.

Generally to make sense of battery voltages you need to record what happens throughout discharge tests. Based on the results of those tests you should then be able to estimate the remaining battery life in your application.

Peter Green
  • 21,158
  • 1
  • 38
  • 76
  • Why noise? The question was not the remaining lifetime of the battery, the screenshot shows nicely the adc readout, as well as the value converted to voltage. (It shall show V instead of mV but that's a typo, you can see it from the code.) – Gee Bee Mar 30 '16 at 17:25