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

NRF52 real sampling rate different

Hello, I was wondering why I am not getting a theoretical sampling rate as I set them to with a timer.

I am using PPI to trigger a SAADC sampling with the timer to set to 8ms. However, I am not getting a sampling rate with 125Hz. My Connection intervals for BT are Min = 20 and Max=30. Also, I am using 2 buffers to ensure that sampling happens even if other higher priority events than saadc_callback

   uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 8);
    nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
    nrf_drv_timer_enable(&m_timer);

    uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0);
    uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get();

    /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr);
    APP_ERROR_CHECK(err_code);

I am wondering if there are any solutions for the inconsistency of the sampling rate or a way I can calculate the inconsistency and optimize for it. My project highly depends on constant sampling rate and having no blind spots for sampling.

Thank you, John

Parents
  • Hi,

    Since you are using 8ms sample intervals the HFCLK based TIMER is not recommended as it adds a lot of current consumption. Instead you can use the LFCLK.

    The sample rate is relatively slow, so you should not need to be worried about being interrupted by SoftDevice activity. To ensure that you do not collide with the SoftDevice you can read the buffers from a lower priority interrupt when the application has time.

    Instead of using the SAADC directly have you tried to set a GPIO using the task and measuring the frequency, if so, what did you get?

    Best regards,

    Øyvind

  • Sorry for the late update! I did some testing and as you said the ppi and ssadc timings were very accurate. However, it turned out that I was losing data while they were being sent to the phone via BLE. With the connection interval at 10ms and sending 16 bytes per packet, I was able to only receive 80% of the total packet I send. This was regardless of the sampling rate(I tried 125Hz 500Hz 1000Hz). I did some research online and some say that BLE is not a reliable protocol and is expected to lose some packets on air. Is this true about BLE? I expect the packet loss rate to be much lower. If the data loss rate is true is there other ways I can reduce the packet loss?

Reply
  • Sorry for the late update! I did some testing and as you said the ppi and ssadc timings were very accurate. However, it turned out that I was losing data while they were being sent to the phone via BLE. With the connection interval at 10ms and sending 16 bytes per packet, I was able to only receive 80% of the total packet I send. This was regardless of the sampling rate(I tried 125Hz 500Hz 1000Hz). I did some research online and some say that BLE is not a reliable protocol and is expected to lose some packets on air. Is this true about BLE? I expect the packet loss rate to be much lower. If the data loss rate is true is there other ways I can reduce the packet loss?

Children
No Data
Related