From b92871fcd7203e096551879cd51a850fa585529f Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 16 Apr 2011 17:01:55 +0200 Subject: Enable battery monitoring. --- board.h | 2 +- halconf.h | 2 +- main.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/board.h b/board.h index 9034d20..8265944 100644 --- a/board.h +++ b/board.h @@ -61,7 +61,7 @@ * PC11 - Push Pull output (USB DISC). * PC12 - Push Pull output (LED). */ -#define VAL_GPIOCCRL 0x44848888 /* PC7...PC0 */ +#define VAL_GPIOCCRL 0x44008888 /* PC7...PC0 */ #define VAL_GPIOCCRH 0x88833388 /* PC15...PC8 */ #define VAL_GPIOCODR 0xFFFFFFFF diff --git a/halconf.h b/halconf.h index 1b0e3dd..b4624aa 100644 --- a/halconf.h +++ b/halconf.h @@ -45,7 +45,7 @@ * @brief Enables the ADC subsystem. */ #if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) -#define HAL_USE_ADC FALSE +#define HAL_USE_ADC TRUE #endif /** diff --git a/main.cpp b/main.cpp index 57d3d17..f8c203f 100644 --- a/main.cpp +++ b/main.cpp @@ -199,6 +199,41 @@ static ICUConfig icucfg = { icuperiodcb }; +static const ADCConversionGroup adcgrpcfg = { + FALSE, + 2, + 0, + 0, + 0, + 0, + 0, + ADC_SQR1_NUM_CH(2), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN14) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN15) +}; + +class ADCThread : public BaseThread { + private: + adcsample_t adc_samples[2]; + + public: + noreturn_t thread_main() { + adcStart(&ADCD1, NULL); + + systime_t time = chTimeNow(); + while (TRUE) { + adcStartConversion(&ADCD1, &adcgrpcfg, adc_samples, 1); + sensordata[12] = adc_samples[0] * 1265 / 1000; + sensordata[13] = adc_samples[1] * 2201 / 1000; + + time += MS2ST(1000); + chThdSleepUntil(time); + } + } +}; + +ADCThread adc_thread; + int main(void) { halInit(); chSysInit(); @@ -212,6 +247,8 @@ int main(void) { i2c_thread.start(); + adc_thread.start(); + pwmStart(&PWMD2, &pwmcfg); palSetPadMode(GPIOA, 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL); palSetPadMode(GPIOA, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL); -- cgit v1.2.3