![]() |
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 |
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. |
Re: Quick Timer Question
Great, thanks alot! You also answered another question I had regarding the amount of time per tick (800 ns). Thanks!
|
Re: Quick Timer Question
Here's an example of using the library calls.
In User_Initialization() (user_routines.c) Code:
OpenTimer1(TIMER_INT_ON &Code:
if (PIR1bits.TMR1IF) /* TIMER 1 INTERRUPT */ |
| All times are GMT -5. The time now is 01:32. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi