View previous topic :: View next topic |
Author |
Message |
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
#USE TIMER() elements can not understand |
Posted: Sun Oct 22, 2017 6:19 pm |
|
|
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: 19550
|
|
Posted: Mon Oct 23, 2017 11:44 am |
|
|
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
|
|
Posted: Tue Oct 24, 2017 3:49 pm |
|
|
what do you mean by master oscillator?? Is it the internal oscillator? |
|
|
guy
Joined: 21 Oct 2005 Posts: 297
|
|
Posted: Wed Oct 25, 2017 7:10 am |
|
|
yes this is what he means. |
|
|
|