|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19227
|
|
Posted: Wed Nov 02, 2016 8:16 am |
|
|
You are not using the timer's 'resolutiion'.
The 16bit timer is counting to 65536. The 8bit timer to 256. You are not using the timer 'count', but the _roll over_ (when it wraps). The smaller timer wraps more often, but if instead you read the timer value, the larger timer would give you more counts (resolution).
The only timer that can give you 1mSec interrupt on a standard PIC, is timer2. This is an 8bit timer, but has an adjustable count, and an adjustable postscaler (for the interrupt).
Code: |
setup_timer_2(T2_DIV_BY_16, 249, 3); |
From a 48MHz master clock, will give a 1mSec interrupt.
Fosc=48MHz
Fcy= 48E6/4 = 12MHz.
Division by 16*250*3 = 12000
Result 1000.
Don't get hooked on 'human' values though. If you look in the code library, there is an example using a timer counting in an odd fraction of a second to generate an accurate RTC, without any complex maths. 1mSec is very fast to run an interrupt on a PIC (you'll be spending a huge percentage of the chips time going into and out of this interrupt). Much better to run at a more sensible rate like perhaps the 183.1Hz (12MHz/65536). |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Mon Nov 07, 2016 7:18 am |
|
|
Ttelmah wrote: | You are not using the timer's 'resolutiion'.
The 16bit timer is counting to 65536. The 8bit timer to 256. You are not using the timer 'count', but the _roll over_ (when it wraps). The smaller timer wraps more often, but if instead you read the timer value, the larger timer would give you more counts (resolution).
The only timer that can give you 1mSec interrupt on a standard PIC, is timer2. This is an 8bit timer, but has an adjustable count, and an adjustable postscaler (for the interrupt).
Code: |
setup_timer_2(T2_DIV_BY_16, 249, 3); |
From a 48MHz master clock, will give a 1mSec interrupt.
Fosc=48MHz
Fcy= 48E6/4 = 12MHz.
Division by 16*250*3 = 12000
Result 1000.
Don't get hooked on 'human' values though. If you look in the code library, there is an example using a timer counting in an odd fraction of a second to generate an accurate RTC, without any complex maths. 1mSec is very fast to run an interrupt on a PIC (you'll be spending a huge percentage of the chips time going into and out of this interrupt). Much better to run at a more sensible rate like perhaps the 183.1Hz (12MHz/65536). |
Hello Ttelmah
Thank you for your reply and sorry for late respond. Even though you explained it very well, it is still a bit confusing for me. I will research more. Thank you for your help and explanation.
Best wishes,
Doğuhan |
|
|
|
|
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
|