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

  • Hi,

    I think u didn't get my question, actually that 17th pin write is necessary for my application,   

    nrf_gpio_pin_write(17,1);

    nrf_delay_us(320); --------->within this delay time only have to read ADC pin then only will get sensor data 

    nrf_gpio_pin_write(17,0);

    First thing i have to write 17th pin as 1, then 320us delay(within this delay time have to read ADC pin) and finally 17th pin have to make 0, this has to be in loop for continuous monitor. 

    Regards

    Kashinath

  • Yes.

    But you still need to get familiar with how the ADC works. Setting the pin is not too difficult. You can see the pin_int_change example on how to change pins easily.

    I attached a project which reads the ADC pin on a buttonpress on Button1 on the DK. Note that you have to press the button 5 times to get the sample done event. This is because the SAADC buffer has 5 elements. If you reduce the size of this to 1, you should get the event on every buttonpress. You can see how you can call nrfx_saadc_sample(). The button handler also toggles a pin. If you change it to set the pin to high in the button handler, and low in the saadc callback, you are almost there.

    The example is made in Keil, SDK15.0.0. You should be able to run it in SES as well, but you might need to include the saadc files in your IDE (segger embedded studio).

    saadc_pin_int_change.zip

     

    What you need to do is to use a timer to get your delay. nrf_delay_us() is not recommended, as it keeps the CPU awake. Look into the app_timer library. You probably also need to store the value from the saadc callback function, if you want to use it at a later point in time. Just store it in a variable in your main.c file.

     

    Best regards,

    Edvin

Related