diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-06-22 14:29:43 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-22 14:29:43 -0700 |
| commit | 54b66d9484e36b7289e0df7714f45fad51d8252d (patch) | |
| tree | 997b7d829e7d34b4fa97b67349670baf0c46f7d9 | |
| parent | f1a497e29335ffaf59ad48d5c5a9327305f5fd49 (diff) | |
| parent | 1687c8b1e38aa646639455e141c28e724da4d269 (diff) | |
Merge pull request #3052 from dhalbert/samd51-voltage-check-delay
delay 1ms on SAMD51 when reading processor voltage
| -rw-r--r-- | ports/atmel-samd/common-hal/microcontroller/Processor.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 1e0b8fa79..2ca3ab30b 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -61,6 +61,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "py/mphal.h" #include "common-hal/microcontroller/Processor.h" #include "samd/adc.h" @@ -286,11 +287,15 @@ float common_hal_mcu_processor_get_voltage(void) { #ifdef SAMD51 hri_supc_set_VREF_SEL_bf(SUPC, SUPC_VREF_SEL_1V0_Val); - // ONDEMAND must be clear, and VREFOE must be set, or else the ADC conversion will not complete. - // See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference - hri_supc_clear_VREF_ONDEMAND_bit(SUPC); hri_supc_set_VREF_VREFOE_bit(SUPC); + adc_sync_set_reference(&adc, ADC_REFCTRL_REFSEL_INTREF_Val); + + // On some processor samples, the ADC will hang trying to read the voltage. A simple + // delay after setting the SUPC bits seems to fix things. This appears to be due to VREFOE + // startup time. There is no synchronization bit to check. + // See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference + mp_hal_delay_ms(1); #endif adc_sync_set_resolution(&adc, ADC_CTRLB_RESSEL_12BIT_Val); |
