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;
|
|
|
|
}
|