From 26b1e1fe0cdd3d23b82a768bbd65f9efeb08cae4 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 13 Jan 2017 13:55:59 -1000 Subject: [PATCH] Use HW independant overrideable defines to condition ADC V5 sensing & publishing Use ADC_SCALED_V5_SENSE as apposed to legasy ADC_5V_RAIL_SENSE to populate voltage5V_v Then Scale the DN based on an overridable ADC_V5_V_FULL_SCALE value --- src/drivers/stm32/adc/adc.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/drivers/stm32/adc/adc.cpp b/src/drivers/stm32/adc/adc.cpp index cd2213f450..541abce421 100644 --- a/src/drivers/stm32/adc/adc.cpp +++ b/src/drivers/stm32/adc/adc.cpp @@ -68,6 +68,7 @@ #include #if defined(ADC_CHANNELS) + /* * Register accessors. * For now, no reason not to just use ADC1. @@ -347,16 +348,19 @@ ADC::update_system_power(hrt_abstime now) system_power.voltage5V_v = 0; -#if defined(ADC_5V_RAIL_SENSE) + /* HW provides ADC_SCALED_V5_SENSE */ + +# if defined(ADC_SCALED_V5_SENSE) for (unsigned i = 0; i < _channel_count; i++) { - if (_samples[i].am_channel == ADC_5V_RAIL_SENSE) { + if (_samples[i].am_channel == ADC_SCALED_V5_SENSE) { // it is 2:1 scaled - system_power.voltage5V_v = _samples[i].am_data * (6.6f / 4096); + system_power.voltage5V_v = _samples[i].am_data * (ADC_V5_V_FULL_SCALE / 4096); + break; } } -#endif +# endif /* Note once the board_config.h provides BOARD_ADC_USB_CONNECTED, * It must provide the true logic GPIO BOARD_ADC_xxxx macros.