Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduced battery driver
- Loading branch information
Showing
3 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdint.h> | ||
#include <cc430x613x.h> | ||
#include <cc430-adc.h> | ||
|
||
uint16_t battery_get_voltate(void) { | ||
uint16_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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef BATTERY_H | ||
#define BATTERY_H | ||
|
||
uint16_t battery_get_voltate(void); | ||
|
||
#endif /* BATTERY_H */ |