CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

usb bootloader and timer0
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19227

View user's profile Send private message

PostPosted: Wed Nov 02, 2016 8:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 07, 2016 7:18 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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