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

nRF52 delay_us and delay_ms are not accurate

Hello,

I currently working with the nRF52832 chip on a custom board. The external clock is a 32MHz clock with +/- 10 ppm. When I use nrf_delay_us or nrf_delay_ms the delay is always not accurate. The following part of the code:

						nrf_gpio_pin_set(GPIO2_EXT);
						nrf_delay_ms(100);
						nrf_gpio_pin_clear(GPIO2_EXT);

Shows on the logic analyzer the following delays for different values:

nrf_delay_ms(100) ==> 96.81 ms delay nrf_delay_ms(40) ==> 38.73 ms delay nrf_delay_ms(10) ==> 9.682 ms delay

nrf_delay_us(100) ==> 95.1 us delay nrf_delay_us(40) ==> 38.2 us delay nrf_delay_us(10) ==> 9.975 us delay

Any idea whats causing this behavior or how to fix it ?

Parents
  • As @gacek16 pointed out this function is using cycle of NOP instructions so indeed it isn't accurate. I believe that documentation on infocenter and inside SDK indicate that this function should never be used for actual time measurement, only test purposes or inaccurate blocking busy loops. Use RTC por TIMER peripherals/libraries for everything else.

Reply
  • As @gacek16 pointed out this function is using cycle of NOP instructions so indeed it isn't accurate. I believe that documentation on infocenter and inside SDK indicate that this function should never be used for actual time measurement, only test purposes or inaccurate blocking busy loops. Use RTC por TIMER peripherals/libraries for everything else.

Children
Related