Thursday, September 29, 2011

PIC32 Timer1 example code

The following code snippet opens and uses Timer1 as an interrupt. In your initialization sequence:
//Open Timer1 with 1:8 prescaler (80MHz -> 10MHz), with period of 10, therefore tick = 1MHz.
OpenTimer1(T1_ON | T1_PS_1_8 | T1_SOURCE_INT, 10);
ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);
INTEnableSystemMultiVectoredInt();
And the interrupt handler:
void __ISR(_TIMER_1_VECTOR, ipl2) _Timer1Handler(void) {
	mT1ClearIntFlag();
	//Your code
}

2 comments: