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

SAADC how run a code just before the sample is taken

Hi,

I need to activate one pin just before the sample is taken on a saadc channel. I have settings as in saadc example.

How can I do this? Is there any event that I can handle to do that? and where.

Thanks!

Parents
  • Hi,

    The SAADC example in the SDK is configured to trigger the sample task using PPI, on the compare event from a timer. If you want to set a pin before sampling, you have two options:

    1. Trigger the sample task manually from the timer handler interrupt.
    2. Set the pin using PPI and GPIOTE, on the same compare event from the timer, that triggers sampling. Note that this approach will set the pin at the same time as the sample task is triggered.

    Option 1 is quite simple to implement in the SAADC example project. These instructions are for main.c in SDK 14.2.0:

    Enable interrupt for timer compare event by setting the enable_int parameter to nrf_drv_timer_extended_compare() to true on line 104.

    Setup timer_handler to set pin and trigger sample task:

    void timer_handler(nrf_timer_event_t event_type, void * p_context)
    {
        // Set GPIO pin and add necessary delay before sampling can start
    
        nrf_drv_saadc_sample(); // Trigger SAADC sample task
    }
    

    Remove/comment out code configuring PPI to trigger SAADC sample task (line 57, 76, 90-91, 107-118, 122-127, and 191).

    Best regards,

    Jørgen

Reply
  • Hi,

    The SAADC example in the SDK is configured to trigger the sample task using PPI, on the compare event from a timer. If you want to set a pin before sampling, you have two options:

    1. Trigger the sample task manually from the timer handler interrupt.
    2. Set the pin using PPI and GPIOTE, on the same compare event from the timer, that triggers sampling. Note that this approach will set the pin at the same time as the sample task is triggered.

    Option 1 is quite simple to implement in the SAADC example project. These instructions are for main.c in SDK 14.2.0:

    Enable interrupt for timer compare event by setting the enable_int parameter to nrf_drv_timer_extended_compare() to true on line 104.

    Setup timer_handler to set pin and trigger sample task:

    void timer_handler(nrf_timer_event_t event_type, void * p_context)
    {
        // Set GPIO pin and add necessary delay before sampling can start
    
        nrf_drv_saadc_sample(); // Trigger SAADC sample task
    }
    

    Remove/comment out code configuring PPI to trigger SAADC sample task (line 57, 76, 90-91, 107-118, 122-127, and 191).

    Best regards,

    Jørgen

Children
Related