Skip to content

Commit

Permalink
WIP Digital PM Support
Browse files Browse the repository at this point in the history
  • Loading branch information
davids5 authored and dagar committed Jun 26, 2019
1 parent 1cf4a2d commit 6fcc4cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/drivers/boards/common/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@
# define BOARD_BATT_I_LIST {ADC_BATTERY_CURRENT_CHANNEL}
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK_VALID}
#elif BOARD_NUMBER_BRICKS == 2
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL}
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL}
# define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID}
# if !defined(BOARD_NUMBER_DIGITAL_BRICKS)
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL}
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL}
# endif
#define BOARD_BRICK_VALID_LIST {BOARD_ADC_BRICK1_VALID, BOARD_ADC_BRICK2_VALID}
#elif BOARD_NUMBER_BRICKS == 3
# define BOARD_BATT_V_LIST {ADC_BATTERY1_VOLTAGE_CHANNEL, ADC_BATTERY2_VOLTAGE_CHANNEL, ADC_BATTERY3_VOLTAGE_CHANNEL}
# define BOARD_BATT_I_LIST {ADC_BATTERY1_CURRENT_CHANNEL, ADC_BATTERY2_CURRENT_CHANNEL, ADC_BATTERY3_CURRENT_CHANNEL}
Expand Down
4 changes: 3 additions & 1 deletion src/drivers/stm32/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,16 @@ ADC::update_system_power(hrt_abstime now)
#endif

/* The valid signals (HW dependent) are associated with each brick */

#if !defined(BOARD_NUMBER_DIGITAL_BRICKS)
bool valid_chan[BOARD_NUMBER_BRICKS] = BOARD_BRICK_VALID_LIST;
system_power.brick_valid = 0;

for (int b = 0; b < BOARD_NUMBER_BRICKS; b++) {
system_power.brick_valid |= valid_chan[b] ? 1 << b : 0;
}

#endif

system_power.servo_valid = BOARD_ADC_SERVO_VALID;

// OC pins are active low
Expand Down
12 changes: 9 additions & 3 deletions src/modules/sensors/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Sensors::adc_poll()
* Selection is done in HW ala a LTC4417 or similar, or may be hard coded
* Like in the FMUv4
*/

#if !defined(BOARD_NUMBER_DIGITAL_BRICKS)
/* The ADC channels that are associated with each brick, in power controller
* priority order highest to lowest, as defined by the board config.
*/
Expand All @@ -415,6 +415,8 @@ Sensors::adc_poll()
bat_voltage_v_chan[0] = _parameters.battery_adc_channel;
}

#endif

/* The valid signals (HW dependent) are associated with each brick */
bool valid_chan[BOARD_NUMBER_BRICKS] = BOARD_BRICK_VALID_LIST;

Expand Down Expand Up @@ -479,7 +481,7 @@ Sensors::adc_poll()
*/
selected_source = b;

#if BOARD_NUMBER_BRICKS > 1
# if BOARD_NUMBER_BRICKS > 1

/* Move the selected_source to instance 0 */
if (_battery_pub_intance0ndx != selected_source) {
Expand All @@ -490,9 +492,11 @@ Sensors::adc_poll()
_battery_pub_intance0ndx = selected_source;
}

#endif /* BOARD_NUMBER_BRICKS > 1 */
# endif /* BOARD_NUMBER_BRICKS > 1 */
}

# if !defined(BOARD_NUMBER_DIGITAL_BRICKS)

// todo:per brick scaling
/* look for specific channels and process the raw voltage to measurement data */
if (bat_voltage_v_chan[b] == buf_adc[i].am_channel) {
Expand All @@ -503,6 +507,8 @@ Sensors::adc_poll()
bat_current_a[b] = ((buf_adc[i].am_data * _parameters.battery_current_scaling)
- _parameters.battery_current_offset) * _parameters.battery_a_per_v;
}

# endif /* !defined(BOARD_NUMBER_DIGITAL_BRICKS) */
}

#endif /* BOARD_NUMBER_BRICKS > 0 */
Expand Down

0 comments on commit 6fcc4cc

Please sign in to comment.