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

As to timer control of 52832

Hi,

I have a problem as to timer, please help to let me know the solution to solve it, thankful for your support in advance,

thanks.

Issue : when using the following codes, the waveform(GPIO Control) is blinking, it seems that the timer turn off and then turn on... why is happened?

void start_timer(void)
{		
	NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // Set the timer in Counter Mode
	NRF_TIMER2->TASKS_CLEAR = 1;               // clear the task first to be usable for later
	NRF_TIMER2->PRESCALER = 4;                             //Set prescaler. Higher number gives slower timer. Prescaler = 0 gives 16MHz timer
	NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;		 //Set counter to 16 bit resolution
	NRF_TIMER2->CC[0] = 5;//25000;                             //Set value for TIMER2 compare register 0
	//	NRF_TIMER2->CC[1] = 5;                                 //Set value for TIMER2 compare register 1
		
	// Enable interrupt on Timer 2, both for CC[0] and CC[1] compare match events
	NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);
	
	NVIC_EnableIRQ(TIMER2_IRQn);
		
	NRF_TIMER2->TASKS_START = 1;               // Start TIMER2
}
		
/** TIMTER2 peripheral interrupt handler. This interrupt handler is called whenever there it a TIMER2 interrupt
 */
void TIMER2_IRQHandler(void)
{
	if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0) && ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0))
	{
		NRF_TIMER2->EVENTS_COMPARE[0] = 0;           //Clear compare register 0 event	
		
		tcs_on_count++;
		
		if(tcs_on_count == 20)//667 133 
			tcs_on_count = 0;
		
		if(tcs_on_count == 1)//250 us
			NRF_P0->OUTSET = (1 << TCS_ON2);
		else if(tcs_on_count == 5)//5 ms
			NRF_P0->OUTCLR = (1 << TCS_ON2);
		else if(tcs_on_count == 6)//3 ms
			NRF_P0->OUTSET = (1 << TCS_ON1);
		else if(tcs_on_count == 16)
			NRF_P0->OUTCLR = (1 << TCS_ON1);
		
		NRF_TIMER2->CC[0] += 5;
	}
}
Related