12
Timer Functions:
This section covers the operation of the timer module when it is used for non-
interrupt based operations, such as output compare and input capture functions.
Interrupt based timer features are discussed in chapter 5.
The basics of timer module operation:
There are several basic features of timer module that apply to both the input
capture and output compare functions, as well as interrupt driven Timer functions.
In order to make use of any timer based operations, the timer module must first be
enabled. This is done by setting _H12TSCR to 0x80. This will set the Timer Enable
bit (TEN), which then enables all timer operations.
_H12TSCR:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
TEN
TSWAI
TSBCK
TFFCA
unused
unused
unused
unused
The Timer uses a counter, also called a free running counter, that is incremented
by one every clock pulse. The free running counter on the 68HC12 can be accessed
by the user if needed. The free running counter is a 16-bit value that is stored
in the register _H12TCNT. It can be read at anytime, but can not be written to by
the user.
Port T is used as I/O pins for the timer input capture and timer output compare.
Each pin can serve as either an input capture or output compare pin. The function
of the pin is selected by the state of the _H12TIOS register. Each bit in _H12TIOS
corresponds to a pin of Port T. When the bit is set to 0, the pin is used as an
input capture, when the bit is set to a one, the pin is used as an output compare.
Any combination of input captures and output compares can be selected by the user.
_H12TIOS:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
pin 7
pin 6
pin 5
pin 4
pin 3
pin 2
pin 1
pin 0
The data for the input captures and output compares are stored in _H12TC0 to
_H12TC7. These are 16 bit registers. For input capture operations the value of the
free running counter will be latched into the register when the input capture is
triggered. For output compare operations the value in the register is used to
trigger an action.
The 68HC12 also allows the user to assign pull-up resistors to the timer module
inputs. This is done by writing a one to TPE in _H12TMSK2. This will enable the
pull-ups. A zero will disable them.
_H12TMSK2:
bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
TOIE
unused
TPE
TDRB
TCRE
PR2
PR1
PR0