2014-02-02 16:48:18 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
*
|
|
|
|
* The source code is licensed under the LGPLv2 license,
|
|
|
|
* See the file LICENSE for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup chronos
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief eZ430-chronos battery readout (via ADC)
|
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2010-12-17 13:38:03 +01:00
|
|
|
#include <stdint.h>
|
2013-03-30 21:37:56 +01:00
|
|
|
#include <cc430f6137.h>
|
2013-12-19 12:21:34 +01:00
|
|
|
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "cc430-adc.h"
|
2010-12-17 13:38:03 +01:00
|
|
|
|
2013-07-29 16:41:43 +02:00
|
|
|
uint32_t battery_get_voltage(void)
|
|
|
|
{
|
2011-03-18 15:59:50 +01:00
|
|
|
uint32_t voltage;
|
2010-12-17 13:38:03 +01:00
|
|
|
voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11);
|
|
|
|
|
|
|
|
/* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V
|
|
|
|
* --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 */
|
2013-07-29 16:41:43 +02:00
|
|
|
voltage = (voltage * 2 * 2 * 1000) / 4095;
|
2010-12-17 13:38:03 +01:00
|
|
|
return voltage;
|
|
|
|
}
|