Skip to content

Commit

Permalink
Don't wait forever for battery ADC conversion to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Jan 8, 2024
1 parent 356a9ba commit 8df2477
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions software/firmware/src/peripherals/src/battery.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Header Inclusions ---------------------------------------------------------------------------------------------------

#include "battery.h"
#include "system.h"


// Static Global Variables ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -189,6 +190,7 @@ void battery_register_event_callback(battery_event_callback_t callback)
uint32_t battery_monitor_get_level_mV(void)
{
// Wake up the ADC
battery_voltage_code = 0;
conversion_complete = false;
if (am_hal_adc_power_control(adc_handle, AM_HAL_SYSCTRL_WAKE, true) != AM_HAL_STATUS_SUCCESS)
return 0;
Expand All @@ -208,8 +210,9 @@ uint32_t battery_monitor_get_level_mV(void)
}

// Wait until the conversion has completed
while (!conversion_complete)
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_NORMAL);
uint32_t retries_remaining = 25;
while (!conversion_complete && retries_remaining--)
system_delay(10);

// Disable the ADC
am_hal_adc_interrupt_disable(adc_handle, AM_HAL_ADC_INT_CNVCMP);
Expand Down

0 comments on commit 8df2477

Please sign in to comment.