Thread: Using Timers
View Single Post
  #5   Spotlight this post!  
Unread 26-01-2006, 10:11
tribotec_ca88's Avatar
tribotec_ca88 tribotec_ca88 is offline
FIRST-a-holic
AKA: Camila Fitzgibbon
FRC #1382 (Tribotec Team)
Team Role: Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: São José dos Campos, Brazil
Posts: 194
tribotec_ca88 is just really nicetribotec_ca88 is just really nicetribotec_ca88 is just really nicetribotec_ca88 is just really nicetribotec_ca88 is just really nice
Send a message via ICQ to tribotec_ca88 Send a message via MSN to tribotec_ca88 Send a message via Yahoo to tribotec_ca88
Re: Using Timers

I'm not too familiar with working with interrupt-driven timers so here's a question for those of you more experienced programmers... I'm simply detailing the steps i took to set up a timer, so someone please correct me if i took a wrong turn.

OK I was thinking about using an interrupt-driven timer (Timer1 - as indicated in the PIC datasheet - to be more specific) used to keep track of time intervals during the Autonomous period.

The first thing I did was initialize it under User_Initialization (user_routines.c) with the following configurations:

T1CONbits.T1CKPS0 = 1; // 1:8 Prescale (clock=1.25MHz/each tick=800ns)
T1CONbits.T1CKPS1 = 1;


T1CONbits.TMR1CS = 0; // = 0 Timer uses internal clock
TMR1H = 0x85; // Sets most significant byte
TMRIL = 0xED; // Sets least significant byte
T1CONbits.TMR1ON = 1; // Turns on Timer1

IPR1bits.TMR1IP = 0; // Sets Timer1 as low priority
PIE1bits.TMR1IE = 1; // Enables Timer1 overflow interrupt
INTCONbits.GIEL = 1; // Enables low priority interruptions


Inside the InterruptHandlerLow () function i've got the following IF loop set up:

if (PIR1bits.TMR1IF) // In other words, has Timer1 overflowed?
{
PIR1bits.TMRI1F = 0; // Resets Timer1
timer1_flag = 1; // Variable used as a flag
}


All righty, the one thing i need to know is where exactly should i call the InterruptHandlerLow () function from? Inside the while (autonomous_mode) loop in user_routines_fast?? That way I was thinking of calling my team's customized autonomous function (known as Autonomous() in this case) from inside the while (autonomous_mode), transferring the value of timer1_flag through parameters, and using that value afterwards inside my Autonomous() function...
Example:

while (autonomous_mode) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata);

Autonomous((int)timer1_flag);
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata);
}
}

OK would this by any chance work at all, or have i totally lost it lol ? Any help at all would be greatly appreciated!!!
__________________
1382 Tribotec Team - Brazil
-----------------------------------------------
2005 NJ Regional GM Industrial Design Award
2005 NJ Regional Website Excellence Award
2004 NJ Regional Semifinalists
-----------------------------------------------