Skip to content

Commit

Permalink
board config: add define for adc voltage scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng committed Nov 21, 2019
1 parent b7a7ba8 commit 1371887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions platforms/common/include/px4_platform_common/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@
#define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
#endif

#ifndef BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN
#define BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN (3.3f) // Reference voltage for reading out the current channel
#endif

#ifndef BOARD_ADC_POS_REF_V_FOR_VOLTAGE_CHAN
#define BOARD_ADC_POS_REF_V_FOR_VOLTAGE_CHAN (3.3f) // Reference voltage for reading out the voltage channel
#endif

/* Provide define for Bricks and Battery */

/* Define the default maximum voltage resulting from the bias on ADC termination */
Expand Down
5 changes: 3 additions & 2 deletions src/modules/battery_status/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "parameters.h"

#include <px4_platform_common/log.h>
#include <px4_platform_common/px4_config.h>
#include <drivers/drv_adc.h>

namespace battery_status
Expand Down Expand Up @@ -68,7 +69,7 @@ int update_parameters(const ParameterHandles &parameter_handles, Parameters &par

} else if (parameters.battery_voltage_scaling < 0.0f) {
/* apply scaling according to defaults if set to default */
parameters.battery_voltage_scaling = (3.3f / px4_arch_adc_dn_fullcount());
parameters.battery_voltage_scaling = (BOARD_ADC_POS_REF_V_FOR_VOLTAGE_CHAN / px4_arch_adc_dn_fullcount());
param_set_no_notification(parameter_handles.battery_voltage_scaling, &parameters.battery_voltage_scaling);
}

Expand All @@ -78,7 +79,7 @@ int update_parameters(const ParameterHandles &parameter_handles, Parameters &par

} else if (parameters.battery_current_scaling < 0.0f) {
/* apply scaling according to defaults if set to default */
parameters.battery_current_scaling = (3.3f / px4_arch_adc_dn_fullcount());
parameters.battery_current_scaling = (BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN / px4_arch_adc_dn_fullcount());
param_set_no_notification(parameter_handles.battery_current_scaling, &parameters.battery_current_scaling);
}

Expand Down

0 comments on commit 1371887

Please sign in to comment.