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;
}