Timers are simple to use, no soldering required.
IFI has a white paper on coding timers that goes into the bits and bytes of it all:
http://www.ifirobotics.com/docs/time...004-jan-14.pdf
For a description of the timer library calls see the MPLAB-C18-Libraries.pdf manual under C:\mcc18\doc.
Here's a sample using the timer libraries:
Code:
// In user_routines.c
#include <timers.h>
#define CLOCKOFFSET 60535 //Set timer for 4ms
// Maximum for 16-bit timer 65535 - 5000 (4ms) = 60535
/* Use Timer3 (16-bits) to control our clock */
/* timer set to 4 ms */
// Call from User_Initialization()
OpenTimer3(TIMER_INT_ON &
T3_16BIT_RW &
T3_SOURCE_INT &
T3_PS_1_8
);
WriteTimer3(CLOCKOFFSET); /* Preload timer to overflow after 4ms */
Code:
// In user_routines_fast.c
#include <timers.h>
// globals declared as extern wherever else they are used
volatile unsigned long Clockms=0; // 1 millisecond clock
volatile unsigned int Clockds=0; // 1/10 second
volatile unsigned int Clocksec=0; // 1 second clock
//etc.
// In InterruptHandlerLow()
if (PIR2bits.TMR3IF) /* TIMER 3 INTERRUPT */
{
/** This provides us with a clock for timing events **/
PIR2bits.TMR3IF = 0; /* Clear Timer interrupt flag */
WriteTimer3(CLOCKOFFSET); /* Reset Timer to overflow in 4ms */
Clockms += 4; /* milliseconds */
Clockds = Clockms / 100;
Clocksec = Clockms / 1000;
// etc.
}