Skip to content

inittimer3

Anobium edited this page Oct 18, 2020 · 1 revision

InitTimer3

Syntax:

InitTimer3 source, prescaler

Command Availability:

Available on all microcontrollers with a Timer 3 module.

Explanation:

InitTimer3 will set up timer 3.

Parameters are required as detailed in the table below:

Parameter Description

source

The clock source for this specific timer. Can be either Osc, Ext or ExtOsc where:
Osc is an internal oscillator.
Ext is an external oscillator.



Osc - Selects the clock source in use, as set by the microcontroller specific configuration (fuses or #config).  This could be an internal clock or an external clock source ( external clock sources are typically attached to the XTAL pins).

Ext - Selects the clock source attached to a specific exernal interrupt input port.  This allows a different clock frequency than the main clock to be used, such as 32.768 kHz crystals commonly used for real time circuits.

ExtOsc is an external oscillator and only available on a Microchip PIC microcontroller.

Enhanced Microchip PIC microcontrollers with a dedicated TMRxCLK register support additional clock sources. This includes, but limited to, the following devices: 16F153xx, 16F16xx, 16F188xx and 18FxxK40 Microchip PIC microcontroller series On these devices the clock source can be one of the following:

Osc is an internal oscillator which is the same source as FOSC4.
Ext is an external oscillator which is the same source as TxXKIPPS.
ExtOsc is an external oscillator which is the same source as SOSC.
FOSC is an internal oscillator which is the Frequency of the OSCillator.
FOSC4 is an internal oscillator which is the Frequency of the OSCillator divided by 4.
SOSC is an external oscillator which is the same source as SOSC.
MFINTOSC is an internal 500KHz internal clock oscillator.
LFINTOSC is an internal 31Khz internal clock oscillator.
HFINTOSC is an oscillator as specified within the datasheet for each specific microcontroller.
TxCKIPPS is an oscillator input on TxCKIPPS Pin.

prescaler

The value of the prescaler for this specific timer. See the tables below for permitted vales for Microchip PIC or the Atmel AVR microcontrollers.

When the timer overflows an interrupt event will be generated. This interrupt event can be used in conjunction with On Interrupt to run a section of code when the interrupt event occurs.

Microchip PIC microcontrollers:

On Microchip PIC microcontrollers prescaler must be one of the following constants:

Prescaler Value Primary GCB Constant Constant Equates
to value

1:1

PS3_1

0

1:2

PS3_2

16

1:4

PS3_4

32

1:8

PS3_8

48

These correspond to a prescaler of between 1:2 and 1:8 of the oscillator (FOSC/4) speed. The prescaler will apply to either the oscillator or the external clock input.

Atmel AVR microcontrollers:

On the majority of Atmel AVR microcontrollers prescaler must be one of the following constants:

The prescaler will only apply when the timer is driven from the Osc the internal oscillator - the prescaler has no effect when the external clock source is specified.

Prescaler Value Primary GCB Constant Secondary GCB Constant Constant Equates
to value

1:0

PS_0

PS_3_0

1

1:1

PS_1

PS_3_1

1

1:8

PS_8

PS_3_8

2

1:64

PS_64

PS_3_64

3

1:256

PS_256

PS_3_256

4

1:1024

PS_1024

PS_3_1024

5

Supported in <TIMER.H>

Clone this wiki locally