forked from Archive/PX4-Autopilot
adc: add support for multiple sensor voltage channels
This commit is contained in:
parent
e2337a34eb
commit
ade3871bee
|
@ -1,7 +1,7 @@
|
|||
uint64 timestamp # time since system start (microseconds)
|
||||
float32 voltage5v_v # peripheral 5V rail voltage
|
||||
float32 voltage3v3_v # Sensor 3V3 rail voltage
|
||||
uint8 v3v3_valid # Sensor 3V3 rail voltage was read.
|
||||
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
|
||||
uint8 brick_valid # brick bits power is good when bit 1
|
||||
uint8 usb_valid # USB is valid when 1
|
||||
|
|
|
@ -174,7 +174,19 @@
|
|||
/* Define the source for ADC_SCALED_V3V3_SENSORS_SENSE */
|
||||
|
||||
#if defined(ADC_SCALED_VDD_3V3_SENSORS_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE ADC_SCALED_VDD_3V3_SENSORS_CHANNEL
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 1
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS4_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS4_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 4
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL, \
|
||||
ADC_SCALED_VDD_3V3_SENSORS3_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 3
|
||||
#elif defined(ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL)
|
||||
# define ADC_SCALED_V3V3_SENSORS_SENSE { ADC_SCALED_VDD_3V3_SENSORS1_CHANNEL, ADC_SCALED_VDD_3V3_SENSORS2_CHANNEL }
|
||||
# define ADC_SCALED_V3V3_SENSORS_COUNT 2
|
||||
#endif
|
||||
|
||||
/* Define an overridable default of 0.0f V for batery v div
|
||||
|
|
|
@ -198,7 +198,7 @@ void ADC::update_system_power(hrt_abstime now)
|
|||
int cnt = 1;
|
||||
/* HW provides both ADC_SCALED_V5_SENSE and ADC_SCALED_V3V3_SENSORS_SENSE */
|
||||
# if defined(ADC_SCALED_V5_SENSE) && defined(ADC_SCALED_V3V3_SENSORS_SENSE)
|
||||
cnt++;
|
||||
cnt += ADC_SCALED_V3V3_SENSORS_COUNT;
|
||||
# endif
|
||||
|
||||
for (unsigned i = 0; i < _channel_count; i++) {
|
||||
|
@ -213,11 +213,17 @@ void ADC::update_system_power(hrt_abstime now)
|
|||
# endif
|
||||
# if defined(ADC_SCALED_V3V3_SENSORS_SENSE)
|
||||
{
|
||||
if (_samples[i].am_channel == ADC_SCALED_V3V3_SENSORS_SENSE) {
|
||||
// it is 2:1 scaled
|
||||
system_power.voltage3v3_v = _samples[i].am_data * (ADC_3V3_SCALE * (3.3f / px4_arch_adc_dn_fullcount()));
|
||||
system_power.v3v3_valid = 1;
|
||||
cnt--;
|
||||
const int sensors_channels[ADC_SCALED_V3V3_SENSORS_COUNT] = ADC_SCALED_V3V3_SENSORS_SENSE;
|
||||
static_assert(sizeof(system_power.sensors3v3) / sizeof(system_power.sensors3v3[0]) >= ADC_SCALED_V3V3_SENSORS_COUNT,
|
||||
"array too small");
|
||||
|
||||
for (int j = 0; j < ADC_SCALED_V3V3_SENSORS_COUNT; ++j) {
|
||||
if (_samples[i].am_channel == sensors_channels[j]) {
|
||||
// it is 2:1 scaled
|
||||
system_power.sensors3v3[j] = _samples[i].am_data * (ADC_3V3_SCALE * (3.3f / px4_arch_adc_dn_fullcount()));
|
||||
system_power.sensors3v3_valid |= 1 << j;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue