This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Clarification - TIMER[N] CAPTURE Event Time Delay on NRF52840

Hello,

Referencing the specification, the time it takes to complete the COMPARE task upon triggering is not directly outlined. 

I would like to have the following function in the code below. Will this return the expected value, or should I add a delay? Also, if there is a delay, how many clock cycles should this command take?

/**
 * Get the microsecond value on the main timer
 * 
 * @return microseconds since timer start (or since overflow)
 */
inline uint32_t get_microseconds()
{
  NRF_TIMER3->TASKS_CAPTURE[0] = 1;
  return NRF_TIMER3->CC[0];
}

I also have included the TIMER3 initialization code here.

/**
 * Set up the Main Timer for system-wide microsecond precision timing
 */
void init_main_timer()
{
  NRF_TIMER3->TASKS_STOP  = 1;  // just in case it's running
  NRF_TIMER3->TASKS_CLEAR = 1;

  NRF_TIMER3->BITMODE = TIMER_BITMODE_BITMODE_32Bit; // 32 bit
  NRF_TIMER3->MODE = TIMER_MODE_MODE_Timer;    // timer, not counter
  NRF_TIMER3->PRESCALER = 4UL; // freq = 16Mhz / 2^prescaler = 1Mhz - Microsecond precision

  NRF_TIMER3->TASKS_START = 1;
}

  • Hi Basile,

    After TASKS_CAPTURE is striggered the value of the timer is is captured in the CC register at most within 1 cycle of 32MHz peripheral clock that is within 31ns, Reading the value from NRF_TIMER3->CC[0] might break into couple of more CPU instructions which is still far below the 1us resolution you set to the timer. So you do not need any delays when you get the value from NRF_TIMER3->CC[0], it should be precise enough up to  one-third or a microsecond.

Related