AP_HAL_ChibiOS: fix ADC scaling on IOMCU

This commit is contained in:
TunaLobster 2021-09-28 11:40:08 -05:00 committed by Andrew Tridgell
parent 5aa3714e71
commit 11f98f7421
2 changed files with 16 additions and 3 deletions

View File

@ -36,7 +36,17 @@ extern AP_IOMCU iomcu;
#define ANLOGIN_DEBUGGING 0
// base voltage scaling for 12 bit 3.3V ADC
#define VOLTAGE_SCALING (3.3f/(1<<12))
#define VOLTAGE_SCALING (3.3f / ((1 << 12) - 1))
// voltage divider is usually 1/(10/(20+10))
#ifndef HAL_IOMCU_VSERVO_SCALAR
#define HAL_IOMCU_VSERVO_SCALAR 3
#endif
// voltage divider is usually not present
#ifndef HAL_IOMCU_VRSSI_SCALAR
#define HAL_IOMCU_VRSSI_SCALAR 1
#endif
#if ANLOGIN_DEBUGGING
# define Debug(fmt, args ...) do {printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, ## args); } while(0)
@ -462,8 +472,8 @@ void AnalogIn::_timer_tick(void)
#if HAL_WITH_IO_MCU
// now handle special inputs from IOMCU
_servorail_voltage = iomcu.get_vservo();
_rssi_voltage = iomcu.get_vrssi();
_servorail_voltage = iomcu.get_vservo_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VSERVO_SCALAR);
_rssi_voltage = iomcu.get_vrssi_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VRSSI_SCALAR);
#endif
for (uint8_t i=0; i<ADC_GRP1_NUM_CHANNELS; i++) {

View File

@ -204,6 +204,9 @@ PB0 RSSI_IN ADC1 SCALE(1)
PC0 VDD_5V_SENS ADC1 SCALE(2)
PC1 SCALED_V3V3 ADC1 SCALE(2)
# voltage divider 1/(16.9/(33+16.9))
define HAL_IOMCU_VSERVO_SCALAR 1 / (16.9 / (33 + 16.9))
# CAN bus
PI9 CAN1_RX CAN1
PH13 CAN1_TX CAN1