Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unblocked saadc and buffer size

Does unblocked saadc sample the buffer size and stop or does it start re-sampling after the callback?  In other words, if the buffer is 100 entries in length, will it issue a callback every 100 samples, continuously.  The documentation isn't clear.

Parents
  • Hello,

    Are you using the nrfx_saadc_v2 driver, or the legacy nrfx_saadc driver?
    I do not see which device you are working with, so all my references will point to the nRF52832 SoC - but the same will apply to all the nRF52 series SoC's.
    In general, the SAADC will generate events and interrupts according to which interrupts you have enabled. Please note that it is not recommended that you change which interrupts that are enabled when working with the driver, since this may break the driver and/or lead to undefined behavior.
    For your specific question, for a buffer of size 100 there will be generated 100 EVENTS_RESULTDONE during sampling and a EVENTS_DONE when the entire buffer is filled, if enabled. In the case that you have supplied another buffer to the SAADC prior to this happening it will continue sampling at the same rate into the second buffer.
    If you are using the nrfx_saadc_v2 driver then you may see the list of available events and their explanation in the nrfx_saadc_v2 header file:

    /** @brief SAADC driver event types. */
    typedef enum
    {
        NRFX_SAADC_EVT_DONE,          ///< Event generated when the buffer is filled with samples.
        NRFX_SAADC_EVT_LIMIT,         ///< Event generated when one of the limits is reached.
        NRFX_SAADC_EVT_CALIBRATEDONE, ///< Event generated when the calibration is complete.
        NRFX_SAADC_EVT_BUF_REQ,       ///< Event generated when the next buffer for continuous conversion is requested.
        NRFX_SAADC_EVT_READY,         ///< Event generated when the first buffer is acquired by the peripheral and sampling can be started.
        NRFX_SAADC_EVT_FINISHED,      ///< Event generated when all supplied buffers are filled with results.
    } nrfx_saadc_evt_type_t;

    The documentation isn't clear.

    Specifically which part of the documentation do you think is unclear? If you specify then I may elaborate on the particular subject.

    Best regards,
    Karl

Reply
  • Hello,

    Are you using the nrfx_saadc_v2 driver, or the legacy nrfx_saadc driver?
    I do not see which device you are working with, so all my references will point to the nRF52832 SoC - but the same will apply to all the nRF52 series SoC's.
    In general, the SAADC will generate events and interrupts according to which interrupts you have enabled. Please note that it is not recommended that you change which interrupts that are enabled when working with the driver, since this may break the driver and/or lead to undefined behavior.
    For your specific question, for a buffer of size 100 there will be generated 100 EVENTS_RESULTDONE during sampling and a EVENTS_DONE when the entire buffer is filled, if enabled. In the case that you have supplied another buffer to the SAADC prior to this happening it will continue sampling at the same rate into the second buffer.
    If you are using the nrfx_saadc_v2 driver then you may see the list of available events and their explanation in the nrfx_saadc_v2 header file:

    /** @brief SAADC driver event types. */
    typedef enum
    {
        NRFX_SAADC_EVT_DONE,          ///< Event generated when the buffer is filled with samples.
        NRFX_SAADC_EVT_LIMIT,         ///< Event generated when one of the limits is reached.
        NRFX_SAADC_EVT_CALIBRATEDONE, ///< Event generated when the calibration is complete.
        NRFX_SAADC_EVT_BUF_REQ,       ///< Event generated when the next buffer for continuous conversion is requested.
        NRFX_SAADC_EVT_READY,         ///< Event generated when the first buffer is acquired by the peripheral and sampling can be started.
        NRFX_SAADC_EVT_FINISHED,      ///< Event generated when all supplied buffers are filled with results.
    } nrfx_saadc_evt_type_t;

    The documentation isn't clear.

    Specifically which part of the documentation do you think is unclear? If you specify then I may elaborate on the particular subject.

    Best regards,
    Karl

Children
  • I have a PCB with NRF52832-QFAA.  I am using the NRF52832-DK to program/debug.  I am compiling with Segger Embedded Studio 4.2 and have SDK 15.2 libraries.  From your description I am using the 'legacy' nrfx drivers (this is what came with the development environment).  Based on the examples from the kit, and the descriptions on the Nordic website I do the following:

    1) Initialize the saadc by calling nrf_drv_saadc_init()... which calls nrfx_saadc_init()

    2) Initialize saadc channel by calling nrf_drv_saadc_channel_init() ... which calls nrfx_saadc_channel_init()

    3) Start conversions using nrfx_saadc_buffer_convert( buffer, NUM_SAMPLES )

    4) Trigger sampling by calling nrfx_saadc_sample()

    THIS is where the question comes in.  Does the code get NUM_SAMPLES, execute the callback routine and end (one time thru) OR does it continue to sample into the existing buffer and execute the callback forever?

    It is not clear in the documentation if the feature executes once or continues indefinately

  • SentinelLighting said:
    I have a PCB with NRF52832-QFAA.  I am using the NRF52832-DK to program/debug.  I am compiling with Segger Embedded Studio 4.2 and have SDK 15.2 libraries.  From your description I am using the 'legacy' nrfx drivers (this is what came with the development environment).  Based on the examples from the kit, and the descriptions on the Nordic website I do the following:

    Thank you for elaborating. The nrfx_saadc driver is the latest SAADC peripheral driver supplied with the nRF5 SDK v15.2.0, correct.
    The nrf_drv is the legacy driver of the v15.2.0 SDK, and is there using the nrfx_saadc drive behind the scenes through forwarding macros, this is also correct.

    SentinelLighting said:

    THIS is where the question comes in.  Does the code get NUM_SAMPLES, execute the callback routine and end (one time thru) OR does it continue to sample into the existing buffer and execute the callback forever?

    It is not clear in the documentation if the feature executes once or continues indefinately

    With the steps described above the SAADC will be operating in one shot modeonly doing a single measurement per call to nrfx_saadc_sample (which in turns trigger the TASKS_SAMPLE task). If you wish to sample continuously you will need to trigger the SAMPLE task periodically, either through the internal timer, or through another event connected to the TASKS_SAMPLE using the PPI peripheral. You can see the latter demonstrated in the peripheral SAADC example from the SDK.
    An exempt from the continuous mode documentation reads:

    Continuous sampling can be achieved by using the internal timer in the ADC, or triggering the SAMPLE task from one of the general purpose timers through the PPI.

    Please do not hesitate to ask if any part of my answer should be unclear, or if you have any additional questions about this.

    Best regards,
    Karl

Related