View Single Post
  #4   Spotlight this post!  
Unread 02-02-2006, 15:19
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,825
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Quick Timer Question

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 */
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 02-02-2006 at 15:22.