Thread: Using Timers
View Single Post
  #6   Spotlight this post!  
Unread 26-01-2006, 13:38
Eldarion's Avatar
Eldarion Eldarion is offline
Electrical Engineer / Computer Geek
AKA: Eldarion Telcontar
no team (Teamless Orphan)
Team Role: Alumni
 
Join Date: Nov 2005
Rookie Year: 2005
Location: Númenor
Posts: 558
Eldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond reputeEldarion has a reputation beyond repute
Send a message via AIM to Eldarion Send a message via Yahoo to Eldarion
Re: Using Timers

Quote:
Originally Posted by tribotec_ca88
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!!!
InterruptHandlerLow () is a system function; I.E. when an interrupt is set, this function is immediately called by IFI's interrupt handler. You do not need to call it from anywhere in your code.
__________________
CMUCam not working? Tracks sporadically? Try this instead: http://www.falconir.com!
PM me for more information if you are interested (it's open source!).

Want the FIRST Email blasts? See here: http://www.chiefdelphi.com/forums/sh...ad.php?t=50809

"The harder the conflict, the more glorious the triumph. What we obtain too cheaply, we esteem too lightly; it is dearness only that gives everything its value."
-- Thomas Paine

If it's falling apart it's a mechanical problem. If it's spewing smoke it's a electrical problem.
If it's rampaging around destroying things it's a programming problem.

"All technology is run on 'Magic Smoke' contained within the device. As everyone knows, whenever the magic smoke is released, the device ceases to function."
-- Anonymous

I currently speak: English, some German, Verilog, x86 and 8051 Assembler, C, C++, VB, VB.NET, ASP, PHP, HTML, UNIX and SQL