From 6e05213fb81f9734912ddd5fde69b5d486772b44 Mon Sep 17 00:00:00 2001 From: alexklimaj Date: Mon, 21 Oct 2024 17:17:20 -0600 Subject: [PATCH] Add payload power ADC measurement --- boards/ark/fpv/init/rc.board_defaults | 2 ++ boards/ark/fpv/src/board_config.h | 21 ++++++++++++------- msg/SystemPower.msg | 2 ++ .../px4_platform_common/board_common.h | 7 +++++++ src/drivers/adc/board_adc/ADC.cpp | 14 +++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/boards/ark/fpv/init/rc.board_defaults b/boards/ark/fpv/init/rc.board_defaults index da8444bbc0c7..9998d562d1e3 100644 --- a/boards/ark/fpv/init/rc.board_defaults +++ b/boards/ark/fpv/init/rc.board_defaults @@ -24,3 +24,5 @@ if ver hwtypecmp ARKFPV000 then param set-default SENS_TEMP_ID 3014666 fi + +param set-default BAT1_V_DIV 21.0 diff --git a/boards/ark/fpv/src/board_config.h b/boards/ark/fpv/src/board_config.h index fceb1264e0be..cb37323c4770 100644 --- a/boards/ark/fpv/src/board_config.h +++ b/boards/ark/fpv/src/board_config.h @@ -156,17 +156,22 @@ #define ADC_BATTERY_VOLTAGE_CHANNEL /* PB0 */ ADC1_CH(9) #define ADC_BATTERY_CURRENT_CHANNEL /* PC2 */ ADC3_CH(0) #define ADC_SCALED_12V_CHANNEL /* PA4 */ ADC1_CH(18) -#define ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL /* PA0 */ ADC1_CH(16) +#define ADC_SCALED_VDD_3V3_SENSORS_CHANNEL /* PA0 */ ADC1_CH(16) #define ADC_SCALED_V5_CHANNEL /* PB1 */ ADC1_CH(5) #define ADC_HW_VER_SENSE_CHANNEL /* PH3 */ ADC3_CH(14) #define ADC_HW_REV_SENSE_CHANNEL /* PH4 */ ADC3_CH(15) #define ADC_CHANNELS \ - ((1 << ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL) | \ - (1 << ADC_SCALED_V5_CHANNEL)) | \ - (1 << ADC_SCALED_12V_CHANNEL) | \ - (1 << ADC_BATTERY_VOLTAGE_CHANNEL) | \ - (1 << ADC_BATTERY_CURRENT_CHANNEL) + ((1 << ADC_BATTERY_VOLTAGE_CHANNEL) | \ + (1 << ADC_BATTERY_CURRENT_CHANNEL) | \ + (1 << ADC_SCALED_VDD_3V3_SENSORS_CHANNEL) | \ + (1 << ADC_SCALED_V5_CHANNEL) | \ + (1 << ADC_SCALED_12V_CHANNEL)) + + +#define BOARD_BATTERY1_V_DIV (21.0f) // (20k + 1k) / 1k = 21 + +#define ADC_SCALED_PAYLOAD_SENSE ADC_SCALED_12V_CHANNEL /* HW has to large of R termination on ADC todo:change when HW value is chosen */ @@ -235,6 +240,8 @@ #define GPIO_VDD_3V3_SD_CARD_EN /* PC13 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN13) +#define BOARD_NUMBER_BRICKS 1 + /* Define True logic Power Control in arch agnostic form */ #define VDD_3V3_SD_CARD_EN(on_true) px4_arch_gpiowrite(GPIO_VDD_3V3_SD_CARD_EN, (on_true)) @@ -287,7 +294,7 @@ #define BOARD_ADC_SERVO_VALID (1) #define BOARD_ADC_BRICK_VALID (px4_arch_gpioread(GPIO_VDD_5V_PGOOD)) -#define BOARD_ADC_12V_RAIL_VALID (px4_arch_gpioread(GPIO_VDD_12V_PGOOD)) +#define BOARD_GPIO_PAYOLOAD_V_VALID (px4_arch_gpioread(GPIO_VDD_12V_PGOOD)) /* This board provides a DMA pool and APIs */ #define BOARD_DMA_ALLOC_POOL_SIZE 5120 diff --git a/msg/SystemPower.msg b/msg/SystemPower.msg index 21b35ba1dc43..05754dab0ee1 100644 --- a/msg/SystemPower.msg +++ b/msg/SystemPower.msg @@ -1,5 +1,6 @@ uint64 timestamp # time since system start (microseconds) float32 voltage5v_v # peripheral 5V rail voltage +float32 voltage_payload_v # payload rail voltage float32[4] sensors3v3 # Sensors 3V3 rail voltage uint8 sensors3v3_valid # Sensors 3V3 rail voltage was read (bitfield). uint8 usb_connected # USB is connected when 1 @@ -10,6 +11,7 @@ uint8 periph_5v_oc # peripheral overcurrent when 1 uint8 hipower_5v_oc # high power peripheral overcurrent when 1 uint8 comp_5v_valid # 5V to companion valid uint8 can1_gps1_5v_valid # 5V for CAN1/GPS1 valid +uint8 payload_v_valid # payload rail voltage is valid uint8 BRICK1_VALID_SHIFTS=0 uint8 BRICK1_VALID_MASK=1 diff --git a/platforms/common/include/px4_platform_common/board_common.h b/platforms/common/include/px4_platform_common/board_common.h index 4dff12c1b24f..763b09994ce8 100644 --- a/platforms/common/include/px4_platform_common/board_common.h +++ b/platforms/common/include/px4_platform_common/board_common.h @@ -106,6 +106,13 @@ #define ADC_V5_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb #endif +#if !defined(ADC_PAYLOAD_V_FULL_SCALE) +#define ADC_PAYLOAD_V_FULL_SCALE (25.3f) // Payload volt Rail full scale voltage +#endif +#if !defined(ADC_PAYLOAD_SCALE) +#define ADC_PAYLOAD_SCALE (7.667f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb +#endif + #if !defined(ADC_3V3_V_FULL_SCALE) #define ADC_3V3_V_FULL_SCALE (3.6f) // 3.3V volt Rail full scale voltage #endif diff --git a/src/drivers/adc/board_adc/ADC.cpp b/src/drivers/adc/board_adc/ADC.cpp index 906af6995945..146732402856 100644 --- a/src/drivers/adc/board_adc/ADC.cpp +++ b/src/drivers/adc/board_adc/ADC.cpp @@ -204,6 +204,9 @@ void ADC::update_system_power(hrt_abstime now) # if defined(ADC_SCALED_V5_SENSE) && defined(ADC_SCALED_V3V3_SENSORS_SENSE) cnt += ADC_SCALED_V3V3_SENSORS_COUNT; # endif +# if defined(ADC_SCALED_PAYLOAD_SENSE) + cnt++; +# endif for (unsigned i = 0; i < _channel_count; i++) { # if defined(ADC_SCALED_V5_SENSE) @@ -234,7 +237,15 @@ void ADC::update_system_power(hrt_abstime now) } # endif +# if defined(ADC_SCALED_PAYLOAD_SENSE) + if (_samples[i].am_channel == ADC_SCALED_PAYLOAD_SENSE) { + system_power.voltage_payload_v = _samples[i].am_data * ((ADC_PAYLOAD_V_FULL_SCALE / 3.3f) * (px4_arch_adc_reference_v() / + px4_arch_adc_dn_fullcount())); + cnt--; + } + +# endif if (cnt == 0) { break; } @@ -285,6 +296,9 @@ void ADC::update_system_power(hrt_abstime now) #ifdef BOARD_GPIO_VDD_5V_CAN1_GPS1_VALID system_power.can1_gps1_5v_valid = read_gpio_value(_5v_can1_gps1_valid_fd); #endif +#ifdef BOARD_GPIO_PAYOLOAD_V_VALID + system_power.payload_v_valid = BOARD_GPIO_PAYOLOAD_V_VALID; +#endif system_power.timestamp = hrt_absolute_time(); _to_system_power.publish(system_power);