InitTimer6

Syntax: (MicroChip PIC)

    InitTimer6 prescaler, postscaler

or, where you required to state the clock source, use the following

    InitTimer6 clocksource, prescaler, postscaler

Syntax: (Atmel AVR)

    InitTimer6 source, prescaler

Command Availability:

Available on all microcontrollers with a Timer 6 module.  As shown above a Microchip microcontroller can potentially support two types of methods for initialisation.

The first method is:

    InitTimer6 prescaler, postscaler

This the most common method to initialise a Microchip microcontroller timer.  With this method the timer has only one possible clock source, this mandated by the microcontrollers architecture, and that clock source is the System Clock/4 also known as FOSC/4.


The second method is much more flexible in term of the clock source.  Microcontrollers that support this second method enable you to select different clock sources and to select more prescale values.  The method is shown below:

    InitTimer6 clocksource, prescaler, postscaler

How do you determine which method to use for your specific Microchip microcontroller ?

The timer type for a Microchip microcontroller can be determined by checking for the existance of a T2CLKCON register, either in the Datasheet or in the GCBASIC "dat file" for the specific device.

If the Microchip microcontroller DOES NOT have a T2CLKCON register then timers 2/4/6/8 for that specific microcontroller chip use the first method, and are configured using:

    InitTimer6 (PreScale, PostScale)

If the microcontroller DOES have a T2CLKCON register then ALL timers 2/4/6/8 for that specific microcontroller chip use the second method, and are configured using:

    InitTimer6 (Source,PreScale,PostScale)

The possible Source, Prescale and Postscale constants for each type are shown in the tables below.  These table are summary tables from the Microchip datasheets.

Period of the Timers

The Period of the timer is determined by the system clock speed, the prescale value and 8-bit value in the respective timer period register.  The timer period for timer 6 is held in register PR6.  

When the timer is enabled, by starting the timer, it will increment until the TMR6 register matches the value in the PR6 register.  At this time the TMR6 register is cleared to 0 and the timer continues to increment until the next match, and so on.

The lower the value of the PR6 register, the shorter the timer period will be.  The default value for the PR6 register at power up is 255.

The timer interrupt flag (TMR6IF) is set based upon the number of match conditions as determine by the postscaler.  The postscaler does not actually change the timer period, it changes the time between interrupt conditions.

Timer constants for the MicroChip microcontrollers

Parameters for this timer are detailed in the tables below:

Parameter Description

clocksource

This is an optional parameter. Please review the datasheet for specific usage.
 
Source can be one of the following numeric values:
 
1 equates to OSC (FOSC/4).    The default clock source

6 equates to EXTOSC same as SOSC
5 equates to MFINTOSC
4 equates to LFINTOSC
3 equates to HFINTOSC
2 equates to FOSC
1 equates to FOSC/4 same as OSC
0 equates to TxCKIPPS same as EXTOSC and EXT (T1CKIPPS)

Other sources may be available but can vary from microcontroller to microcontroller and these can be included manually per the specific microcontrollers datasheet.

prescaler

The value of the prescaler for this specific timer. See the tables below for permitted values.

postscaler

The value of the postscaler for this specific timer. See the tables below for permitted values.

Table 1 shown above



prescaler can be one of the following settings, if you MicroChip microcontroller has the T6CKPS4 bit then refer to table 3:

Prescaler Value Primary GCB Constant Constant Equates
to value

1:1

PS6_1

0

1:4

PS6_4

1

1:16

PS6_16

2

1:64

PS6_64

3

Table 2

Note that a 1:64 prescale is only avaialable on certain midrange microcontrollers. Please refer to the datasheet to determine if a 1:64 prescale is supported by a spectific microcontroller.

Prescaler Value Primary GCB Constant Constant Equates
to value

1:1

PS6_1

0

1:2

PS6_2

1

1:4

PS6_4

2

1:8

PS6_8

3

1:16

PS6_16

4

1:32

PS6_32

5

1:64

PS6_64

6

1:128

PS6_128

7

Table 3

postscaler slows the rate of the interrupt generation (or WDT reset) from a counter/timer by dividing it down.

On Microchip PIC microcontroller one of the following constants where the Postscaler Rate Select bits are in the range of 1 to 16.

Postcaler Value Use Numeric Constant

1:1 Postscaler

0

1:2 Postscaler

1

1:3 Postscaler

2

1:4 Postscaler

3

1:5 Postscaler

4

1:6 Postscaler

5

1:7 Postscaler

6

1:8 Postscaler

7

1:9 Postscaler

8

1:10 Postscaler

9

1:11 Postscaler

10

1:12 Postscaler

11

1:13 Postscaler

12

1:14 Postscaler

13

1:15 Postscaler

14

1:16 Postscaler

15