Go to Post If the pattern holds, it's a bizarro year. - GeeTwo [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2006, 10:50
et1337's Avatar
et1337 et1337 is offline
et1337
AKA: Evan Todd
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Columbus OH
Posts: 42
et1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of light
Quick Timer Question

So we set up a timer to trigger an interrupt every time it overflows. However, I could not get OpenTimer1(), ReadTimer1(), etc. to work, so we had to manually set up the timer.

My question is, how do I get the timer to overflow faster? Right now it overflows 3 or 4 times per loop.

Timer setup code:

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
TMR1L = 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
__________________
There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order.
et1337
  #2   Spotlight this post!  
Unread 02-02-2006, 11:04
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Quick Timer Question

You need to store a new value in TMR1H and TMR1L each time you service the interrupt. That value counts up every tick until it overflows and triggers the interrupt again. To make it happen faster, use a larger number to start with.

0x85ED is 34825 decimal, giving 31251 ticks until it overflows at 65536. At 800 ns per tick, that's 25 milliseconds. If you want to drop that to 5 milliseconds, you need 6250 ticks. Store 59286 in the timer, 0xE796.
  #3   Spotlight this post!  
Unread 02-02-2006, 14:26
et1337's Avatar
et1337 et1337 is offline
et1337
AKA: Evan Todd
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Columbus OH
Posts: 42
et1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of lightet1337 is a glorious beacon of light
Thumbs up Re: Quick Timer Question

Great, thanks alot! You also answered another question I had regarding the amount of time per tick (800 ns). Thanks!
__________________
There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order.
et1337
  #4   Spotlight this post!  
Unread 02-02-2006, 15:19
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
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,801
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accelerometer code ImmortalAres Programming 28 04-06-2005 01:02
a quick function question Kashi Chan Programming 3 06-03-2005 20:44
Accelerometer Timer Question psquared Programming 3 12-02-2005 01:34
A quick IR sensor question PBoss Programming 7 28-03-2004 21:02
A quick question Joelster Technical Discussion 6 10-02-2002 09:09


All times are GMT -5. The time now is 01:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi