|
|
View previous topic :: View next topic |
Author |
Message |
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
Timer question |
Posted: Thu Jul 16, 2015 12:54 pm |
|
|
This is on a 18f66j50.
The compiler version is 5.018
I have the following extremely small program that does nothing I care about except set up a timer. My question has to do with an "info" message posted by the compiler.
Obviously this is a stripped down version of a bigger program (the USB in the delay statement).
Code: | #include <18F66J50.h>
#use delay(internal=48MHz,USB_FULL)
#use timer(timer=3, tick=1s, bits=32, ISR, stream=T3)
#use rs232(baud=115200,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,stream=OUT)
#INT_TIMER3
void TIMER3_isr(void)
{
}
void main()
{
enable_interrupts(INT_EXT) ;
enable_interrupts(GLOBAL) ;
while(1)
{
}
} |
One of the messages produced by the compile is the following:
Quote: | --- Info 300 "timer3.c" Line 5(1,1): More info: Timer 3 tick time is 10.93 ms |
I cannot for the life of me figure out where the 10.93 comes from. If I understand the equations correctly, 1 tick = 1/(48000000/4)*prescale
I can't come up with any prescale or combination of prescale and postscale that gets me 10.93. I am guessing the 48000000 is wrong.
What am I missing? And, yes, I've been through the data sheets. Obviously I've missed or misunderstood something.
D. Scruggs _________________ D. Scruggs |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 16, 2015 1:11 pm |
|
|
I hate it when people enable interrupts without a handler. When cutting the program down remember that this is lethal.
The 'tick', is when the interrupt is called. The timer has divided by 65536 at this point
12MHz/(65536) = 183*/sec.
Use the /2 prescaler and you get 91.55* per second. So interrupt 10.922666mSec |
|
|
bcfd36
Joined: 14 Apr 2015 Posts: 28 Location: Boulder Creek, CA
|
|
Posted: Thu Jul 16, 2015 2:21 pm |
|
|
I don't understand about not having an interrupt handler when clearly there is a null one, but no matter.
I believe the matter is one of terminology and the inconsistent use of "tick" in various places. In my book (by Mark Siegesmund) it has the following:
Quote: | Timer tick = (1/fosc/cycles per instruction)*prescale
Overflow time = tick * 2**bits
Interrupt time = overflow_time * postscale
Interrupt rate = 1/overflow_time
|
What you are calling the tick is what he is calling the overflow time. What the compiler message is referring to is also what he is calling the overflow time.
From what I can see, the "#use timer" applies its own prescales and postscales that we can't see. _________________ D. Scruggs |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Jul 16, 2015 2:39 pm |
|
|
You have INT_EXT enabled, but no handler for it...
Tick is used for anything advancing.
It's just another name for 'clock'. However it is most commonly used where something changes/happens 'on' that clock.
So, the clock for the timer, is a 'tick', but it is also used for anything like a timing interrupt, that is then used as the basic interval for timing something. The 'tick interrupt'. So on the PC the tick interrupt, is normally 18.2 times per second. You are asking the timer to do a 'time' that it cannot do using the hardware timer, so it has to count in 'timer wrap ticks'.
#USE timer, is 'unfortunate'. It is done for people who can't be bothered to do the calculations themselves. All the "old hand's" will use setup_timer instead, not because it is what they are used to, but because it ensures they know _when_ things advance and what rates are actually being used. Its a balance between simplification, and knowing what is going on. |
|
|
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|