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

having trouble capturing from timer2

I just want timer2 to run at 1Mhz so I can grab a microsecond counter as a timestamp. I don't care that it'll overflow after 32 bits. Put together what I thought should be a simple piece of code, but my captured value in CC[0] is always zero. 

Thoughts? 

void timer2_init(void)
{

nrf_drv_clock_lfclk_request(NULL);
nrf_drv_clock_hfclk_request(NULL);

while (false == nrf_drv_clock_hfclk_is_running());
while (false == nrf_drv_clock_lfclk_is_running());

NRF_TIMER2->MODE = 2; // counter
NRF_TIMER2->PRESCALER = 4;
NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
NRF_TIMER2->TASKS_CLEAR = 1;
NRF_TIMER2->TASKS_START = 1;

}

uint32_t get_microseconds(void)
{
NRF_TIMER2->TASKS_CAPTURE[0]=1;
return (NRF_TIMER2->CC[0]);
}

Parents Reply Children
Related