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

Method of high precision timer count

OS in development environment :Windows7
HARD :(Taiyo Yuden)EBSHSN Series Evaluation Board : Central / Peripherals
CPU :(Nordic) nRF52832 / ARMR Cortex?-M4F 32 bit processor 28-pin Land Grid Array / 15GPIOs / SWD
Soft Ver:nRF5_SDK_15.2.0_9412b96

Timer counts were created in two ways: with or without the PPI feature.
Which program is more accurate?

1,Timer_ppi.zip  (Timer using PPI)
   1) In timer count mode, set timer 1 to generate an interrupt at 1 count. 
   2) Set timer 2 to 100 us in timer mode without interrupt. 
   3) Whenever timer2 reaches 100 μs, timer1 is counted. 

2.Timer_not_PPI.zip (Timer not using PPI) 
  1) In timer mode, set timer 1 to generate an interrupt at 100us.Timer_ppi.zipTimer_not_PPI.zip

Parents
  • Other than the above, is there any way to create a timer that counts correctly?
    This timer needs to be synchronized with another device.

  • Hi,

     

    Timer-wise, both should have the same accuracy.

    Both implementations use the CPU for incrementing a variable, where the PPI example uses two timers, one in counter mode, and one in capture/compare mode.

     

    To get an accurate timer, remember to start the external HFCLK (NRF_CLOCK->TASKS_HFCLKSTART = 1;), as the default behavior is to run on the internal 64 MHz RC oscillator.

     

    If you want to synchronize based on an external signal, I'd recommend that you look into the GPIOTE IN functionality, and use PPI to either count or provide an event on either rising or falling edge.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Timer-wise, both should have the same accuracy.

    Both implementations use the CPU for incrementing a variable, where the PPI example uses two timers, one in counter mode, and one in capture/compare mode.

     

    To get an accurate timer, remember to start the external HFCLK (NRF_CLOCK->TASKS_HFCLKSTART = 1;), as the default behavior is to run on the internal 64 MHz RC oscillator.

     

    If you want to synchronize based on an external signal, I'd recommend that you look into the GPIOTE IN functionality, and use PPI to either count or provide an event on either rising or falling edge.

     

    Kind regards,

    Håkon

Children
Related