nrf_drv_saadc_abort doesn't raise SAADC DONE task

I have an application where I am using the SAADC to take ADC samples. At any point during the measurements, I want to be able to stop the samples prior to the ADC buffer filling completely. I've created a mock project of the general issue shown where the app_timer callback successfully calls the SAADC abort, however I don't receive a DONE task as the function description declares it does.

This is using the BLE SoftDevice as my intention is to essentially start ADC sampling from a BLE command. I will also be having a BLE command to provide an early stop to the measurements as well as activity detection to stop ADC sampling during movement, then resume afterwards (hence a timer interrupt occurs to stop the sampling as an expected time the ADC sampling would have completed if no activity was detected).

/**
 * @brief Function for aborting the ongoing and buffered conversions.
 *
 * @note @ref NRFX_SAADC_EVT_DONE event will be generated if there is a conversion in progress.
 *       Event will contain number of words in the sample buffer.
 *
 * @warning This function must not be called from the context of event handler of the SAADC driver
 *          or from the context of interrupt with priority equal to or higher than priority
 *          of the SAADC interrupt.
 */
void nrfx_saadc_abort(void);

Based on the above @warning I have attempted to use the abort directly from main() as well as ensuring the app_timer interrupt is a lower priority without success.

I have attached a dummy project based on the BLE App Template where I added the SAADC example where I also added an App Timer to abort the measurements early.

Any thoughts on the SAADC abort is not raising the DONE task or what I'm doing wrong here?

0654.ble_app_template.zip

Parents
  • Hi,

    I'm guessing that your basing your assumption on this comment regarding the driver function:

    NRFX_SAADC_EVT_DONE is a HW event that isn't propagated to the application in this case. Calling nrfx_saadc_abort() will trigger the task NRF_SAADC_TASK_STOP which again will generate the NRF_SAADC_EVENT_STOPPED.
     
    regards
    Jared 
  • Thanks for the info!

    I need to be able to cause an early stop using while still knowing how many samples were taken during the period before nrfx_saadc_abort was called. For example, my sampling period fills a buffer of 512 ADC measurements. If the abort is called and only 300 measurements were taken, I need to know this number and be able to still convert the 300 measurements with nrfx_saadc_buffer_convert. Do you have a suggestion on how I would accomplish this if nrfx_saadc_abort does not propogate the HW event to the application?

  • Hi,

    When you call nrfx_saadc_abort() it will effectively call trigger the NRF_SAADC_TASK_STOP task which will eventually result in the EVENTS_STOPPED to be generated. When that event has been generated, you can check the RESULT.AMOUNT register to see how many samples that has been transferred to RAM.

     
    regards
    Jared
  • This is true that this works to get the last frame's number of samples. However, my 512 measurements are occurring from my SAADC being connected to a timer through the PPI to measure at a specific frequency. With this, each measurement is triggering a START then STOP event in the SAADC. Consequently, when I call nrf_saadc_amount_get() to read the RESULT.AMOUNT register, I am only receiving a value from the last measurement interval. For example, I have 3 SAADC channels, so whenever I read RESULT.AMOUNT, my value is either 3 or occasionally 6.

  • Hi,

    How are you aborting the sampling, how is it triggered, can you show me the code? I'm not 100% sure, but I would expect it to report the exact number of samples in that interval even though it didn't manage to sample all enabled channels,

    regards

    Jared 

Reply Children
Related