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
  • I'm not positive, but I think I remember seeing that the delay_us function is just a number of NOP's in a row. You could try adjusting this number. You would have to track down where the function is defined but you might throw it further off.

    That's dang close though, personally I would just leave it unless you need a more exact delay, in which case you could set up a timer.

Reply
  • I'm not positive, but I think I remember seeing that the delay_us function is just a number of NOP's in a row. You could try adjusting this number. You would have to track down where the function is defined but you might throw it further off.

    That's dang close though, personally I would just leave it unless you need a more exact delay, in which case you could set up a timer.

Children
Related