add battery sensor
This commit is contained in:
parent
538bb6075c
commit
ff022fce05
|
@ -58,7 +58,7 @@
|
||||||
#define REST_RES_LEDS 0
|
#define REST_RES_LEDS 0
|
||||||
#define REST_RES_TOGGLE 0
|
#define REST_RES_TOGGLE 0
|
||||||
#define REST_RES_LIGHT 0
|
#define REST_RES_LIGHT 0
|
||||||
#define REST_RES_BATTERY 0
|
#define REST_RES_BATTERY 1
|
||||||
#define REST_RES_RADIO 0
|
#define REST_RES_RADIO 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
//#define PLATFORM_HAS_BUTTON 1
|
//#define PLATFORM_HAS_BUTTON 1
|
||||||
//#define PLATFORM_HAS_LIGHT 1
|
//#define PLATFORM_HAS_LIGHT 1
|
||||||
#define PLATFORM_HAS_TEMPERATURE 1
|
#define PLATFORM_HAS_TEMPERATURE 1
|
||||||
//#define PLATFORM_HAS_BATTERY 1
|
#define PLATFORM_HAS_BATTERY 1
|
||||||
//#define PLATFORM_HAS_SHT11 1
|
//#define PLATFORM_HAS_SHT11 1
|
||||||
|
|
||||||
#define SICSLOWPAN_CONF_FRAG 1
|
#define SICSLOWPAN_CONF_FRAG 1
|
||||||
|
|
|
@ -9,7 +9,8 @@ CONTIKI_TARGET_SOURCEFILES += temperature-sensor.c adc.c button-sensor.c sensors
|
||||||
CONTIKI_TARGET_SOURCEFILES += dht11.c
|
CONTIKI_TARGET_SOURCEFILES += dht11.c
|
||||||
#Needed for DS18S20 temperature sensor
|
#Needed for DS18S20 temperature sensor
|
||||||
CONTIKI_TARGET_SOURCEFILES += ds1820.c
|
CONTIKI_TARGET_SOURCEFILES += ds1820.c
|
||||||
|
#Needed for Battery test
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += battery-sensor.c
|
||||||
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
||||||
CONTIKIBOARD=.
|
CONTIKIBOARD=.
|
||||||
BOOTLOADER_START = 0x1F000
|
BOOTLOADER_START = 0x1F000
|
||||||
|
|
|
@ -31,30 +31,23 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* Battery sensor header file for Atmega128rfa1.
|
* Battery sensor file for Atmega128rfa1.
|
||||||
* \author
|
* \author
|
||||||
* Paulo Louro <paulolouro@binarylabs.dk>
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
* Harald Pichler <harald@the-develop.net>
|
* Harald Pichler <harald@the-develop.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dev/battery-sensor.h"
|
/**
|
||||||
#include "adc.h"
|
*The atmel rf23x radios have a low voltage detector that can be configured in units of 75 millivolts. Here is example *code for the ATmega128rfa1, where the BATMON register is in extended io space [dak664]
|
||||||
|
|
||||||
/* Connect Battery(+) to pin A1, via a 1000/470 voltage divider.
|
|
||||||
* This will case a battery voltage of 5.0V to read as the max analog
|
|
||||||
* voltage of 1.6V.
|
|
||||||
*
|
|
||||||
* Connect Battery(+) to pin A1, via a 1000/(470+470) voltage divider.
|
|
||||||
* This will case a battery voltage of 3.3V to read as the max analog
|
|
||||||
* voltage of 1.6V.
|
|
||||||
*/
|
*/
|
||||||
#define INPUT_CHANNEL 1
|
|
||||||
|
#include "dev/battery-sensor.h"
|
||||||
|
|
||||||
const struct sensors_sensor battery_sensor;
|
const struct sensors_sensor battery_sensor;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \return Voltage on battery measurement pin, 4096 is 5V.
|
* \return Voltage on battery measurement with BATMON register.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
|
@ -67,11 +60,12 @@ value(int type)
|
||||||
/* Use BATMON register instead */
|
/* Use BATMON register instead */
|
||||||
for ( p1=16; p1<31; p1++) {
|
for ( p1=16; p1<31; p1++) {
|
||||||
BATMON = p1;
|
BATMON = p1;
|
||||||
// delay_us(100); //delay needed?
|
clock_delay_usec(100); // delay needed !!
|
||||||
if ((BATMON&(1<<BATMON_OK))==0) break;
|
if ((BATMON&(1<<BATMON_OK))==0) break;
|
||||||
}
|
}
|
||||||
h=2550-75*16-75+75*p1; //-75 to take the floor of the 75 mv transition window
|
h=2550-75*16-75+75*p1; //-75 to take the floor of the 75 mv transition window
|
||||||
|
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue