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

What is the precision on timers?

We have built and run the code in examples->peripherals->timer in nRF5_SDK_12.3.0_d7731ad on 4 different Nordic DK nRF51 development boards. The timer period is 5 msec. We commented out the LED initialization and toggling. In the ISR, we toggle a GPIO pin and monitor the output on a logic analyzer. We find that the timer period varies from board to board, ranging from 4994 to 5025 msec. We replaced the nrf_drv_timer_xxx functions with direct programming of registers and get identical results. This is a problem because our nRF51 product needs a very accurate 5 msec "clock", and we don't want to have to hand calibrate the timer initialization with varying values for each board produced.

Can you confirm this problem and perhaps suggest a solution?

Parents
  • Hi Jeffery

    The accuracy of the timers is set by the clock source, which by default is the internal 16MHz RC oscillator. This oscillator has an accuracy of around +/- 5%, and as such your timer accuracy will be the same.

    To get better accuracy for your timers you should start the external 16MHz crystal, which will have an accuracy of 50 ppm or better (depending on the crystal used).

    The simplest way to start the external 16MHz crystal is to trigger the HFCLKSTART task, like this:

    NRF_CLOCK->TASKS_HFCLKSTART = 1;  
    

    Best regards
    Torbjørn

Reply
  • Hi Jeffery

    The accuracy of the timers is set by the clock source, which by default is the internal 16MHz RC oscillator. This oscillator has an accuracy of around +/- 5%, and as such your timer accuracy will be the same.

    To get better accuracy for your timers you should start the external 16MHz crystal, which will have an accuracy of 50 ppm or better (depending on the crystal used).

    The simplest way to start the external 16MHz crystal is to trigger the HFCLKSTART task, like this:

    NRF_CLOCK->TASKS_HFCLKSTART = 1;  
    

    Best regards
    Torbjørn

Children
No Data
Related