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

ADC configuration for the 2 channel for nrf52840.

Hello,

I am using the nrf52840 controller for the development ,i want to read the value from 2 channel of ADC . I just gone through the SDK example code of 

SAADC, here i don't understand , how to 2 channel sampling event triggered in callback.

As per my understanding when one channel preprocessed then the control comes into callback function and check the event status and increment event counter.

and SAMPLES_IN_BUFFER  macro is nothing but one channel samples in Pbuffer array right? likewise for second channel 2 times callback function called and so on.

that time event counter will be 2 and will have different values into pbuffer array right?

please let me correct here if am making wrong interpretation.

Thank You

Nilesh 

Parents
  • Hi Nilesh

    The callback is not triggered until you have filled the current ADC buffer, the size of which is set by the SAMPLES_IN_BUFFER define. 

    This means that by default the SAADC needs to be triggered 5 times before the callback is triggered. 

    When you enable multiple channels the SAADC will automatically sample each enabled channel each time it is triggered, which means if you have 2 channels enabled you will fill up the buffer twice as fast. 

    I recommend setting the SAMPLES_IN_BUFFER to an even number if you use 2 channels, otherwise the buffer will fill up after sampling just one of two channels. 

    If you set SAMPLES_IN_BUFFER to 10 it will take the same amount of time as when you have just one channel and set the buffer size to 5. 

    Best regards
    Torbjørn

Reply
  • Hi Nilesh

    The callback is not triggered until you have filled the current ADC buffer, the size of which is set by the SAMPLES_IN_BUFFER define. 

    This means that by default the SAADC needs to be triggered 5 times before the callback is triggered. 

    When you enable multiple channels the SAADC will automatically sample each enabled channel each time it is triggered, which means if you have 2 channels enabled you will fill up the buffer twice as fast. 

    I recommend setting the SAMPLES_IN_BUFFER to an even number if you use 2 channels, otherwise the buffer will fill up after sampling just one of two channels. 

    If you set SAMPLES_IN_BUFFER to 10 it will take the same amount of time as when you have just one channel and set the buffer size to 5. 

    Best regards
    Torbjørn

Children
  • please here correct my interpretation

    for 2 channel  - SAMPLES_IN_BUFFER    3

    for 1 channel - when ADC pbuffer filled --> Trigger

    in Callback () -> Increment counter  and base on sample size pbuffer will  

    pbuffer[0],pbuffer[1],pbuffer[2] --> so this contains samples of channel 1 only is it right?

    for 2 channel - when ADC pbuffer filled --> Trigger 2 time

    in Callback () -> Increment counter and base on sample size pbuffer will  

    pbuffer[0],pbuffer[1],pbuffer[2] --> so this contains samples of channel 2 only? 

    please verify this is right or wrong.

  • Hi Nilesh

    Setting SAMPLES_IN_BUFFER to 3 is not very practical when you have 2 channels enabled. 

    The first ADC trigger will sample channel 1 and 2 quickly, and store them in pbuffer[0] and pbuffer[1] respectively. 

    The second trigger will sample both channels again, store channel 1 in pbuffer[2], then since the buffer has reached the limit of 3 it will store channel 2 in the second configured buffer, and trigger the callback. 

    In the callback you can then process the 3 currently ready samples (two from channel 1 and one from channel 2), but you need to wait for the next ADC trigger to pick up the second channel 2 sample as well as the third sample of channel 1 and 2.

    If instead you set SAMPLES_IN_BUFFER to 4 you will get a callback for every second ADC trigger, and you can easily read the channel 1 and 2 data for the last two triggers like this:

    pbuffer[0] - channel 1 first trigger
    pbuffer[1] - channel 2 first trigger
    pbuffer[2] - channel 1 second trigger
    pbuffer[3] - channel 2 second trigger

    Best regards
    Torbjørn

Related