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

  • Hi Edvin,

    Thank you for your suggestion.Here i am attaching the application code for Dust sensor, actually i have to do like this:dustSensor.ino

    Kindly suggest me for this, till then i will also try with your suggestion.

    Regards

    Kashinath   

  • Hello,

    I didn't know you were using Arduino. What kind of board do you have? Do you have a site where you find your projects? I am not sure whether you can use the regular SDK. That depends on what programming chip that is on the board (if any).

     

    Best regards,

    Edvin

  • Hi Edvin,

    I am not using any Arduino board, just i am referring this code, so i want to write code according to attached  file, so just keep it for reference, so suggest for the same.I have to write the same code for Nordic nrf52810, in SAADC example SDKv15

    Regards

    Kashinath

  • Things are a bit different when you use the SDK. I suggest that you take a look at the SAADC example in SDK15 (which you can find here).

     

    BR,

    Edvin

Reply Children
  • 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