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

Capture timer value

Hi,

i want to start timer 2 and read its value just before the radio gets active. I've seen in the nr51 series reference manual i can use task capture to set the current count value in CC register and afterwards set the register value in a variable(counter in my code). Here is my code so far: initialise:

NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
	NRF_TIMER2->TASKS_CLEAR = 1;               
	NRF_TIMER2->PRESCALER = 14;
	NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
	NVIC_EnableIRQ(TIMER2_IRQn);
	NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled<<TIMER_INTENSET_COMPARE0_Pos;
	sd_softdevice_forward_to_application();

	NRF_TIMER2->TASKS_START = 1;

main for loop:

for (;;)
    {
    	if (m_do_update)
    	        {
    		    NRF_TIMER2->TASKS_CAPTURE[0];
    		    counter = NRF_TIMER2->CC[0];
    		    nrf_gpio_pin_write(LED_6, 1);
    	            advertising_init();
    	            m_do_update = false;
    	            nrf_gpio_pin_clear(LED_6);
    	        }
    }

When debugging, i do not see the counter variable incrementing. My ble application stops working (led_6 is nog toggling anymore). When removing the timer tasks the ble application works again.

Is this way of reading back the current CC[0] wrong? I could not find any example of this in the SDK.

Related