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 CCS Technical Support

#USE TIMER() elements can not understand

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

#USE TIMER() elements can not understand
PostPosted: Sun Oct 22, 2017 6:19 pm     Reply with quote

I have read the ccs c manual but can't understand the following elements function under #use timer(). Anybody can explain it clearly ??

Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 11:44 am     Reply with quote

Slightly difficult to know 'where to start'. A lot depends on how much you do understand.

The PIC has hardware timers that can be fed of various divisions from a clock. However the available divisions are limited. So if you setup a time on a particular oscillator, the result will be a counter that increments a number of times per second. So the first thing is that the code creates a define that specifies what this will actually be. By default this define is called 'TICKS_PER_SECOND'. The 'DEFINE=ID' part of the setup allows you to change this. So if you had DEFINE=MY_TICKS, the code would generate a line:
#define MY_TICKS xxxxxx

Where 'xxxxxx' is the number of ticks per second the timer has to use.

Now the hardware timers overflow at 65536 counts. To handle more counts than this there has to be extra code. There are two ways of calling this extra code. The first is automatic by using an ISR (interrupt service routine). If you specify 'ISR' the compiler will generate an ISR for you to automatically give effectively a 32bit counter. If you don;t specify this and use 'NOISR', then you must call 'get_ticks' at least once every 65536 ticks, for the code to handle the extra bits.

By default the timer runs from the master oscillator. You can also specify for it instead to count an external clock. This is what 'COUNTER' enables.

Now, once you have setup a timer like this you have a counter that counts 'TICKS_PER_SECOND' counts per second, which you can read with 'get_ticks'. If you want to setup more than one, then you can use a stream name. Giving the timers 'names', so you can then read the counts from multiple timers using get_ticks(name), where this is the name you have used.
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Tue Oct 24, 2017 3:49 pm     Reply with quote

what do you mean by master oscillator?? Is it the internal oscillator?
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 25, 2017 7:10 am     Reply with quote

yes this is what he means.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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