Here's an example of using the library calls.
In User_Initialization() (user_routines.c)
Code:
OpenTimer1(TIMER_INT_ON &
T3_16BIT_RW &
T3_SOURCE_INT &
T3_PS_1_8);
// #ticks = elapsed_time(sec) * 10**7 / prescale
// #ticks = .004sec * 10**7 / 8 #ticks = 5000
// Maximum for 16-bit 65535 - 5000 (4ms) = 60535
WriteTimer1(60535); /* Preload timer to overflow after 4ms */
In InterruptHandlerLow () (user_routines_fast.c)
Code:
if (PIR1bits.TMR1IF) /* TIMER 1 INTERRUPT */
{
PIR1bits.TMR1IF = 0; // clear the interrupt flag
WriteTimer1(60535); /* Reset Timer to overflow in 4ms */
}