This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Possibility of indefinite wait for SAADC Start event

Hello Nordic Community,

In order to measure battery voltage, I am using ADC with the code implemented as below: 

 // Configure SAADC:
 NRF_SAADC->RESULT.PTR = (uint32_t)&adc_output; 
 NRF_SAADC->RESULT.MAXCNT = 1;        
 NRF_SAADC->RESOLUTION = (SAADC_RESOLUTION_VAL_10bit << SAADC_RESOLUTION_VAL_Pos);
 NRF_SAADC->OVERSAMPLE = (SAADC_OVERSAMPLE_OVERSAMPLE_Bypass << SAADC_OVERSAMPLE_OVERSAMPLE_Pos);
 NRF_SAADC->CH[0].CONFIG =
    (SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) |
    (SAADC_CH_CONFIG_TACQ_10us << SAADC_CH_CONFIG_TACQ_Pos) |
    (SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
    (SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) |
    (SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos) |
    (SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos);
 NRF_SAADC->CH[0].PSELN = (SAADC_CH_PSELN_PSELN_NC << SAADC_CH_PSELN_PSELN_Pos);
 NRF_SAADC->CH[0].PSELP = (SAADC_CH_PSELP_PSELP_VDD << SAADC_CH_PSELP_PSELP_Pos); // (VDD==Battery Voltage)
 // Enable SAADC
 NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos);

 // Start SAADC
 NRF_SAADC->EVENTS_STARTED = 0;
 NRF_SAADC->TASKS_START = 1;
 while (!NRF_SAADC->EVENTS_STARTED)
 {
    // Wait for SAADC start
 }
 NRF_SAADC->EVENTS_END = 0;
 NRF_SAADC->TASKS_SAMPLE = 1;
 while (!NRF_SAADC->EVENTS_END)
 {
    // Wait for conversion to be done
 }
    // Disable SAADC:
 NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos);
 NRF_SAADC->TASKS_STOP = 1;

In this, there is a while loop used to wait for ADC to start and conversion to end. I would like to understand if there is a possibility of indefinite wait for ADC to start or end of conversion? If yes, what are the possible scenarios it can occur so that I can decide to have a timeout for these while loops.

Thanks & Regards.

Parents
  • Hi,

    With the posted code/configuration, I cannot see any was that the waits should not exit.

    A STARTED event should always follow the triggering of START task, and the END event should follow the SAMPLE task. The only exceptions I can think of is the following:

    • The the STOP task is triggered from an interrupt context, before the corresponding STARTED/END event is generated.
    • If you configure the MAXCNT register to a number larger than the number of enabled channels, you must trigger the SAMPLE task multiple times before the END event is generated.
    • If OVERSAMPLE is enabled, without BURST mode, you need to trigger the SAMPLE task 2^OVERSAMPLE times before the END event is generated.

    Best regards,
    Jørgen

Reply
  • Hi,

    With the posted code/configuration, I cannot see any was that the waits should not exit.

    A STARTED event should always follow the triggering of START task, and the END event should follow the SAMPLE task. The only exceptions I can think of is the following:

    • The the STOP task is triggered from an interrupt context, before the corresponding STARTED/END event is generated.
    • If you configure the MAXCNT register to a number larger than the number of enabled channels, you must trigger the SAMPLE task multiple times before the END event is generated.
    • If OVERSAMPLE is enabled, without BURST mode, you need to trigger the SAMPLE task 2^OVERSAMPLE times before the END event is generated.

    Best regards,
    Jørgen

Children
No Data
Related