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

  • Hello, Thank you for your thoughtful answer. I will go ahead and do the GPIO test today.

    In My question, I forgot to indicate that I was using timeslot for multiprotocol with nrf_esb. Can that be the reason it would not work?

    Also, I have one question regarding your answer. With soft device working, I thought that HFCLK will always run because I do not have code anywhere that turns the HFCLK on. Is this not true and will the HFCLK only be turned on when a radio event is happening?

    Thank you, John Lee

Reply
  • Hello, Thank you for your thoughtful answer. I will go ahead and do the GPIO test today.

    In My question, I forgot to indicate that I was using timeslot for multiprotocol with nrf_esb. Can that be the reason it would not work?

    Also, I have one question regarding your answer. With soft device working, I thought that HFCLK will always run because I do not have code anywhere that turns the HFCLK on. Is this not true and will the HFCLK only be turned on when a radio event is happening?

    Thank you, John Lee

Children
No Data
Related