View previous topic :: View next topic |
Author |
Message |
rileyesi
Joined: 19 Dec 2006 Posts: 398
|
Posted: Wed Jan 16, 2008 7:26 pm Post subject: TIMER1 Questions |
|
|
Hi,
First time using TIMER1, so sorry for the basic questions.
Using Ian's WONDERFUL timer routine, I got the following:
Code: |
const Timer1Reload = 3906
config timer1=timer,prescale = 1024
load timer1 , Timer1Reload
on ovf1 Timer1_isr
enable timer1
start timer1
enable interrupts
'Add your code here
Timer1_ISR:
load timer1, Timer1Reload
'Add your ISR code here
return
'Timer value explination
' The timer is a 16Bit timer, it overflows when the timer reaches 65536
' The AVR is running at 4000000Hz, the prescaler is 1024
' Each tick is 0.256 ms - (1 / CPUSpeed in KHz ) * Prescaler
' The timer needs 3906 ticks to reach the required time ( 3906 * 0.256 = 999.936ms)
' The start value for the timer must be set to 61630 so that it will overflow at 65536 after 3906 ticks
' NOTE: The load command does the inversion for you (256-value or 65536-value)
|
I wrote a simple test program and it actually worked the first time!
Now, please help me understand.
As I see the above, the routine named "Timer1_ISR:" will run each time that the TIMER1 count reaches 65,536. Any code that is included in that routine will only be run (AND will be run each time) at that time. The TIMER1 function will have no effect on the main program.
What I am trying to do is to set some variables in my main program if they have not reached a certain value in 15 minutes. I entend to set the TIMER1 to interrupt every second (as in the above code from Ian's program) and in my ISR routine, I will simply count to 900 (i.e. 15 minutes times 60 seconds per minute). If the count ever reaches 900, then I will set my variables to 0.
Am I understanding this right??
Thanks and Regards,
Pete
PS
Ian,
I'd like to add my voice to the many who thank you for the AVR timer routine! |
|
Back to top |
|
|
JohnCannon
Joined: 04 Jan 2006 Posts: 162
|
Posted: Thu Jan 17, 2008 9:34 am Post subject: |
|
|
Hi,
If your system needs a Real Time Clock, you can get a 1 second imterrupt "SECTIC" with it. See HELP.
JC |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Jan 17, 2008 1:23 pm Post subject: |
|
|
Hi,
Glad you could make use of my tool. I plan to sit down and make afew improvements one day (Better error handling etc) but I don't have to time at the moment.
I actually wrote AVRTimer to help me understand how the timers work in AVR (I'm an old school programmer who needs to feel the bare metal to understand how it works).
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|