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

Read ADC based on particular delay

Hi all,

I am using SDK version 15, SES IDE.

I am working on Dust sensor, for that i am using SAAADC  example code, I want to read the ADC value from the pin, like this:

nrf_gpio_pin_write(17,1);

ADC_read_pin from channel1 within this delay(below)(which means i want to read ADC in a particular delay)

nrf_delay_us(320);

nrf_gpio_pin_write(17,0);

Can anyone suggest me, how to write this, by using SAADC example code.

Thanks in advance

Regards

Kashinath

Parents
  • Hello Kashinath,

    The SAADC example, which I assume you have seen, uses a timer to trigger the samples. 

     

    If you want to trigger a sample after 320µs, you can change the line in the saadc_sampling_event_init():

    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 400);

    to

    uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 320);

     

    Then it will do one sample every 320µs.

     

    Is the pin toggle needed in your application, or is it only to see that it is happening?

    The reason I ask is because there is not application interrupt when the example trigger a sample. It uses the PPI to link the task_sample() function call to the timeout event. If you want the timeout event, you must call nrf_drv_timer_extended_compare() with "true" as the last parameter.

     

    You will get the saadc_callback every time the sample call has been called (and finished) N times, where N is the size of your SAADC buffer (=SAMPLES_IN_BUFFER).

     

    Best regards,

    Edvin

Reply
  • Hello Kashinath,

    The SAADC example, which I assume you have seen, uses a timer to trigger the samples. 

     

    If you want to trigger a sample after 320µs, you can change the line in the saadc_sampling_event_init():

    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 400);

    to

    uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 320);

     

    Then it will do one sample every 320µs.

     

    Is the pin toggle needed in your application, or is it only to see that it is happening?

    The reason I ask is because there is not application interrupt when the example trigger a sample. It uses the PPI to link the task_sample() function call to the timeout event. If you want the timeout event, you must call nrf_drv_timer_extended_compare() with "true" as the last parameter.

     

    You will get the saadc_callback every time the sample call has been called (and finished) N times, where N is the size of your SAADC buffer (=SAMPLES_IN_BUFFER).

     

    Best regards,

    Edvin

Children
Related