[Contiki-developers] battery voltage

298 views
Skip to first unread message

mohamed ben hassen

unread,
Apr 15, 2010, 6:36:40 AM4/15/10
to gffs f
hi all,
i use contiki-2.4 and i 'd like to use the battery volatage
please ifs there any one know how can i show the level of the battery in my program ?
thanks a lot.


Télécharger en toute sécurité sur Internet ? La solution avec Internet Explorer 8

Marek Bykowski

unread,
Apr 15, 2010, 6:43:42 AM4/15/10
to Contiki developer mailing list

Hi All,

I join you Ben Hassen for the question. I'll need it particularity for the use in routing metrics to make it more energy efficient.

Thanks,
Marek




------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Contiki-developers mailing list
Contiki-d...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/contiki-developers


Carlo Alberto Boano

unread,
Apr 15, 2010, 6:46:17 AM4/15/10
to Contiki developer mailing list
Hi Mohammed,
I used to do the following, and it seems to work, but there might exist cleaner code.


int get_voltage() {
 SENSORS_ACTIVATE(battery_sensor);
 // Retrieving the voltage reference from the REF2_5V bit (1.5V or 2.5V) - I already multiply per 2
 int vref = 3;
 if((REF2_5V & ADC12CTL0) != 0) vref = 5;
 // Polling the ADC to get the battery voltage. I get an average of many values to be on the safe side
 unsigned long bsens = 0;
 int cnt = 0;
 for(cnt=0;cnt<20;cnt++) bsens += battery_sensor.value(0);
 bsens = bsens / cnt;
 // Converting the raw value to the actual battery voltage (mV) -  Value = raw_value / 4095 * Vref * 2
 unsigned long bs = (bsens * vref * 1000)/ 4095;  
 SENSORS_DEACTIVATE(battery_sensor);
 return (int) bs;
}

Hope it helps.

Best Regards,
Carlo Alberto Boano






mohamed ben hassen ha scritto:

------------------------------------------------------------------------------ Download Intel&#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev

Marek Bykowski

unread,
Apr 15, 2010, 7:25:13 AM4/15/10
to Contiki developer mailing list
Actually is there a primitive to get the capacity value of the battery remained?

Marek

mohamed ben hassen

unread,
Apr 15, 2010, 7:39:51 AM4/15/10
to gffs f
hi,Carlo
thank u for your help i test the function with hello world but i get some errors
i think that some librairies miss .am i right? please if u can help me don't esitate
i get these errors:
  [java] d.c: In function `get_voltage':
     [java] d.c:56: `Value' undeclared (first use in this function)
     [java] d.c:56: (Each undeclared identifier is reported only once
     [java] d.c:56: for each function it appears in.)
     [java] d.c:56: `raw_value' undeclared (first use in this function)
     [java] d.c:56: `Vref' undeclared (first use in this function)
     [java] d.c:57: syntax error before "unsigned"
     [java] d.c:59: `bs' undeclared (first use in this function)
     [java] d.c: In function `process_thread_hello_world_process':
     [java] d.c:71: warning: implicit declaration of function `et_voltage'
     [java] make: *** [d.co] Erreur 1
     [java] Process returned error code 2
     [java]
thanks a lot,
Mohamed


Acheter en ligne en toute sécurité ? Internet Explorer 8 vous protège gratuitement !

Borms Joris

unread,
Apr 15, 2010, 7:45:21 AM4/15/10
to Contiki developer mailing list

Actually, there is.

 

“lib/sensors.h” and “dev/battery-sensor.h” define the API for the battery sensor. The implementation depends on the platform of course – you’ll find it in “platform/(platform name)/dev/battery-sensor.c” if it exists.

 

Basically,  you activate the battery sensor with battery_sensor.activate() and you can get its value with battery_sensor.value(0). You will probably need to rescale the result of that operation to a desired magnitude though.

 

Joris

Borms Joris

unread,
Apr 15, 2010, 7:53:38 AM4/15/10
to Contiki developer mailing list
Whoops, mixing old and new API, as you can see from Carlo's code, you activate the sensor with SENSORS_ACTIVATE(battery_sensor).

You may not need the averaging, but his code is pretty close to the simplest way to read battery voltage. You could also leave the "sensor" activated, instead of deactivating it at each get_voltage().


Van: Borms Joris [mailto:jbo...@etro.vub.ac.be]
Verzonden: Thursday, April 15, 2010 1:45 PM
Aan: Contiki developer mailing list
Onderwerp: Re: [Contiki-developers] battery voltage

Actually, there is.

"lib/sensors.h" and "dev/battery-sensor.h" define the API for the battery sensor. The implementation depends on the platform of course - you'll find it in "platform/(platform name)/dev/battery-sensor.c" if it exists.

Joris

Hope it helps.

________________________________________


Télécharger en toute sécurité sur Internet ? La solution avec Internet Explorer 8


________________________________________

Carlo Alberto Boano

unread,
Apr 15, 2010, 8:03:20 AM4/15/10
to joris...@vub.ac.be, Contiki developer mailing list
Hi,
I agree with you Joris.
The only thing with the deactivation is that the ADC configuration might
collide with the one needed for other purposes.
So I deactivated it to be on the safe side (I was retrieving the
temperature from the MSP, and this requires another configuration).

Best Regards,
Carlo Alberto Boano

Borms Joris ha scritto:

hamma hamma

unread,
Apr 15, 2010, 8:51:25 AM4/15/10
to contiki-d...@lists.sourceforge.net
hi all , sorry for this stupid question
i need to know the voltage of each node and i use the sky platform
i saw the code in the archive but i don't understand how can i get the value
i test the code of carlo but it seems that there is a lot of errors.
please can any one guide me step by step
 best regards,

Borms Joris

unread,
Apr 15, 2010, 9:24:49 AM4/15/10
to Contiki developer mailing list
The line "Value = raw_value / 4095 * Vref * 2" is a comment describing the rescaling of the raw value measured with the ADC to a more meaningful value. If you leave it in comment the code should compile fine. For more details, check the datasheet of the MSP430 microcontroller, specifically the section that describes the ADC12.

________________________________________


Acheter en ligne en toute sécurité ? Internet Explorer 8 vous protège gratuitement !

------------------------------------------------------------------------------

Carlo Alberto Boano

unread,
Apr 15, 2010, 9:36:39 AM4/15/10
to Contiki developer mailing list
Hi,
I forgot to mention that the function I pasted before takes many samples
from the ADC, performs an average, and converts the raw value to
millivolts.
So, it returns the mV as integer. It compiles fine for me, and it looks
like it work fine, I hope it does for you as well. Remember to add
#include "dev/battery-sensor.h".

Best Regards,
Carlo Alberto Boano

Borms Joris ha scritto:

hamma hamma

unread,
Apr 15, 2010, 9:44:06 AM4/15/10
to contiki-d...@lists.sourceforge.net
hi,Boms Joris

thank u a lot now i understand the  procedure. but i have a small question the voltage that i get {53 mv ,164mv }all the values under 1v
is that right because the battery initially ist about 1.5 or 2.5 v but the values that i get decrease  very quickly.normally i must get some value in volt ?
the value that i get is the current volatge of the battery?
best regards,
hamma

Renato Spiandorello

unread,
Apr 15, 2010, 3:00:08 PM4/15/10
to Contiki developer mailing list
Hi, please do you remeber any issue in Contiki 2.3 related to more than 1 icmp reply of empty ?
 
thank you in advance
 
greatings
 
rs
Reply all
Reply to author
Forward
0 new messages