1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/boards/chronos/drivers/battery.c
Oleg Hahm 4bc6dfbf69 added license headers and doxygen file information
plus replaced tabs with spaces
2014-02-02 22:22:03 +01:00

38 lines
784 B
C

/*
* 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>
#include <stdint.h>
#include <cc430f6137.h>
#include "cc430-adc.h"
uint32_t battery_get_voltage(void)
{
uint32_t voltage;
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 */
voltage = (voltage * 2 * 2 * 1000) / 4095;
return voltage;
}