use batmon in battery_sensor
This commit is contained in:
parent
ff227b7a04
commit
b6bea56c27
|
@ -12,7 +12,7 @@ CONTIKI_TARGET_SOURCEFILES += dht11.c
|
|||
#Needed for DS18S20 temperature sensor
|
||||
CONTIKI_TARGET_SOURCEFILES += ds1820.c
|
||||
#Needed for Battery test
|
||||
CONTIKI_TARGET_SOURCEFILES += battery-sensor.c
|
||||
CONTIKI_TARGET_SOURCEFILES += battery-sensor.c batmon.c
|
||||
#Needed for PIR
|
||||
CONTIKI_TARGET_SOURCEFILES += pir-sensor.c
|
||||
#Needed for OPTRIAC
|
||||
|
|
|
@ -17,10 +17,10 @@ int8_t batmon_get_voltage(uint16_t* voltage)
|
|||
uint16_t offset = 2550;
|
||||
int8_t ctr = 0;
|
||||
|
||||
BATMON = 0 | BV(BATMON_HR);
|
||||
BATMON = 0 | _BV(BATMON_HR);
|
||||
_delay_us(2);
|
||||
|
||||
if(BATMON & BV(BATMON_OK))
|
||||
if(BATMON & _BV(BATMON_OK))
|
||||
{
|
||||
// voltage above 2.550 V
|
||||
resolution = 75;
|
||||
|
@ -29,7 +29,7 @@ int8_t batmon_get_voltage(uint16_t* voltage)
|
|||
{
|
||||
BATMON = (BATMON & 0xF0) | (ctr);
|
||||
_delay_us(2);
|
||||
if(BATMON & BV(BATMON_OK)) break;
|
||||
if(BATMON & _BV(BATMON_OK)) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -38,13 +38,13 @@ int8_t batmon_get_voltage(uint16_t* voltage)
|
|||
resolution = 50;
|
||||
offset = 1700;
|
||||
|
||||
BATMON &= ~BV(BATMON_HR);
|
||||
BATMON &= ~_BV(BATMON_HR);
|
||||
|
||||
for(ctr=15; ctr>=0; ctr--)
|
||||
{
|
||||
BATMON = (BATMON & 0xF0) | (ctr);
|
||||
_delay_us(2);
|
||||
if(BATMON & BV(BATMON_OK)) break;
|
||||
if(BATMON & _BV(BATMON_OK)) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
*/
|
||||
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/batmon.h"
|
||||
|
||||
const struct sensors_sensor battery_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -52,20 +53,22 @@ const struct sensors_sensor battery_sensor;
|
|||
static int
|
||||
value(int type)
|
||||
{
|
||||
|
||||
uint16_t h;
|
||||
/*
|
||||
uint8_t p1;
|
||||
BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage
|
||||
|
||||
/* Bandgap can't be measured against supply voltage in this chip. */
|
||||
/* Use BATMON register instead */
|
||||
// Bandgap can't be measured against supply voltage in this chip.
|
||||
// Use BATMON register instead
|
||||
for ( p1=16; p1<31; p1++) {
|
||||
BATMON = p1;
|
||||
clock_delay_usec(100); // delay needed !!
|
||||
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
|
||||
|
||||
|
||||
*/
|
||||
batmon_get_voltage(&h);
|
||||
return h;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -73,6 +76,7 @@ static int
|
|||
configure(int type, int c)
|
||||
{
|
||||
// No configuration needed. readADC() handles all the config needed.
|
||||
batmon_init();
|
||||
return type == SENSORS_ACTIVE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -83,4 +87,4 @@ status(int type)
|
|||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
||||
|
|
Loading…
Reference in a new issue