View Single Post
  #19   Spotlight this post!  
Unread 12-03-2004, 10:00
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,868
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 question: TIMERS

Quote:
Originally Posted by Astronouth7303
I have had problems with interupts.c and timers. I use Timer 2 (and/or 1) to increment a variable and if that variable overflows, it increments another one. The problem is that I can't ever seem to get either to change. Help?
Sounds like the timers haven't been enabled in your initialization code.

Here's a sample initialization of Timer 4 to cause a 4ms interrupt.
Code:
OpenTimer4(TIMER_INT_ON &
	  T4_PS_1_16 &
	  T4_POST_1_10);
WriteTimer4(6); /* Preload timer to overflow after 4ms */
Here's the corrsponding user_routines_fast.c interrupt code.
Code:
unsigned long Clockms; // 1 millisecond clock
unsigned long Clockcs; // 100 millisecond
unsigned long Clocksec; // 1 second clock
 
static unsigned char t100ms=0;
static unsigned int t1sec=0;
 
...
 
else if (PIR3bits.TMR4IF) /* TIMER 4 INTERRUPT */
{
  /** This provides us with a clock for timing events **/
  PIR3bits.TMR4IF = 0; /* Clear Timer interrupt flag */
  WriteTimer4(6);	/* Reset Timer to overflow at 4ms */
  Clockms += 4; /* milliseconds */
  if (++t100ms >= 25)
  {
	t100ms = 0;
	Clockcs++; /* tenths of seconds */
	if (++t1sec >= 10)
	{
	  t1sec = 0;
	  Clocksec++; /* seconds */
	}
  }
}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 12-03-2004 at 10:13.