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

How to use the SAADC driver to sample faster than 1 milisecond

Hello,

I would like to be able to sample an analog voltage signal with a sample rate of approximately 250us (4096 samples/sec). I am using the SAADC example in nRF5 SDK v12.2.0, and the code is running fine. I am reading the ADC value using the PUTTY serial monitor, by connecting GPIO pin 2 to either GND or VCC. In the example code the following configuration is made to set up a 400ms sample rate (as I understand it):

/* setup m_timer for compare event every 400ms */
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 1000); // us_to_ticks also exists uint32_t nrf_drv_timer_us_to_ticks
nrf_drv_timer_extended_compare(&m_timer,
NRF_TIMER_CC_CHANNEL0,
ticks,
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
false);

But in the above code the sample rate can't be set lower than 1ms. I am now trying to use 'us_to_ticks' as shown below to be able to set the sample rate to 250us:

uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 250);

But when I do this all I get is an 'Overflow' in the PUTTY terminal window. As soon as I change the input parameter to 1000 us it works again. As far as I can see the Timer frequency is set to 16MHz (TIMER_DEFAULT_CONFIG_FREQUENCY 0), so it should be possible to get ADC sampling faster than 1ms I assume..?

Any help is greatly appreciated. Thanks.

Cheers,

Jan

  • Hi,

    The SAADC of nRF52832 support sample rates of up to 200 ksps, so this should work when you use nrf_drv_timer_us_to_ticks(). The reason why you get 'Overflow' in the terminal is that the UART interface is not able to transfer the logging fast enough when you sample that fast, and you will overflow the transmitt buffer. You should rather count the number of samples and print this on a regular (i.e. 4000 samples/1 second) , to check that the SAADC is sampling at the desired sample rate.

    Best regards,
    Jørgen