The information herein is given to describe certain components and shall not be considered as a guarantee of
characteristics.
Terms of delivery and rights to technical change reserved.
We hereby disclaim any and all warranties, including but not limited to warranties of non-infringement, regarding
circuits, descriptions and charts stated herein.
Information
For further information on technology, delivery terms and conditions and prices please contact your nearest
Infineon Technologies Office (www.infineon.com).
Warnings
Due to technical requirements components may contain dangerous substances. For information on the types in
question please contact your nearest Infineon Technologies Office.
Infineon Technologies Components may only be used in life-support devices or systems with the express written
approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure
of that life-support device or system, or to affect the safety or effectiveness of that device or system. Life support
devices or systems are intended to be implanted in the human body, or to support and/or maintain and sustain
and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may
be endangered.
User’s Manual, V2.2, Jan. 2004
XC161
16-Bit Single-Chip Microcontroller
with C166SV2 Core
1) In order to create the current version V2.2 of this manual, the layout of several graphics and text structures
has been adapted to company documentation rules. The contents have not been changed otherwise, except
for the Pre-release note on page 1-2 or obvious typographical errors.
Controller Area Network (CAN): License of Robert Bosch GmbH
We Listen to Your Comments
Any information within this document that you feel is wrong, unclear or missing at all?
Your feedback will help us to continuously improve the quality of this document.
Please send your proposal (including a reference to this document) to:
mcdocu.comments@infineon.com
Template: mc_tmplt_a5.fm / 3 / 2003-09-01
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Table of ContentsPage
This User’s Manual consists of two Volumes, “System Units” and “Peripheral Units”. For
your convenience this table of contents (and also the keyword index) lists both volumes,
so can immediately find the reference to the desired section in the corresponding
document ([1] or [2]).
The General Purpose Timer Unit blocks GPT1 and GPT2 have very flexible
multifunctional timer structures which may be used for timing, event counting, pulse
width measurement, pulse generation, frequency multiplication, and other purposes.
They incorporate five 16-bit timers that are grouped into the two timer blocks GPT1 and
GPT2. Each timer in each block may operate independently in a number of different
modes such as gated timer or counter mode, or may be concatenated with another timer
of the same block. Each block has alternate input/output functions and specific interrupts
associated with it.
Block GPT1 contains three timers/counters: The core timer T3 and the two auxiliary
timers T2 and T4. The maximum resolution is
optionally be configured as reload or capture registers for the core timer. These registers
are listed in Section 14.1.6.
Block GPT2 contains two timers/counters: The core timer T6 and the auxiliary timer T5.
The maximum resolution is
f
/2. An additional Capture/Reload register (CAPREL)
GPT
supports capture and reload operation with extended functionality. These registers are
listed in Section 14.2.7. The core timer T6 may be concatenated with timers of the
CAPCOM units (T0, T1, T7, and T8).
The following list summarizes the features which are supported:
•
f
/2 maximum resolution
GPT
•2 independent timers/counters
•Timers/counters can be concatenated
•3 operating modes:
– Timer Mode
– Gated Timer Mode
– Counter Mode
•Extended capture/reload functions via 16-bit capture/reload register CAPREL
•Separate interrupt lines
User’s Manual14-1V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1Timer Block GPT1
From a programmer’s point of view, the GPT1 block is composed of a set of SFRs as
summarized below. Those portions of port and direction registers which are used for
alternate functions by the GPT1 block are shaded.
Data RegistersControl RegistersPort Registers
T2T2CONT2IC
T3T3CONT3IC
T4T4CONT4IC
SYSCON3
TxGPT1 Timer x Register
TxCONGPT1 Timer x Control Register
TxICGPT1 Timer x Interrupt Ctrl. Reg.
SYSCON3System Ctrl. Reg. 3 (Per. M gmt.)
Interrupt Control
ODP3
DP3
P3
ALTSEL0P3
P5
P5DIDIS
ODP3Port 3 Open Drain Control Register
DP3Port 3 Direction Control Register
P3Port 3 Data Register
ALTSEL0P3 Port 3 Alternate Output Select Reg.
P5Port 5 Data Register
P5DIDISPort 5 Digital Input Disable Reg.
E
E
mc_gpt0100_registers.vsd
Figure 14-1SFRs Associated with Timer Block GPT1
All three timers of block GPT1 (T2, T3, T4) can run in one of 4 basic modes: Timer Mode,
Gated Timer Mode, Counter Mode, or Incremental Interface Mode. All timers can count
up or down. Each timer of GPT1 is controlled by a separate control register TxCON.
Each timer has an input pin TxIN (alternate pin function) associated with it, which serves
as the gate control in gated timer mode, or as the count input in counter mode. The count
direction (up/down) may be programmed via software or may be dynamically altered by
a signal at the External Up/Down control input TxEUD (alternate pin function). An
overflow/underflow of core timer T3 is indicated by the Output Toggle Latch T3OTL,
whose state may be output on the associated pin T3OUT (alternate pin function). The
auxiliary timers T2 and T4 may additionally be concatenated with the core timer T3
(through T3OTL) or may be used as capture or reload registers for the core timer T3.
The current contents of each timer can be read or modified by the CPU by accessing the
corresponding timer count registers T2, T3, or T4, located in the non-bitaddressable SFR
space (see Section 14.1.6). When any of the timer registers is written to by the CPU in
the state immediately preceding a timer increment, decrement, reload, or capture
operation, the CPU write operation has priority in order to guarantee correct results.
User’s Manual14-2V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
The interrupts of GPT1 are controlled through the Interrupt Control Registers TxIC.
These registers are not part of the GPT1 block. The input and output lines of GPT1 are
connected to pins of ports P3 and P5. The control registers for the port functions are
located in the respective port modules.
Note: The timing requirements for external input signals can be found in Section 14.1.5,
Section 14.3 summarizes the module interface signals, including pins.
T3CON.BPS1
GPT
T2I N
T2EUD
2n: 1f
T2
Mode
Control
Basic clock
U/D
Reload
Capture
Aux. Timer T2
Interrupt
Request
(T2IRQ)
T3I N
T3EUD
T4I N
T4EUD
T3
Mode
Control
T4
Mode
Control
U/D
Capture
Reload
U/D
Toggle Latch
Core Timer T3T3O TL
Aux. Timer T4
Interrupt
Request
(T3IRQ)
T3O UT
Interrupt
Request
(T4IRQ)
mc_gpt0101_bldiax1.vsd
Figure 14-2GPT1 Block Diagram (n = 2 … 5)
User’s Manual14-3V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1.1GPT1 Core Timer T3 Control
The current contents of the core timer T3 are reflected by its count register T3. This
register can also be written to by the CPU, for example, to set the initial start value.
The core timer T3 is configured and controlled via its bitaddressable control register
T3CON.
GPT12E_T3CON
Timer 3 Control RegisterSFR (FF42
1514131211109876543210
T3
T3
R
CH
DIR
DIR
rhrwhrwhrwrwhrwrwrwrwrwrw
T3
ED
GE
BPS1
T3
OTLT3OET3UDET3UD
FieldBitsTypDescription
/A1H)Reset Value: 0000
H
T3RT3MT3I
H
T3RDIR15rhTimer T3 Rotation Direction Flag
0Timer T3 counts up
1Timer T3 counts down
T3CHDIR14rwhTimer T3 Count Direction Change Flag
This bit is set each time the count direction of timer
T3 changes. T3CHDIR must be cleared by SW.
0No change of count direction was detected
1A change of count direction was detected
T3EDGE13rwhTimer T3 Edge Detection Flag
The bit is set each time a count edge is detected.
T3EDGE must be cleared by SW.
0No count edge was detected
1A count edge was detected
BPS1[12:11] rwGPT1 Block Prescaler Control
Selects the basic clock for block GPT1
(see also Section 14.1.5)
00
01
10
11
f
GPT
f
GPT
f
GPT
f
GPT
/8
/4
/32
/16
T3OTL10rwhTimer T3 Overflow Toggle Latch
Toggles on each overflow/underflow of T3. Can be
set or reset by software (see separate description)
0Alternate Output Function Disabled
1State of T3 toggle latch is output on pin T3OUT
T3UDE8rwTimer T3 External Up/Down Enable
0Input T3EUD is disconnected
1Direction influenced by input T3EUD
T3UD7rwTimer T3 Up/Down Control
1)
1)
T3R6rwTimer T3 Run Bit
0Timer T3 stops
1Timer T3 runs
T3M[5:3]rwTimer T3 Mode Control (Basic Operating Mode)
000Timer Mode
001Counter Mode
010Gated Timer Mode with gate active low
011Gated Timer Mode with gate active high
100Reserved. Do not use this combination.
101Reserved. Do not use this combination.
110Incremental Interface Mode
(Rotation Detection Mode)
111Incremental Interface Mode
(Edge Detection Mode)
T3I[2:0]rwTimer T3 Input Parameter Selection
Depends on the operating mode, see respective
sections for encoding:
Table 14-7 for Timer Mode and Gated Timer Mode
Table 14-2 for Counter Mode
Table 14-3 for Incremental Interface Mode
1) See Table 14-1 for encoding of bits T3UD and T3EUD.
User’s Manual14-5V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timer T3 Run Control
The core timer T3 can be started or stopped by software through bit T3R (Timer T3 Run
Bit). This bit is relevant in all operating modes of T3. Setting bit T3R will start the timer,
clearing bit T3R stops the timer.
In gated timer mode, the timer will only run if T3R = 1 and the gate is active (high or low,
as programmed).
Note: When bit T2RC or T4RC in timer control register T2CON or T4CON is set, bit T3R
will also control (start and stop) the auxiliary timer(s) T2 and/or T4.
Count Direction Control
The count direction of the GPT1 timers (core timer and auxiliary timers) can be controlled
either by software or by the external input pin TxEUD (Timer Tx External Up/Down
Control Input). These options are selected by bits TxUD and TxUDE in the respective
control register TxCON. When the up/down control is provided by software (bit
TxUDE = 0), the count direction can be altered by setting or clearing bit TxUD. When bit
TxUDE = 1, pin TxEUD is selected to be the controlling source of the count direction.
However, bit TxUD can still be used to reverse the actual count direction, as shown in
Table 14-1. The count direction can be changed regardless of whether or not the timer
is running.
Note: When pin TxEUD is used as external count direction control input, it must be
configured as input (its corresponding direction control bit must be cleared).
Table 14-1GPT1 Timer Count Direction Control
Pin TxEUDBit TxUDEBit TxUDCount DirectionBit TxRDIR
The overflow/underflow signal of timer T3 is connected to a block named ‘Toggle Latch’,
shown in the timer mode diagrams. Figure 14-3 illustrates the details of this block. An
overflow or underflow of T3 will clock two latches: The first latch represents bit T3OTL in
control register T3CON. The second latch is an internal latch toggled by T3OTL’s output.
Both latch outputs are connected to the input control blocks of the auxiliary timers T2 and
T4. The output level of the shadow latch will match the output level of T3OTL, but is
delayed by one clock cycle. When the T3OTL value changes, this will result in a
temporarily different output level from T3OTL and the shadow latch, which can trigger
the selected count event in T2 and/or T4.
When software writes to T3OTL, both latches are set or cleared simultaneously. In this
case, both signals to the auxiliary timers carry the same level and no edge will be
detected. Bit T3OE (overflow/underflow output enable) in register T3CON enables the
state of T3OTL to be monitored via an external pin T3OUT. When T3OTL is linked to an
external port pin (must be configured as output), T3OUT can be used to control external
HW. If T3OE = 1, pin T3OUT outputs the state of T3OTL. If T3OE = 0, pin T3OUT
outputs a high level (as long as the T3OUT alternate function is selected for the port pin).
The trigger signals can serve as an input for the counter function or as a trigger source
for the reload function of the auxiliary timers T2 and T4.
As can be seen from Figure 14-3, when latch T3OTL is modified by software to
determine the state of the output line, also the internal shadow latch is set or cleared
accordingly. Therefore, no trigger condition is detected by T2/T4 in this case.
Core Timer
Overflow/
Underflow
Set/Clear (SW )
TxOTL
Toggle Latch Logic
1
Shadow
Latch
1
0
TxOE
MUX
To Port Logic
To Aux. Timer
Input Logic
mc_gpt0106_otl.vsd
TxOUT
Figure 14-3Block Diagram of the Toggle Latch Logic of Core Timer T3
User’s Manual14-7V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1.2GPT1 Core Timer T3 Operating Modes
Timer 3 in Timer Mode
Timer mode for the core timer T3 is selected by setting bitfield T3M in register T3CON
to 000
programmable prescalers controlled by bitfields BPS1 and T3I in register T3CON.
Please see Section 14.1.5 for details on the input clock options.
T3EUD
. In timer mode, T3 is clocked with the module’s input clock f
B
GPT
f
PrescalerCore Timer T3Toggle Latch
BPS1T3I
T3UD
T3
=1
T3R
0
1
Count
MUX
Up/Down
divided by two
GPT
T3IRQ
T3OUT
to
T2/T4
T3UDE
MCB05391
Figure 14-4Block Diagram of Core Timer T3 in Timer Mode
User’s Manual14-8V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Gated Timer Mode
Gated timer mode for the core timer T3 is selected by setting bitfield T3M in register
T3CON to 010
or 011B. Bit T3M.0 (T3CON.3) selects the active level of the gate input.
B
The same options for the input frequency are available in gated timer mode as in timer
mode (see Section 14.1.5). However, the input clock to the timer in this mode is gated
by the external input pin T3IN (Timer T3 External Input).
To enable this operation, the associated pin T3IN must be configured as input, that is,
the corresponding direction control bit must contain 0.
T3IRQ
f
GPT
T3IN
Prescaler
BPS1T3I
Gate
Ctrl.
T3
T3R
Count
Core Timer T3Toggle Latch
T3OUT
to
T2/T4
T3UD
0
MUX
Up/Down
MCB05392
T3EUD
=1
1
T3UDE
Figure 14-5Block Diagram of Core Timer T3 in Gated Timer Mode
If T3M = 010
stops the timer. If T3M = 011
, the timer is enabled when T3IN shows a low level. A high level at this line
B
, line T3IN must have a high level in order to enable the
B
timer. Additionally, the timer can be turned on or off by software using bit T3R. The timer
will only run if T3R is 1 and the gate is active. It will stop if either T3R is 0 or the gate is
inactive.
Note: A transition of the gate signal at pin T3IN does not cause an interrupt request.
User’s Manual14-9V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Counter Mode
Counter Mode for the core timer T3 is selected by setting bitfield T3M in register T3CON
to 001
. In counter mode, timer T3 is clocked by a transition at the external input pin
B
T3IN. The event causing an increment or decrement of the timer can be a positive, a
negative, or both a positive and a negative transition at this line. Bitfield T3I in control
register T3CON selects the triggering transition (see Table 14-2).
T3IRQ
Edge
T3IN
Select
T3I
T3UD
=1
T3EUD
T3R
0
1
Count
MUX
Core Timer T3Toggle Latch
Up/Down
T3OUT
to
T2/T4
T3UDE
MCB05393
Figure 14-6Block Diagram of Core Timer T3 in Counter Mode
Table 14-2GPT1 Core Timer T3 (Counter Mode) Input Edge Selection
T3ITriggering Edge for Counter Increment/Decrement
0 0 0None. Counter T3 is disabled
0 0 1Positive transition (rising edge) on T3IN
0 1 0Negative transition (falling edge) on T3IN
0 1 1Any transition (rising or falling edge) on T3IN
1 X XReserved. Do not use this combination
For counter mode operation, pin T3IN must be configured as input (the respective
direction control bit DPx.y must be 0). The maximum input frequency allowed in counter
mode depends on the selected prescaler value. To ensure that a transition of the count
input signal applied to T3IN is recognized correctly, its level must be held high or low for
a minimum number of module clock cycles before it changes. This information can be
found in Section 14.1.5.
User’s Manual14-10V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Incremental Interface Mode
Incremental interface mode for the core timer T3 is selected by setting bitfield T3M in
register T3CON to 110
or 111B. In incremental interface mode, the two inputs
B
associated with core timer T3 (T3IN, T3EUD) are used to interface to an incremental
encoder. T3 is clocked by each transition on one or both of the external input pins to
provide 2-fold or 4-fold resolution of the encoder input.
T3IN
Edge
Select
T3I
T3R
Count
T3
EDGE
Core
Timer T3
T3
RDIR
Toggle
Latch
_
>1
T3OUT
to
T2/T4
T3IRQ
T3UD
0
T3EUD
Phase
Detect
=1
1
T3UDE
MUX
Change
Detect
T3CH
DIR
T3M
T3M
MCB05394
Figure 14-7Block Diagram of Core Timer T3 in Incremental Interface Mode
Bitfield T3I in control register T3CON selects the triggering transitions (see Table 14-3).
The sequence of the transitions of the two input signals is evaluated and generates count
pulses as well as the direction signal. So T3 is modified automatically according to the
speed and the direction of the incremental encoder and, therefore, its contents always
represent the encoder’s current position.
The interrupt request (T3IRQ) generation mode can be selected: In Rotation Detection
Mode (T3M = 110
T3 changes. In Edge Detection Mode (T3M = 111
), an interrupt request is generated each time the count direction of
B
), an interrupt request is generated
B
each time a count edge for T3 is detected. Count direction, changes in the count
direction, and count requests are monitored by status bits T3RDIR, T3CHDIR, and
T3EDGE in register T3CON.
User’s Manual14-11V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Table 14-3Core Timer T3 (Incremental Interface Mode) Input Edge Selection
T3ITriggering Edge for Counter Increment/Decrement
0 0 0None. Counter T3 stops.
0 0 1Any transition (rising or falling edge) on T3IN.
0 1 0Any transition (rising or falling edge) on T3EUD.
0 1 1Any transition (rising or falling edge) on any T3 input (T3IN or T3EUD).
1 X XReserved. Do not use this combination.
The incremental encoder can be connected directly to the XC161 without external
interface logic. In a standard system, however, comparators will be employed to convert
the encoder’s differential outputs (such as A, A
) to digital signals (such as A). This greatly
increases noise immunity.
Note: The third encoder output T0, which indicates the mechanical zero position, may
be connected to an external interrupt input and trigger a reset of timer T3 (for
example via PEC transfer from ZEROS).
Signal
EncoderController
A
A
B
B
T0
T0
Conditioning
A
B
T0
T3Input
T3Input
Interrupt
MCS04372
Figure 14-8Connection of the Encoder to the XC161
For incremental interface operation, the following conditions must be met:
•Bitfield T3M must be 110
or 111B.
B
•Both pins T3IN and T3EUD must be configured as input, i.e. the respective direction
control bits must be 0.
•Bit T3UDE must be 1 to enable automatic external direction control.
The maximum count frequency allowed in incremental interface mode depends on the
selected prescaler value. To ensure that a transition of any input signal is recognized
correctly, its level must be held high or low for a minimum number of module clock cycles
before it changes. This information can be found in Section 14.1.5.
User’s Manual14-12V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
As in incremental interface mode two input signals with a 90° phase shift are evaluated,
their maximum input frequency can be half the maximum count frequency.
In incremental interface mode, the count direction is automatically derived from the
sequence in which the input signals change, which corresponds to the rotation direction
of the connected sensor. Table 14-4 summarizes the possible combinations.
Table 14-4GPT1 Core Timer T3 (Incremental Interface Mode) Count Direction
Level on Respective
other Input
Rising Falling Rising Falling
T3IN InputT3EUD Input
HighDownUpUpDown
LowUpDownDownUp
Figure 14-9 and Figure 14-10 give examples of T3’s operation, visualizing count signal
generation and direction control. They also show how input jitter is compensated, which
might occur if the sensor rests near to one of its switching points.
ForwardJitterBackwardJitterForward
T3IN
T3EUD
Contents
of T3
Note: This example shows the timer behaviour assuming that T3 counts upon any
transition on input, i.e. T3I = '011
UpDownUp
'.
B
MCT04373
Figure 14-9Evaluation of Incremental Encoder Signals, 2 Count Inputs
User’s Manual14-13V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
ForwardJitterBackwardJitterForward
T3IN
T3EUD
Contents
of T3
Note: This example shows the timer behaviour assuming that T3 counts upon any
transition on input T3IN, i.e. T3I = '001
UpDownUp
The General Purpose Timer Units
'.
B
MCT04374
Figure 14-10 Evaluation of Incremental Encoder Signals, 1 Count Input
Note: Timer T3 operating in incremental interface mode automatically provides
information on the sensor’s current position. Dynamic information (speed,
acceleration, deceleration) may be obtained by measuring the incoming signal
periods. This is facilitated by an additional special capture mode for timer T5 (see
Section 14.2.5).
User’s Manual14-14V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1.3GPT1 Auxiliary Timers T2/T4 Control
Auxiliary timers T2 and T4 have exactly the same functionality. They can be configured
for timer mode, gated timer mode, counter mode, or incremental interface mode with the
same options for the timer frequencies and the count signal as the core timer T3. In
addition to these 4 counting modes, the auxiliary timers can be concatenated with the
core timer, or they may be used as reload or capture registers in conjunction with the
core timer. The start/stop function of the auxiliary timers can be remotely controlled by
the T3 run control bit. Several timers may thus be controlled synchronously.
The current contents of an auxiliary timer are reflected by its count register T2 or T4,
respectively. These registers can also be written to by the CPU, for example, to set the
initial start value.
The individual configurations for timers T2 and T4 are determined by their bitaddressable
control registers T2CON and T4CON, which are organized identically. Note that
functions which are present in all 3 timers of block GPT1 are controlled in the same bit
positions and in the same manner in each of the specific control registers.
Note: The auxiliary timers have no output toggle latch and no alternate output function.
GPT12E_T2CON
Timer 2 Control RegisterSFR (FF40
1514131211109876543210
T2
T2
R
CH
DIR
DIR
rhrwhrwhrw--rwrwrwrwrwrw
T2
ED
GE
T2
IR
DIS
--
T2RCT2
UDET2UD
/A0H)Reset Value: 0000
H
T2RT2MT2I
GPT12E_T4CON
Timer 4 Control RegisterSFR (FF44
1514131211109876543210
T4
T4
R
CH
DIR
DIR
rhrwhrwhrw--rwrwrwrwrwrw
T4
ED
GE
T4
IR
DIS
--
T4RCT4
UDET4UD
/A2H)Reset Value: 0000
H
T4RT4MT4I
FieldBitsTypDescription
H
H
TxRDIR15rhTimer Tx Rotation Direction
0Timer x counts up
1Timer x counts down
User’s Manual14-15V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
FieldBitsTypDescription
TxCHDIR14rwhTimer Tx Count Direction Change
This bit is set each time the count direction of timer
Tx changes. TxCHDIR must be cleared by SW.
0No change in count direction was detected
1A change in count direction was detected
TxEDGE13rwhTimer Tx Edge Detection
The bit is set each time a count edge is detected.
TxEDGE must be cleared by SW.
0No count edge was detected
1A count edge was detected
TxIRDIS12rwTimer Tx Interrupt Request Disable
0Interrupt generation for TxCHDIR and
TxEDGE interrupts in Incremental Interface
Mode is enabled
1Interrupt generation for TxCHDIR and
TxEDGE interrupts in Incremental Interface
Mode is disabled
TxRC9rwTimer Tx Remote Control
0Timer Tx is controlled by its own run bit TxR
1Timer Tx is controlled by the run bit T3R of core
timer 3, not by bit TxR
TxUDE8rwTimer Tx External Up/Down Enable
0Input TxEUD is disconnected
1Direction influenced by input TxEUD
TxUD7rwTimer Tx Up/Down Control
1)
1)
TxR6rwTimer Tx Run Bit
0Timer Tx stops
1Timer Tx runs
Note: This bit only controls timer Tx if bit TxRC = 0.
TxM[5:3]rwTimer Tx Mode Control (Basic Operating Mode)
000Timer Mode
001Counter Mode
010Gated Timer Mode with gate active low
011Gated Timer Mode with gate active high
100Reload Mode
101Capture Mode
110Incremental Interface Mode (Rotation Detect.)
111Incremental Interface Mode (Edge Detection)
Depends on the operating mode, see respective
sections for encoding:
Table 14-7 for Timer Mode and Gated Timer Mode
Table 14-2 for Counter Mode
Table 14-3 for Incremental Interface Mode
1) See Table 14-1 for encoding of bits TxUD and TxEUD.
Timer T2/T4 Run Control
Each of the auxiliary timers T2 and T4 can be started or stopped by software in two
different ways:
•Through the associated timer run bit (T2R or T4R). In this case it is required that the
respective control bit TxRC = 0.
•Through the core timer’s run bit (T3R). In this case the respective remote control bit
must be set (TxRC = 1).
The selected run bit is relevant in all operating modes of T2/T4. Setting the bit will start
the timer, clearing the bit stops the timer.
In gated timer mode, the timer will only run if the selected run bit is set and the gate is
active (high or low, as programmed).
Note: If remote control is selected T3R will start/stop timer T3 and the selected auxiliary
timer(s) synchronously.
Count Direction Control
The count direction of the GPT1 timers (core timer and auxiliary timers) is controlled in
the same way, either by software or by the external input pin TxEUD. Please refer to the
description in Table 14-1.
Note: When pin TxEUD is used as external count direction control input, it must be
configured as input (its corresponding direction control bit must be cleared).
User’s Manual14-17V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1.4GPT1 Auxiliary Timers T2/T4 Operating Modes
The operation of the auxiliary timers in the basic operating modes is almost identical with
the core timer’s operation, with very few exceptions. Additionally, some combined
operating modes can be selected.
Timers T2 and T4 in Timer Mode
Timer mode for an auxiliary timer Tx is selected by setting its bitfield TxM in register
TxCON to 000
GPT
.
B
Prescaler
BPS1TxI
TxR
T3R
f
Tx
0
MUX
1
Count
Auxiliary
Timer Tx
TxIRQ
TxRC
TxUD
0
MUX
Up/Down
x = 2, 4
MCB05395
TxEUD
=1
1
TxUDE
Figure 14-11 Block Diagram of an Auxiliary Timer in Timer Mode
User’s Manual14-18V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timers T2 and T4 in Gated Timer Mode
Gated timer mode for an auxiliary timer Tx is selected by setting bitfield TxM in register
TxCON to 010
or 011B. Bit TxM.0 (TxCON.3) selects the active level of the gate input.
B
Note: A transition of the gate signal at line TxINdoes not cause an interrupt request.
f
0
1
=1
Tx
MUX
TxRC
Count
0
MUX
1
Up/Down
Auxiliary
Timer Tx
TxIRQ
GPT
TxIN
TxEUD
Prescaler
BPS1TxI
TxUD
Gate
Ctrl.
TxM
TxR
T3R
TxUDE
x = 2, 4
MCB05396
Figure 14-12 Block Diagram of an Auxiliary Timer in Gated Timer Mode
Note: There is no output toggle latch for T2 and T4.
Start/stop of an auxiliary timer can be controlled locally or remotely.
User’s Manual14-19V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timers T2 and T4 in Counter Mode
Counter mode for an auxiliary timer Tx is selected by setting bitfield TxM in register
TxCON to 001
. In counter mode, an auxiliary timer can be clocked either by a transition
B
at its external input line TxIN, or by a transition of timer T3’s toggle latch T3OTL. The
event causing an increment or decrement of a timer can be a positive, a negative, or both
a positive and a negative transition at either the respective input pin or at the toggle latch.
Bitfield TxI in control register TxCON selects the triggering transition (see Table 14-5).
TxR
T3R
Edge
Select
TxI
0
1
MUX
Count
Auxiliary
Timer Tx
TxIRQ
TxIN
T3
Toggle
Latch
0
MUX
1
TxI.2
TxRC
TxUD
0
MUX
Up/Down
x = 2, 4
MCB05397
TxEUD
=1
1
TxUDE
Figure 14-13 Block Diagram of an Auxiliary Timer in Counter Mode
X 0 0None. Counter Tx is disabled
0 0 1Positive transition (rising edge) on TxIN
0 1 0Negative transition (falling edge) on TxIN
0 1 1Any transition (rising or falling edge) on TxIN
1 0 1Positive transition (rising edge) of T3 toggle latch T3OTL
1 1 0Negative transition (falling edge) of T3 toggle latch T3OTL
1 1 1Any transition (rising or falling edge) of T3 toggle latch T3OTL
Note: Only state transitions of T3OTL which are caused by the overflows/underflows of
T3 will trigger the counter function of T2/T4. Modifications of T3OTL via software
will NOT trigger the counter function of T2/T4.
User’s Manual14-20V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
For counter operation, pin TxIN must be configured as input (the respective direction
control bit DPx.y must be 0). The maximum input frequency allowed in counter mode
depends on the selected prescaler value. To ensure that a transition of the count input
signal applied to TxIN is recognized correctly, its level must be held high or low for a
minimum number of module clock cycles before it changes. This information can be
found in Section 14.1.5.
Timers T2 and T4 in Incremental Interface Mode
Incremental interface mode for an auxiliary timer Tx is selected by setting bitfield TxM in
the respective register TxCON to 110
or 111B. In incremental interface mode, the two
B
inputs associated with an auxiliary timer Tx (TxIN, TxEUD) are used to interface to an
incremental encoder. Tx is clocked by each transition on one or both of the external input
pins to provide 2-fold or 4-fold resolution of the encoder input.
TxIN
Edge
Select
Count
Auxiliary
Timer Tx
Overflow
Underflow
0
1
MUX
TxRC
=1
0
1
TxUDE
Tx
Edge
MUX
Tx
RDIR
Change
Detect
TxCH
DIR
TxM
TxM
&
&
TxIRDIS
_
>1
TxIRQ
MCB05398
TxEUD
TxI
TxUD
Phase
Detect
TxR
T3R
Figure 14-14 Block Diagram of an Auxiliary Timer in Incremental Interface Mode
The operation of the auxiliary timers T2 and T4 in incremental interface mode and the
interrupt generation are the same as described for the core timer T3. The descriptions,
figures and tables apply accordingly.
User’s Manual14-21V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timer Concatenation
Using the toggle bit T3OTL as a clock source for an auxiliary timer in counter mode
concatenates the core timer T3 with the respective auxiliary timer. This concatenation
forms either a 32-bit or a 33-bit timer/counter, depending on which transition of T3OTL
is selected to clock the auxiliary timer.
•32-bit Timer/Counter: If both a positive and a negative transition of T3OTL are used
to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the
core timer T3. Thus, the two timers form a 32-bit timer.
•33-bit Timer/Counter: If either a positive or a negative transition of T3OTL is
selected to clock the auxiliary timer, this timer is clocked on every second
overflow/underflow of the core timer T3. This configuration forms a 33-bit timer (16-bit
core timer + T3OTL + 16-bit auxiliary timer).
As long as bit T3OTL is not modified by software, it represents the state of the internal
toggle latch, and can be regarded as part of the 33-bit timer.
The count directions of the two concatenated timers are not required to be the same.
This offers a wide variety of different configurations.
T3, which represents the low-order part of the concatenated timer, can operate in timer
mode, gated timer mode or counter mode in this case.
T3IRQ
GPT
T3IN
TxIN
Operating
Mode
Control
BPS1TxI
0
MUX
1
TxI.2
T3R
Edge
Select
TxI
Count
TxR
T3R
Core Timer T3
Up/Down
0
MUX
1
TxRC
Count
Toggle LatchT3OUT
Auxiliary
Timer Tx
Up/Down
x = 2, 4
TxIRQ
MCA05399
Figure 14-15 Concatenation of Core Timer T3 and an Auxiliary Timer
User’s Manual14-22V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Auxiliary Timer in Reload Mode
Reload Mode for an auxiliary timer Tx is selected by setting bitfield TxM in the respective
register TxCON to 100
. In reload mode, the core timer T3 is reloaded with the contents
B
of an auxiliary timer register, triggered by one of two different signals. The trigger signal
is selected the same way as the clock source for counter mode (see Table 14-5), i.e. a
transition of the auxiliary timer’s input TxIN or the toggle latch T3OTL may trigger the
reload.
Note: When programmed for reload mode, the respective auxiliary timer (T2 or T4) stops
independently of its run flag T2R or T4R.
The timer input pin TxIN must be configured as input if it shall trigger a reload
operation.
T3IRQ
GPT
T3IN
Operating
Mode
Control
Count
Core Timer T3
Toggle LatchT3OUT
Up/Down
Reload
TxIRQ
Auxiliary
Timer Tx
x = 2, 4
MCA05400
TxIN
BPS1TxI
0
MUX
1
TxI.2
T3R
Edge
Select
TxI
Figure 14-16 GPT1 Auxiliary Timer in Reload Mode
Upon a trigger signal, T3 is loaded with the contents of the respective timer register (T2
or T4) and the respective interrupt request flag (T2IR or T4IR) is set.
Note: When a T3OTL transition is selected for the trigger signal, the interrupt request
flag T3IR will also be set upon a trigger, indicating T3’s overflow or underflow.
Modifications of T3OTL via software will NOT trigger the counter function of T2/T4.
To ensure that a transition of the reload input signal applied to TxIN is recognized
correctly, its level must be held high or low for a minimum number of module clock
cycles, detailed in Section 14.1.5.
The reload mode triggered by the T3 toggle latch can be used in a number of different
configurations. The following functions can be performed, depending on the selected
active transition:
User’s Manual14-23V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
•If both a positive and a negative transition of T3OTL are selected to trigger a reload,
the core timer will be reloaded with the contents of the auxiliary timer each time it
overflows or underflows. This is the standard reload mode (reload on
overflow/underflow).
•If either a positive or a negative transition of T3OTL is selected to trigger a reload, the
core timer will be reloaded with the contents of the auxiliary timer on every second
overflow or underflow.
•Using this “single-transition” mode for both auxiliary timers allows to perform very
flexible Pulse Width Modulation (PWM). One of the auxiliary timers is programmed to
reload the core timer on a positive transition of T3OTL, the other is programmed for
a reload on a negative transition of T3OTL. With this combination the core timer is
alternately reloaded from the two auxiliary timers.
Figure 14-17 shows an example for the generation of a PWM signal using the “single-
transition” reload mechanism. T2 defines the high time of the PWM signal (reloaded on
positive transitions) and T4 defines the low time of the PWM signal (reloaded on negative
transitions). The PWM signal can be output on pin T3OUT if T3OE = 1. With this method,
the high and low time of the PWM signal can be varied in a wide range.
Note: The output toggle latch T3OTL is accessible via software and may be changed, if
required, to modify the PWM signal.
However, this will NOT trigger the reloading of T3.
User’s Manual14-24V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
Auxiliary
Timer T2
T2IN
GPT
T3IN
0
MUX
1
T2I.2
Operating
Mode
Control
BPS1T3I
Edge
Select
T2I
T3R
Reload
Count
Core Timer T3
Up/Down
The General Purpose Timer Units
T2IRQ
T3IRQ
Toggle LatchT3OUT
T4IN
0
1
MUX
T4I.2
Edge
Select
T4I
Reload
T4IRQ
Auxiliary
Timer T4
MCA05401
Figure 14-17 GPT1 Timer Reload Configuration for PWM Generation
Note: Although possible, selecting the same reload trigger event for both auxiliary timers
should be avoided. In such a case, both reload registers would try to load the core
timer at the same time. If this combination is selected, T2 is disregarded and the
contents of T4 is reloaded.
User’s Manual14-25V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Auxiliary Timer in Capture Mode
Capture mode for an auxiliary timer Tx is selected by setting bitfield TxM in the respective
register TxCON to 101
. In capture mode, the contents of the core timer T3 are latched
B
into an auxiliary timer register in response to a signal transition at the respective auxiliary
timer’s external input pin TxIN. The capture trigger signal can be a positive, a negative,
or both a positive and a negative transition.
The two least significant bits of bitfield TxI select the active transition (see Table 14-5).
Bit 2 of TxI is irrelevant for capture mode and must be cleared (TxI.2 = 0).
Note: When programmed for capture mode, the respective auxiliary timer (T2 or T4)
stops independently of its run flag T2R or T4R.
T3IRQ
GPT
T3IN
Operating
Mode
Control
BPS1T3I
T3R
Count
Core Timer T3
Up/Down
Toggle LatchT3OUT
to Ty
Edge
TxIN
Select
TxI
Capture
Auxiliary
Timer Tx
TxIRQ
x = 2, 4
y = 4, 2
MCA05402
Figure 14-18 GPT1 Auxiliary Timer in Capture Mode
Upon a trigger (selected transition) at the corresponding input pin TxIN the contents of
the core timer are loaded into the auxiliary timer register and the associated interrupt
request flag TxIR will be set.
For capture mode operation, the respective timer input pin TxIN must be configured as
input. To ensure that a transition of the capture input signal applied to TxIN is recognized
correctly, its level must be held high or low for a minimum number of module clock
cycles, detailed in Section 14.1.5.
User’s Manual14-26V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.1.5GPT1 Clock Signal Control
All actions within the timer block GPT1 are triggered by transitions of its basic clock. This
basic clock is derived from the system clock by a basic block prescaler, controlled by
bitfield BPS1 in register T3CON (see Figure 14-2). The count clock can be generated in
two different ways:
•Internal count clock, derived from GPT1’s basic clock via a programmable
prescaler, is used for (gated) timer mode.
•External count clock, derived from the timer’s input pin(s), is used for counter mode.
For both ways, the basic clock determines the maximum count frequency and the timer’s
resolution:
Table 14-6Basic Clock Selection for Block GPT1
Block Prescaler
1)
Prescaling Factor for
GPT1: F(BPS1)
BPS1 = 01
F(BPS1)
= 4
BPS1 = 00
B
F(BPS1)
= 8
2)
BPS1 = 11
B
F(BPS1)
= 16
BPS1 = 10
B
F(BPS1)
= 32
B
Maximum External
/8f
GPT
/16f
GPT
/32f
GPT
GPT
/64
f
Count Frequency
Input Signal
4
× t
GPT
8 ×t
GPT
16 ×t
GPT
32 ×t
GPT
Stable Time
1) Please note the non-linear encoding of bitfield BPS1.
2) Default after reset.
Internal Count Clock Generation
In timer mode and gated timer mode, the count clock for each GPT1 timer is derived from
the GPT1 basic clock by a programmable prescaler, controlled by bitfield TxI in the
respective timer’s control register TxCON.
The count frequency
f
for a timer Tx and its resolution rTx are scaled linearly with lower
Tx
clock frequencies, as can be seen from the following formula:
<Txl>
×
MHz[]
(14.1)
Tx
f
------------ ------------------------ ---------=r
F BPS1()2
GPT
<Txl>
×
Tx
µs[]
F BPS1()2
------------ ------------------------ ---------=
f
GPT
The effective count frequency depends on the common module clock prescaler factor
<TxI>
F(BPS1) as well as on the individual input prescaler factor 2
. Table 14-7 summarizes
the resulting overall divider factors for a GPT1 timer that result from these cascaded
prescalers.
Table 14-8 lists a timer’s parameters (such as count frequency, resolution, and period)
resulting from the selected overall prescaler factor and the applied system frequency.
Note that some numbers may be rounded.
User’s Manual14-27V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Table 14-7GPT1 Overall Prescaler Factors for Internal Count Clock
Individual
µs104.9 ms162.5 MHz400 ns26.21 ms
µs209.7 ms321.25 MHz800 ns52.43 ms
µs419.4 ms64625.0 kHz1.6 µs104.9 ms
µs838.9 ms128312.5 kHz3.2 µs209.7 ms
µs1.678 s256156.25 kHz6.4 µs419.4 ms
µs3.355 s51278.125 kHz12.8 µs838.9 ms
µs6.711 s102439.06 kHz25.6 µs1.678 s
µs13.42 s204819.53 kHz51.2 µs3.355 s
µs26.84 s40969.77 kHz102.4 µs6.711 s
410.0 MHz100 ns6.55 ms
85.0 MHz200 ns13.11 ms
User’s Manual14-28V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
External Count Clock Input
The external input signals of the GPT1 block are sampled with the GPT1 basic clock (see
Figure 14-2). To ensure that a signal is recognized correctly, its current level (high or
low) must be held active for at least one complete sampling period, before changing. A
signal transition is recognized if two subsequent samples of the input signal represent
different levels. Therefore, a minimum of two basic clock periods are required for the
sampling of an external input signal. Thus, the maximum frequency of an input signal
must not be higher than half the basic clock.
Table 14-9 summarizes the resulting requirements for external GPT1 input signals.
Table 14-9GPT1 External Input Signal Limits
System Clock = 10 MHz
Max. Input
Frequency
Min. Level
Hold Time
1.25 MHz400 ns
Input
Frequ.
Factor
f
/801
GPT
GPT1
Divider
BPS1
B
Input
Phase
Duration
4 ×t
GPT
System Clock = 40 MHz
Max. Input
Frequency
Min. Level
Hold Time
5.0 MHz100 ns
625.0 kHz800 ns
312.5 kHz1.6
156.25 kHz3.2
µsf
µsf
f
GPT
GPT
GPT
/1600
/3211
/6410
B
B
B
8 ×t
16 ×t
32 ×t
GPT
GPT
GPT
2.5 MHz200 ns
1.25 MHz400 ns
625.0 kHz800 ns
These limitations are valid for all external input signals to GPT1, including the external
count signals in counter mode and incremental interface mode, the gate input signals in
gated timer mode, and the external direction signals.
When a timer overflows from FFFFH to 0000H (when counting up), or when it underflows
from 0000
T4IR) in register TxIC will be set. This will cause an interrupt to the respective timer
interrupt vector (T2INT, T3INT or T4INT) or trigger a PEC service, if the respective
interrupt enable bit (T2IE, T3IE or T4IE in register TxIC) is set. There is an interrupt
control register for each of the three timers.
GPT12E_T2IC
Timer 2 Intr. Ctrl. Reg.SFR (FF60
1514131211109876543210
-------GPXT2IRT2IEILVLGLVL
-------rwrwhrwrwrw
GPT12E_T3IC
Timer 3 Intr. Ctrl. Reg.SFR (FF62
to FFFFH (when counting down), its interrupt request flag (T2IR, T3IR or
H
/B0H)Reset Value: - - 00
H
/B1H)Reset Value: - - 00
H
H
H
1514131211109876543210
-------GPXT3IRT3IEILVLGLVL
-------rwrwhrwrwrw
GPT12E_T4IC
Timer 4 Intr. Ctrl. Reg.SFR (FF64
1514131211109876543210
-------GPXT4IRT4IEILVLGLVL
-------rwrwhrwrwrw
/B2H)Reset Value: - - 00
H
Note: Please refer to the general Interrupt Control Register description for an
explanation of the control fields.
H
User’s Manual14-30V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2Timer Block GPT2
From a programmer’s point of view, the GPT2 block is represented by a set of SFRs as
summarized below. Those portions of port and direction registers which are used for
alternate functions by the GPT2 block are shaded.
Data RegistersControl RegistersPort Registers
T5T5CONT5IC
T6T6CONT6IC
CAPRELCRIC
SYSCON3
TxGPT2 Timer x Register
CAPRELGPT2 Capture/Reload Register
TxCONGPT2 Timer x Control Register
TxICGPT2 Timer x Interrupt Ctrl. Reg.
SYSCON3System Ctrl. Reg. 3 (Per. M gmt.)
Interrupt Control
ODP3
DP3
P3
ALTSEL0P3
P5
P5DIDIS
ODP3Port 3 Open Drain Control Register
DP3Port 3 Direction Control Register
P3Port 3 Data Register
ALTSEL0P3 Port 3 Alternate Output Select Reg.
P5Port 5 Data Register
P5DIDISPort 5 Digital Input Disable Reg.
E
E
mc_gpt0102_registers.vsd
Figure 14-19 SFRs Associated with Timer Block GPT2
Both timers of block GPT2 (T5, T6) can run in one of 3 basic modes: Timer Mode, Gated
Timer Mode, or Counter Mode. All timers can count up or down. Each timer of GPT2 is
controlled by a separate control register TxCON.
Each timer has an input pin TxIN (alternate pin function) associated with it, which serves
as the gate control in gated timer mode, or as the count input in counter mode. The count
direction (up/down) may be programmed via software. An overflow/underflow of core
timer T6 is indicated by the Output Toggle Latch T6OTL, whose state may be output on
the associated pin T6OUT (alternate pin function). The auxiliary timer T5 may
additionally be concatenated with the core timer T6 (through T6OTL).
The Capture/Reload register CAPREL can be used to capture the contents of timer T5,
or to reload timer T6. A special mode facilitates the use of register CAPREL for both
functions at the same time. This mode allows frequency multiplication. The capture
function is triggered by the input pin CAPIN, or by GPT1 timer’s T3 input lines T3IN and
T3EUD. The reload function is triggered by an overflow or underflow of timer T6.
Overflows/underflows of timer T6 may also clock the timers of the CAPCOM units.
The current contents of each timer can be read or modified by the CPU by accessing the
corresponding timer count registers T5 or T6, located in the non-bitaddressable SFR
User’s Manual14-31V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
space (see Section 14.2.7). When any of the timer registers is written to by the CPU in
the state immediately preceding a timer increment, decrement, reload, or capture
operation, the CPU write operation has priority in order to guarantee correct results.
The interrupts of GPT2 are controlled through the Interrupt Control Registers TxIC.
These registers are not part of the GPT2 block. The input and output lines of GPT2 are
connected to pins of Ports P3 and P5. The control registers for the port functions are
located in the respective port modules.
Note: The timing requirements for external input signals can be found in Section 14.2.6,
Section 14.3 summarizes the module interface signals, including pins.
T6CON.BPS2
GPT
T5I N
2n: 1f
T5
Mode
Control
Basic clock
GPT2 Ti mer T5
U/D
Cl ear
Interrupt
Request
(T5IR)
CAPIN
T3I N/
T3EUD
T6I N
CAPREL
Mode
Control
T6
Mode
Control
Capture
GPT2 CAPREL
Rel oa d
Clear
GPT2 Ti mer T6
U/D
Toggle F F
T6O TL
Interrupt
Request
(CRIR)
Interrupt
Request
(T6IR)
T6O UT
T6O UF
mc _gpt0103_bldiax 1.vsd
Figure 14-20 GPT2 Block Diagram
User’s Manual14-32V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2.1GPT2 Core Timer T6 Control
The current contents of the core timer T6 are reflected by its count register T6. This
register can also be written to by the CPU, for example, to set the initial start value.
The core timer T6 is configured and controlled via its bitaddressable control register
T6CON.
0Reload from register CAPREL Disabled
1Reload from register CAPREL Enabled
/A4H)Reset Value: 0000
H
T6
T6RT6MT6I
UD
H
T6CLR14rwTimer T6 Clear Enable Bit
0Timer T6 is not cleared on a capture event
1Timer T6 is cleared on a capture event
BPS2[12:11] rwGPT2 Block Prescaler Control
Selects the basic clock for block GPT2
(see also Section 14.2.6)
00
01
10
11
f
GPT
f
GPT
f
GPT
f
GPT
/4
/2
/16
/8
T6OTL10rwhTimer T6 Overflow Toggle Latch
Toggles on each overflow/underflow of T6. Can be
set or reset by software (see separate description)
T6OE9rwOverflow/Underflow Output Enable
0Alternate Output Function Disabled
1State of T6 toggle latch is output on pin T6OUT
T6UD7rwTimer T6 Up/Down Control
0Timer T6 counts up
1Timer T6 counts down
User’s Manual14-33V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
FieldBitsTypDescription
T6R6rwTimer T6 Run Bit
0Timer T6 stops
1Timer T6 runs
T6M[5:3]rwTimer T6 Mode Control (Basic Operating Mode)
000Timer Mode
001Counter Mode
010Gated Timer Mode with gate active low
011Gated Timer Mode with gate active high
100Reserved. Do not use this combination.
101Reserved. Do not use this combination.
110Reserved. Do not use this combination.
111Reserved. Do not use this combination.
T6I[2:0]rwTimer T6 Input Parameter Selection
Depends on the operating mode, see respective
sections for encoding:
Table 14-15 for Timer Mode and Gated Timer Mode
Table 14-11 for Counter Mode
Timer T6 Run Control
The core timer T6 can be started or stopped by software through bit T6R (timer T6 run
bit). This bit is relevant in all operating modes of T6. Setting bit T6R will start the timer,
clearing bit T6R stops the timer.
In gated timer mode, the timer will only run if T6R = 1 and the gate is active (high or low,
as programmed).
Note: When bit T5RC in timer control register T5CON is set, bit T6R will also control
(start and stop) the Auxiliary Timer T5.
Count Direction Control
The count direction of the GPT2 timers (core timer and auxiliary timer) can be controlled
by software. The count direction can be altered by setting or clearing bit TxUD. The count
direction can be changed regardless of whether or not the timer is running.
User’s Manual14-34V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timer 6 Output Toggle Latch
The overflow/underflow signal of timer T6 is connected to a block named ‘Toggle Latch’,
shown in the timer mode diagrams. Figure 14-21 illustrates the details of this block. An
overflow or underflow of T6 will clock two latches: The first latch represents bit T6OTL in
control register T6CON. The second latch is an internal latch toggled by T6OTL’s output.
Both latch outputs are connected to the input control block of the auxiliary timer T5. The
output level of the shadow latch will match the output level of T6OTL, but is delayed by
one clock cycle. When the T6OTL value changes, this will result in a temporarily different
output level from T6OTL and the shadow latch, which can trigger the selected count
event in T5.
When software writes to T6OTL, both latches are set or cleared simultaneously. In this
case, both signals to the auxiliary timers carry the same level and no edge will be
detected. Bit T6OE (overflow/underflow output enable) in register T6CON enables the
state of T6OTL to be monitored via an external pin T6OUT. When T6OTL is linked to an
external port pin (must be configured as output), T6OUT can be used to control external
HW. If T6OE = 1, pin T6OUT outputs the state of T6OTL. If T6OE = 0, pin T6OUT
outputs a high level (while it selects the timer output signal).
As can be seen from Figure 14-21, when latch T6OTL is modified by software to
determine the state of the output line, also the internal shadow latch is set or cleared
accordingly. Therefore, no trigger condition is detected by T5 in this case.
1
0
TxOE
MUX
To Port Logic
To Aux. Timer
Input Logic
mc_gpt0106_otl.vsd
TxOUT
Core Timer
Overflow/
Underflow
Set/Clear (SW )
TxOTL
Toggle Latch Logic
1
Shadow
Latch
Figure 14-21 Block Diagram of the Toggle Latch Logic of Core Timer T6
Note: T6 is also used to clock the timers in the CAPCOM units. For this purpose, there
is a direct internal connection between the T6 overflow/underflow line and the
CAPCOM timers (signal T6OUF).
User’s Manual14-35V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2.2GPT2 Core Timer T6 Operating Modes
Timer 6 in Timer Mode
Timer mode for the core timer T6 is selected by setting bitfield T6M in register T6CON
to 000
programmable prescalers controlled by bitfields BPS2 and T6I in register T6CON.
Please see Section 14.2.6 for details on the input clock options.
. In this mode, T6 is clocked with the module’s input clock f
B
GPT
f
PrescalerCore Timer T6Toggle Latch
BPS2T6I
T6
Count
T6R
divided by two
GPT
T6IRQ
T6OUT
to T5/
CAPREL
T6OUF
T6UD
Up/Down
Figure 14-22 Block Diagram of Core Timer T6 in Timer Mode
MCB05403
User’s Manual14-36V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Gated Timer Mode
Gated timer mode for the core timer T6 is selected by setting bitfield T6M in register
T6CON to 010
or 011B. Bit T6M.0 (T6CON.3) selects the active level of the gate input.
B
The same options for the input frequency are available in gated timer mode as in timer
mode (see Section 14.2.6). However, the input clock to the timer in this mode is gated
by the external input pin T6IN (Timer T6 External Input).
To enable this operation, the associated pin T6IN must be configured as input (the
corresponding direction control bit must contain 0).
T6IRQ
f
GPT
T6IN
Prescaler
BPS2T6I
Gate
Ctrl.
T6
T6R
Count
Core Timer T6Toggle Latch
Clear
T6OUT
to T5,
CAPREL
T6OUF
T6UD
Up/Down
MCB05404
Figure 14-23 Block Diagram of Core Timer T6 in Gated Timer Mode
If T6M = 010
stops the timer. If T6M = 011
, the timer is enabled when T6IN shows a low level. A high level at this line
B
, line T6IN must have a high level in order to enable the
B
timer. Additionally, the timer can be turned on or off by software using bit T6R. The timer
will only run if T6R is 1 and the gate is active. It will stop if either T6R is 0 or the gate is
inactive.
Note: A transition of the gate signal at pin T6IN does not cause an interrupt request.
User’s Manual14-37V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Counter Mode
Counter mode for the core timer T6 is selected by setting bitfield T6M in register T6CON
to 001
. In counter mode, timer T6 is clocked by a transition at the external input pin
B
T6IN. The event causing an increment or decrement of the timer can be a positive, a
negative, or both a positive and a negative transition at this line. Bitfield T6I in control
register T6CON selects the triggering transition (see Table 14-11).
T6IRQ
Edge
T6IN
Select
T6I
T6R
Count
T6UD
Core Timer T6Toggle Latch
Clear
Up/Down
T6OUT
to T5,
CAPREL
T6OUF
MCB05405
Figure 14-24 Block Diagram of Core Timer T6 in Counter Mode
0 0 0None. Counter T6 is disabled
0 0 1Positive transition (rising edge) on T6IN
0 1 0Negative transition (falling edge) on T6IN
0 1 1Any transition (rising or falling edge) on T6IN
1 X XReserved. Do not use this combination
For counter mode operation, pin T6IN must be configured as input (the respective
direction control bit DPx.y must be 0). The maximum input frequency allowed in counter
mode depends on the selected prescaler value. To ensure that a transition of the count
input signal applied to T6IN is recognized correctly, its level must be held high or low for
a minimum number of module clock cycles before it changes. This information can be
found in Section 14.2.6.
User’s Manual14-38V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2.3GPT2 Auxiliary Timer T5 Control
Auxiliary timer T5 can be configured for timer mode, gated timer mode, or counter mode
with the same options for the timer frequencies and the count signal as the core timer
T6. In addition to these 3 counting modes, the auxiliary timer can be concatenated with
the core timer. The contents of T5 may be captured to register CAPREL upon an external
or an internal trigger. The start/stop function of the auxiliary timers can be remotely
controlled by the T6 run control bit. Several timers may thus be controlled synchronously.
The current contents of the auxiliary timer are reflected by its count register T5. This
register can also be written to by the CPU, for example, to set the initial start value.
The individual configurations for timer T5 are determined by its bitaddressable control
register T5CON. Some bits in this register also control the function of the CAPREL
register. Note that functions which are present in all timers of block GPT2 are controlled
in the same bit positions and in the same manner in each of the specific control registers.
Note: The auxiliary timer has no output toggle latch and no alternate output function.
0T5 is just captured without any correction
1T5 is decremented by 1 before being captured
CT310rwTimer T3 Capture Trigger Enable
0Capture trigger from input line CAPIN
1Capture trigger from T3 input lines T3IN and/or
T3EUD
T5RC9rwTimer T5 Remote Control
0Timer T5 is controlled by its own run bit T5R
1Timer T5 is controlled by the run bit T6R of
core timer 6, not by bit T5R
T5UD7rwTimer T5 Up/Down Control
0Timer T5 counts up
1Timer T5 counts down
T5R6rwTimer T5 Run Bit
0Timer T5 stops
1Timer T5 runs
Note: This bit only controls timer T5 if bit T5RC = 0.
T5M[5:3]rwTimer T5 Mode Control (Basic Operating Mode)
000Timer Mode
001Counter Mode
010Gated Timer Mode with gate active low
011Gated Timer Mode with gate active high
1XXReserved. Do not use this combination
T5I[2:0]rwTimer T5 Input Parameter Selection
Depends on the operating mode, see respective
sections for encoding:
Table 14-15 for Timer Mode and Gated Timer Mode
Table 14-11 for Counter Mode
Timer T5 Run Control
The auxiliary timer T5 can be started or stopped by software in two different ways:
•Through the associated timer run bit (T5R). In this case it is required that the
respective control bit T5RC = 0.
•Through the core timer’s run bit (T6R). In this case the respective remote control bit
must be set (T5RC = 1).
The selected run bit is relevant in all operating modes of T5. Setting the bit will start the
timer, clearing the bit stops the timer.
User’s Manual14-40V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
In gated timer mode, the timer will only run if the selected run bit is set and the gate is
active (high or low, as programmed).
Note: If remote control is selected T6R will start/stop timer T6 and the auxiliary timer T5
synchronously.
14.2.4GPT2 Auxiliary Timer T5 Operating Modes
The operation of the auxiliary timer in the basic operating modes is almost identical with
the core timer’s operation, with very few exceptions. Additionally, some combined
operating modes can be selected.
Timer T5 in Timer Mode
Timer Mode for the auxiliary timer T5 is selected by setting its bitfield T5M in register
T5CON to 000
GPT
B
.
Prescaler
f
T5
Count
Auxiliary
Timer T5
T5IRQ
BPS2T5I
T5R
T6R
0
1
MUX
T5RC
T5UD
Clear
Up/Down
MCB05406
Figure 14-25 Block Diagram of Auxiliary Timer T5 in Timer Mode
User’s Manual14-41V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timer T5 in Gated Timer Mode
Gated timer mode for the auxiliary timer T5 is selected by setting bitfield T5M in register
T5CON to 010
or 011B. Bit T5M.0 (T5CON.3) selects the active level of the gate input.
B
Note: A transition of the gate signal at line T5INdoes not cause an interrupt request.
f
0
1
T5
MUX
T5RC
Count
Auxiliary
Timer T5
Clear
T5IRQ
GPT
T5IN
Prescaler
BPS2T5I
Gate
Ctrl.
T5R
T6R
T5UD
Up/Down
MCB05407
Figure 14-26 Block Diagram of Auxiliary Timer T5 in Gated Timer Mode
Note: There is no output toggle latch for T5.
Start/stop of the auxiliary timer can be controlled locally or remotely.
Timer T5 in Counter Mode
Counter mode for auxiliary timer T5 is selected by setting bitfield T5M in register T5CON
to 001
. In counter mode, the auxiliary timer can be clocked either by a transition at its
B
external input line T5IN, or by a transition of timer T6’s toggle latch T6OTL. The event
causing an increment or decrement of a timer can be a positive, a negative, or both a
positive and a negative transition at either the respective input pin or at the toggle latch.
Bitfield T5I in control register T5CON selects the triggering transition (see Table 14-12).
User’s Manual14-42V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
T5R
T6R
Edge
Select
T5I
0
1
MUX
T5RC
T5IN
T6
Toggle
Latch
0
MUX
1
T5I.2
The General Purpose Timer Units
Count
T5UD
Auxiliary
Timer T5
Clear
Up/Down
T5IRQ
MCB05408
Figure 14-27 Block Diagram of Auxiliary Timer T5 in Counter Mode
X 0 0None. Counter T5 is disabled
0 0 1Positive transition (rising edge) on T5IN
0 1 0Negative transition (falling edge) on T5IN
0 1 1Any transition (rising or falling edge) on T5IN
1 0 1Positive transition (rising edge) of T6 toggle latch T6OTL
1 1 0Negative transition (falling edge) of T6 toggle latch T6OTL
1 1 1Any transition (rising or falling edge) of T6 toggle latch T6OTL
Note: Only state transitions of T6OTL which are caused by the overflows/underflows of
T6 will trigger the counter function of T5. Modifications of T6OTL via software will
NOT trigger the counter function of T5.
For counter operation, pin T5IN must be configured as input (the respective direction
control bit DPx.y must be 0). The maximum input frequency allowed in counter mode
depends on the selected prescaler value. To ensure that a transition of the count input
signal applied to T5IN is recognized correctly, its level must be held high or low for a
minimum number of module clock cycles before it changes. This information can be
found in Section 14.2.6.
User’s Manual14-43V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Timer Concatenation
Using the toggle bit T6OTL as a clock source for the auxiliary timer in counter mode
concatenates the core timer T6 with the auxiliary timer T5. This concatenation forms
either a 32-bit or a 33-bit timer/counter, depending on which transition of T6OTL is
selected to clock the auxiliary timer.
•32-bit Timer/Counter: If both a positive and a negative transition of T6OTL are used
to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the
core timer T6. Thus, the two timers form a 32-bit timer.
•33-bit Timer/Counter: If either a positive or a negative transition of T6OTL is
selected to clock the auxiliary timer, this timer is clocked on every second
overflow/underflow of the core timer T6. This configuration forms a 33-bit timer (16-bit
core timer + T6OTL + 16-bit auxiliary timer).
As long as bit T6OTL is not modified by software, it represents the state of the internal
toggle latch, and can be regarded as part of the 33-bit timer.
The count directions of the two concatenated timers are not required to be the same.
This offers a wide variety of different configurations.
T6, which represents the low-order part of the concatenated timer, can operate in timer
mode, gated timer mode or counter mode in this case.
T6IRQ
GPT
T6IN
T5IN
Operating
Mode
Control
BPS2T6I
0
MUX
1
T5I.2
T6R
Edge
Select
T5I
Count
T5R
T6R
Core Timer T6
Clear
0
MUX
1
T5RC
Up/Down
Count
Toggle LatchT6OUT
Auxiliary
Timer T5
ClearUp/Down
T5IRQ
MCA05409
Figure 14-28 Concatenation of Core Timer T6 and Auxiliary Timer T5
User’s Manual14-44V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2.5GPT2 Register CAPREL Operating Modes
The Capture/Reload register CAPREL can be used to capture the contents of timer T5,
or to reload timer T6. A special mode facilitates the use of register CAPREL for both
functions at the same time. This mode allows frequency multiplication. The capture
function is triggered by the input pin CAPIN, or by GPT1 timer’s T3 input lines T3IN and
T3EUD. The reload function is triggered by an overflow or underflow of timer T6.
In addition to the capture function, the capture trigger signal can also be used to clear
the contents of timers T5 and T6 individually.
The functions of register CAPREL are controlled via several bit(field)s in the timer control
registers T5CON and T6CON.
GPT2 Capture/Reload Register CAPREL in Capture Mode
Capture mode for register CAPREL is selected by setting bit T5SC in control register
T5CON (set bitfield CI in register T5CON to a non-zero value to select a trigger signal).
In capture mode, the contents of the auxiliary timer T5 are latched into register CAPREL
in response to a signal transition at the selected external input pin(s). Bit CT3 selects the
external input line CAPIN or the input lines T3IN and/or T3EUD of GPT1 timer T3 as the
source for a capture trigger. Either a positive, a negative, or both a positive and a
negative transition at line CAPIN can be selected to trigger the capture function, or
transitions on input T3IN or input T3EUD or both inputs, T3IN and T3EUD. The active
edge is controlled by bitfield CI in register T5CON. Table 14-13 summarizes these
options.
X0 0None. Capture Mode is disabled.
00 1Positive transition (rising edge) on CAPIN.
01 0Negative transition (falling edge) on CAPIN.
01 1Any transition (rising or falling edge) on CAPIN.
10 1Any transition (rising or falling edge) on T3IN.
11 0Any transition (rising or falling edge) on T3EUD.
11 1Any transition (rising or falling edge) on T3IN or T3EUD.
User’s Manual14-45V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Count
Clock
Clear
Edge
CAPIN
T3IN
T3EUD
Select
Signal
Select
CI
0
MUX
1
CT3
T5CLR
Capture
T5SC
The General Purpose Timer Units
Auxiliary
Timer T5
Up/Down
Capture
Correction
CAPREL
Register
T5CC
T5IRQ
CRIRQ
Clear
T6
T6CLR
MCA05410
Figure 14-29 GPT2 Register CAPREL in Capture Mode
When a selected trigger is detected, the contents of the auxiliary timer T5 are latched
into register CAPREL and the interrupt request line CRIRQ is activated. The same event
can optionally clear timer T5 and/or timer T6. This option is enabled by bit T5CLR in
register T5CON and bit T6CLR in register T6CON, respectively. If TxCLR = 0 the
contents of timer Tx is not affected by a capture. If TxCLR = 1 timer Tx is cleared after
the current timer T5 value has been latched into register CAPREL.
Note: Bit T5SC only controls whether or not a capture is performed. If T5SC is cleared
the external input pin(s) can still be used to clear timer T5 and/or T6, or as external
interrupt input(s). This interrupt is controlled by the CAPREL interrupt control
register CRIC.
When capture triggers T3IN or T3EUD are enabled (CT3 = 1), register CAPREL captures
the contents of T5 upon transitions of the selected input(s). These values can be used
to measure T3’s input signals. This is useful, for example, when T3 operates in
User’s Manual14-46V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
incremental interface mode, in order to derive dynamic information (speed, acceleration)
from the input signals.
For capture mode operation, the selected pins CAPIN, T3IN, or T3EUD must be
configured as input. To ensure that a transition of a trigger input signal applied to one of
these inputs is recognized correctly, its level must be held high or low for a minimum
number of module clock cycles, detailed in Section 14.2.6.
GPT2 Capture/Reload Register CAPREL in Reload Mode
Reload mode for register CAPREL is selected by setting bit T6SR in control register
T6CON. In reload mode, the core timer T6 is reloaded with the contents of register
CAPREL, triggered by an overflow or underflow of T6. This will not activate the interrupt
request line CRIRQ associated with the CAPREL register. However, interrupt request
line T6IRQ will be activated, indicating the overflow/underflow of T6.
CAPREL
Register
Reload
Count
Clock
Core Timer T6
Up/Down
Figure 14-30 GPT2 Register CAPREL in Reload Mode
T6SR
T6IRQ
Toggle LatchT6OUT
T6OUF
to T5
MCA05411
User’s Manual14-47V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
GPT2 Capture/Reload Register CAPREL in Capture-And-Reload Mode
Since the reload function and the capture function of register CAPREL can be enabled
individually by bits T5SC and T6SR, the two functions can be enabled simultaneously by
setting both bits. This feature can be used to generate an output frequency that is a
multiple of the input frequency.
Count
Clock
CAPIN
T3IN
T3EUD
Edge
Select
Edge
Select
Clear
T5CLR
0
MUX
1
CT3
T5SC
Capture
Auxiliary
Timer T5
Up/Down
CAPREL
Register
Capture
Correction
T5IRQ
T5CC
Count
Clock
CI
T6CLR
Reload
Clear
Core Timer T6
T6SR
Toggle LatchT6OUT
Up/Down
CRIRQ
T6IRQ
T6OUF
to T5
MCA05412
Figure 14-31 GPT2 Register CAPREL in Capture-And-Reload Mode
This combined mode can be used to detect consecutive external events which may
occur aperiodically, but where a finer resolution, that means, more ‘ticks’ within the time
between two external events is required.
For this purpose, the time between the external events is measured using timer T5 and
the CAPREL register. Timer T5 runs in timer mode counting up with a frequency of e.g.
f
/32. The external events are applied to pin CAPIN. When an external event occurs,
GPT
User’s Manual14-48V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
the contents of timer T5 are latched into register CAPREL and timer T5 is cleared
(T5CLR = 1). Thus, register CAPREL always contains the correct time between two
events, measured in timer T5 increments. Timer T6, which runs in timer mode counting
down with a frequency of e.g.
f
/4, uses the value in register CAPREL to perform a
GPT
reload on underflow. This means, the value in register CAPREL represents the time
between two underflows of timer T6, now measured in timer T6 increments. Since (in this
example) timer T6 runs 8 times faster than timer T5, it will underflow 8 times within the
time between two external events. Thus, the underflow signal of timer T6 generates
8 ‘ticks’. Upon each underflow, the interrupt request line T6IRQ will be activated and bit
T6OTL will be toggled. The state of T6OTL may be output on pin T6OUT. This signal has
8 times more transitions than the signal which is applied to pin CAPIN.
Note: The underflow signal of Timer T6 can furthermore be used to clock one or more of
the timers of the CAPCOM units, which gives the user the possibility to set
compare events based on a finer resolution than that of the external events. This
connection is accomplished via signal T6OUF.
Capture Correction
A certain deviation of the output frequency is generated by the fact that timer T5 will
count actual time units (e.g. T5 running at 1 MHz will count up to the value 64
/100D for
H
a 10 kHz input signal), while T6OTL will only toggle upon an underflow of T6 (i.e. the
transition from 0000
from 64
, so the underflow would occur after 101 timing ticks of T6. The actual output
H
to FFFFH). In the above mentioned example, T6 would count down
H
frequency then is 79.2 kHz, instead of the expected 80 kHz.
This deviation can be compensated for by activating the Capture Correction (T5CC = 1).
If capture correction is active, the contents of T5 are decremented by 1 before being
captured. The described deviation is eliminated (in the example, T5 would count up to
the value 64
/99D, T6 would count exactly 100 ticks, and the output frequency is 80 kHz).
63
H
/100D, but the CAPREL register will capture the decremented value
H
User’s Manual14-49V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
f
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.2.6GPT2 Clock Signal Control
All actions within the timer block GPT2 are triggered by transitions of its basic clock. This
basic clock is derived from the system clock by a basic block prescaler, controlled by
bitfield BPS2 in register T6CON (see Figure 14-20). The count clock can be generated
in two different ways:
•Internal count clock, derived from GPT2’s basic clock via a programmable
prescaler, is used for (gated) timer mode.
•External count clock, derived from the timer’s input pin(s), is used for counter mode.
For both ways, the basic clock determines the maximum count frequency and the timer’s
resolution:
Table 14-14Basic Clock Selection for Block GPT2
Block Prescaler
1)
Prescaling Factor
for GPT2: F(BPS2)
BPS2 = 01
F(BPS2)
= 2
B
BPS2 = 00
F(BPS2)
= 4
2)
B
BPS2 = 11
F(BPS2)
= 8
B
BPS2 = 10
F(BPS2)
= 16
B
Maximum External
/4f
GPT
/8f
GPT
/16f
GPT
GPT
/32
f
Count Frequency
Input Signal
2
× t
GPT
4 ×t
GPT
8 ×t
GPT
16 ×t
GPT
Stable Time
1) Please note the non-linear encoding of bitfield BPS2.
2) Default after reset.
Internal Count Clock Generation
In timer mode and gated timer mode, the count clock for each GPT2 timer is derived from
the GPT2 basic clock by a programmable prescaler, controlled by bitfield TxI in the
respective timer’s control register TxCON.
The count frequency
f
for a timer Tx and its resolution rTx are scaled linearly with lower
Tx
clock frequencies, as can be seen from the following formula:
f
------------ ------------------------ ---------=r
Tx
GPT
F BPS2()2
µs[]
<Txl>
×
Tx
F BPS2()2
------------ ------------------------ ---------=
f
GPT
<Txl>
×
MHz[]
(14.2)
The effective count frequency depends on the common module clock prescaler factor
<TxI>
F(BPS2) as well as on the individual input prescaler factor 2
. Table 14-15
summarizes the resulting overall divider factors for a GPT2 timer that result from these
cascaded prescalers.
User’s Manual14-50V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
Table 14-15GPT2 Overall Prescaler Factors for Internal Count Clock
Individual
µs104.9 ms162.5 MHz400 ns26.21 ms
µs209.7 ms321.25 MHz800 ns52.43 ms
µs419.4 ms64625.0 kHz1.6 µs104.9 ms
µs838.9 ms128312.5 kHz3.2 µs209.7 ms
µs1.678 s256156.25 kHz6.4 µs419.4 ms
µs3.355 s51278.125 kHz12.8 µs838.9 ms
µs6.711 s102439.06 kHz25.6 µs1.678 s
µs13.42 s204819.53 kHz51.2 µs3.355 s
220.0 MHz50 ns3.28 ms
410.0 MHz100 ns6.55 ms
85.0 MHz200 ns13.11 ms
User’s Manual14-51V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
External Count Clock Input
The external input signals of the GPT2 block are sampled with the GPT2 basic clock (see
Figure 14-20). To ensure that a signal is recognized correctly, its current level (high or
low) must be held active for at least one complete sampling period, before changing. A
signal transition is recognized if two subsequent samples of the input signal represent
different levels. Therefore, a minimum of two basic clock periods are required for the
sampling of an external input signal. Thus, the maximum frequency of an input signal
must not be higher than half the basic clock.
Table 14-17 summarizes the resulting requirements for external GPT2 input signals.
Table 14-17GPT2 External Input Signal Limits
System Clock = 10 MHz
Max. Input
Frequency
Min. Level
Hold Time
2.5 MHz200 ns
Input
Frequ.
Factor
f
/401
GPT
GPT2
Divider
BPS1
B
Input
Phase
Duration
2 ×t
GPT
System Clock = 40 MHz
Max. Input
Frequency
Min. Level
Hold Time
10.0 MHz50 ns
1.25 MHz400 ns
625.0 kHz800 ns
312.5 kHz1.6
µsf
f
/800
GPT
f
/1611
GPT
/3210
GPT
B
B
B
4 ×t
8 ×t
16 ×t
GPT
GPT
GPT
5.0 MHz100 ns
2.5 MHz200 ns
1.25 MHz400 ns
These limitations are valid for all external input signals to GPT2, including the external
count signals in counter mode and the gate input signals in gated timer mode.
14.2.8Interrupt Control for GPT2 Timers and CAPREL
When a timer overflows from FFFFH to 0000H (when counting up), or when it underflows
from 0000
register TxIC will be set. Whenever a transition according to the selection in bit field CI
is detected at pin CAPIN, interrupt request flag CRIR in register CRIC is set. Setting any
request flag will cause an interrupt to the respective timer or CAPREL interrupt vector
(T5INT, T6INT or CRINT) or trigger a PEC service, if the respective interrupt enable bit
(T5IE or T6IE in register TxIC, CRIE in register CRIC) is set. There is an interrupt control
register for each of the two timers and for the CAPREL register.
GPT12E_T5IC
Timer 5 Intr. Ctrl. Reg.SFR (FF66
1514131211109876543210
-------GPXT5IRT5IEILVLGLVL
-------rwrwhrwrwrw
to FFFFH (when counting down), its interrupt request flag (T5IR or T6IR) in
H
/B3H)Reset Value: - - 00
H
H
GPT12E_T6IC
Timer 6 Intr. Ctrl. Reg.SFR (FF68
1514131211109876543210
-------GPXT6IRT6IEILVLGLVL
-------rwrwhrwrwrw
/B4H)Reset Value: - - 00
H
GPT12E_CRIC
CAPREL Intr. Ctrl. Reg.SFR (FF6A
1514131211109876543210
-------GPXCRIRCRIEILVLGLVL
-------rwrwhrwrwrw
/B5H)Reset Value: - - 00
H
Note: Please refer to the general Interrupt Control Register description for an
explanation of the control fields.
H
H
User’s Manual14-54V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The General Purpose Timer Units
14.3Interfaces of the GPT Module
Besides the described intra-module connections, the timer unit blocks GPT1 and GPT2
are connected to their environment in two basic ways (see Figure 14-32):
•Internal connections interface the timers with on-chip resources such as clock
generation unit, interrupt controller, or other timers.
•External connections interface the timers with external resources via port pins.
f
System
Control
Unit
Interrupt
Control
Unit
GPT
GPTDIS
T2IRQ
T3IRQ
T4IRQ
T5IRQ
T6IRQ
CRIRQ
General
Purpose
Timer
Units
T2EUD
T4EUD
T2IN
T3IN
T4IN
T3EUD
T3OUT
T5IN
T6IN
P5.15
P5.14
P3.7
P3.6
P3.5
P3.4
P3.3
P5.13
P5.12
Port Logic for P3 and P5
CAPCOM
Units
T6OUF
CAPIN
T6OUT
P3.2
P3.1
mc_gpt0104_modinterfacex1.vsd
Figure 14-32 GPT Module Interfaces
Port pins to be used for timer input signals must be switched to input, the respective
direction control bits must be cleared (DPx.y = 0).
Port pins to be used for timer output signals must be switched to output, the respective
direction control bits must be set (DPx.y = 1). The alternate timer output signal must be
selected for these pins via the respective alternate select registers (see Chapter 7).
Interrupt nodes to be used for timer interrupt requests must be enabled and programmed
to a specific interrupt level.
User’s Manual14-55V2.2, 2004-01
GPT_X1, V2.0
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15Real Time Clock
The Real Time Clock (RTC) module of the XC161 basically consists of a chain of
prescalers and timers. Its count clock is derived from the auxiliary oscillator or from the
prescaled main oscillator. The RTC serves various purposes:
•48-bit timer for long term measurements
•System clock to determine the current time and date(the RTC’s structure supports the direct representation of time and date)
•Cyclic time based interrupt (can be generated by any timer of the chain)
A number of programming options as well as interrupt request signals adjust the
operation of the RTC to the application’s requirements. The RTC can continue its
operation while the XC161 is in a power-saving mode, such that real time date and time
information is provided.
Control RegistersData RegistersCounter RegistersInterrupt Control
RTC_CONRTC_T14RELRTC_T14RTC_ISNC
SYSCON0
SYSCON3
RTC_CONReal Time Clock Control Register
SYSCON0General System Control Register
SYSCON3Power Management Control Reg.
RTC_ISNCInterrupt Subnode Control Register
RTC_ICRTC Interrupt Control Register
The RTC module consists of a chain of 3 divider blocks:
•a selectable 8:1 divider (on - off)
•the reloadable 16-bit timer T14
•the 32-bit RTC timer block (accessible via RTC_RTCH and RTC_RTCL), made of:
– the reloadable 10-bit timer CNT0
– the reloadable 6-bit timer CNT1
– the reloadable 6-bit timer CNT2
– the reloadable 10-bit timer CNT3
All timers count upwards. Each of the five timers can generate an interrupt request. All
requests are combined to a common node request.
Note: The RTC registers are not affected by a system reset in order to maintain the
correct system time even when intermediate resets are executed.
User’s Manual15-1V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15.1Defining the RTC Time Base
The timer chain of the RTC is clocked with the count clock signal f
from the auxiliary oscillator or from the prescaled main oscillator (see Figure 15-2 and
Figure 15-3). Optionally prescaled by a factor of 8, this is the basic RTC clock.
Depending on the operating mode, timer T14 may provide the count increments used by
the application and thus determine the input frequency of the RTC timer, that is, the RTC
time base (see also Table 15-3).
The RTC is also supplied with the system clock
f
of the XC161. This clock signal is
SYS
used to control the RTC’s logic blocks and its bus interface. To synchronize properly to
the count clock, the system clock must run at least four times faster than the count clock,
this means
Aux.
OSC
f
SYS
≥ 4 ×f
f
OSCa
CNT
>1
.
REFCLKRUN
f
RTCa
f
RTCm
MUX
f
RTC
8:1
which is derived
RTC
1
0
MUX
f
CNT
RTC
Count
Clock
PRE
Main
OSC
f
OSCm
32:1
Clock
Generation
Unit
f
SYS
Async Mode
Sync Mode
1
MUX
0
RTCCM
SYSCON0.14
RTC
Module
Clock
MCB05413
Figure 15-2RTC Clock Supply Block Diagram
For an example, Table 15-1 lists the interrupt period range and the T14 reload values
(for a time base of 1 s and 1 ms):
Table 15-1RTC Time Base Examples
Oscillator
Frequency
32.768 kHz30.52
T14 Intr. PeriodReload Value AReload Value B
Min.Max.T14RELBaseT14RELBase
µs16.0 s8000
/F000H1.000 sFFDFH/
H
FFFC
1.007 ms/
H
0.977 ms
Note: Select one value from the reload value pairs, depending if the 8:1 prescaler is
disabled/enabled.
User’s Manual15-2V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
Asynchronous Operation
When the system clock frequency becomes lower than 4
× f
proper synchronization
CNT
is not possible and count events may be missed. When the XC161 enters e.g. sleep
mode the system clock stops completely and the RTC would stop counting.
In these cases the RTC can be switched to Asynchronous Mode (by setting bit RTCCM
in register SYSCON0). In this mode the count registers are directly controlled by the
count clock independent of the system clock (hence the name). Asynchronous operation
ensures correct time-keeping even during sleep mode or powerdown mode.
However, as no synchronization between the count registers and the bus interface can
be maintained in asynchronous mode, the RTC registers cannot be written. Read
accesses may interfere with count events and, therefore, must be verified (e.g. by
reading the same value with three consecutive read accesses).
Note: The access restrictions in asynchronous mode are only meaningful if the system
clock is not switched off, of course.
Switching Clocking Modes
The clocking mode of the RTC (synchronous or asynchronous) is selected via bit
RTCCM in register SYSCON0. After reset, the RTC operates in Synchronous Mode
(RTCCM = 0) with the 8:1 prescaler enabled.
The selected clocking mode also affects the access to RTC registers. Bit ACCPOS in
register RTC_CON indicates if full register access is possible (ACCPOS = 1, default
after reset) or not (ACCPOS = 0). This also indicates the current clocking mode.
Attention: Software should poll bit ACCPOS to determine the proper transition to
the intended clocking mode.
After switching to Asynchronous Mode (RTCCM = 1), bit ACCPOS = 0 indicates proper
operation in Asynchronous Mode. In this case the system clock can be stopped or
reduced.
After switching to Synchronous Mode, (RTCCM = 0), bit ACCPOS = 1 indicates proper
operation in Synchronous Mode. In this case the RTC registers can again be accessed
properly (read and write).
Note: The RTC might lose a counting event (edge of
f
) when switching from
CNT
synchronous mode to asynchronous mode while the 8:1 prescaler is disabled. For
these applications it is, therefore, recommended to set up the RTC with the 8:1
prescaler enabled.
User’s Manual15-3V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
Increased RTC Accuracy through Software Correction
The accuracy of the XC161’s RTC is determined by the oscillator frequency and by the
respective prescaling factor (excluding or including T14 and the 8:1 prescaler). The
accuracy limit generated by the prescaler is due to the quantization of a binary counter
(where the average is zero), while the accuracy limit generated by the oscillator
frequency is due to the difference between the ideal and real frequencies (and therefore
accumulates over time). This effect is predictable and can be compensated. The total
accuracy of the RTC can be further increased via software for specific applications that
demand a high time accuracy.
The key to the improved accuracy is knowledge of the exact oscillator frequency. The
relation of this frequency to the expected ideal frequency is a measure of the RTC’s
deviation. The number of cycles, N, after which this deviation causes an error of
can be easily computed. So, the only action is to correct the count by
±1 after each series
±1 cycle
of N cycles. The correction may be made cyclically, for instance, within an interrupt
service routine, or by evaluating a formula when the RTC registers are read (for this the
respective “last” RTC value must be available somewhere).
Note: For the majority of applications, however, the standard accuracy provided by the
RTC’s structure will be more than sufficient.
Adjusting the current RTC value would require reading and then writing the complete
48-bit value. This can only be accomplished by three successive accesses each. To
avoid the hassle of reading/writing multi-word values, the RTC incorporates a correction
option to simply add or suppress one count pulse.
This is done by setting bit T14INC or T14DEC, respectively, in register RTC_CON. This
will add an extra count pulse (T14INC) upon the next count event, or suppress the next
count event (T14DEC). The respective bit remains set until its associated action has
been performed and is automatically cleared by hardware after this event.
Note: Setting both bits, T14INC and T14DEC, at the same time will have no effect on the
count values.
User’s Manual15-4V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15.2RTC Run Control
If the RTC shall operate bit RUN in register RTC_CON must be set (default after reset).
Bit RUN can be cleared, for example, to exclude certain operation phases from time
keeping. The RTC can be completely disabled by setting the corresponding bit RTCDIS
in register SYSCON3.
Note: A valid count clock is required for proper RTC operation, of course.
A reset for the RTC is triggered via software by setting bit RTCRST in register
SYSCON0. In this case all RTC registers are set to their initial values and bit RTCRST
is cleared automatically. A normal system reset does not affect the RTC registers and its
operation (RTC_IC will be reset, however). The initialization software must ensure the
proper RTC operating mode.
The RTC control register RTC_CON selects the basic operation of the RTC module.
RTC_CON
Control RegisterESFR (F110
/88H)Reset Value: 8003
H
H
1514131211109876543210
ACC
POS
rh----------rwrwhrwhrwrw
----------
REF
CLK
T14
INC
T14
DEC
PRE RUN
FieldBitsTypeDescription
ACCPOS15rhRTC Register Access Possible
0No write access is possible, only
asynchronous reads
1Registers can be read and written
REFCLK4rwReference Clock Source
0The RTC count clock is derived from the
auxiliary oscillator (
f
OSCa
)
1The RTC count clock is derived from the main
f
oscillator (
OSCm
/32)
T14INC3rwhIncrement Timer T14 Value
Setting this bit to 1 adds one count pulse upon the
next count event, thus incrementing T14.
This bit is cleared by hardware after incrementation.
T14DEC2rwhDecrement Timer T14 Value
Setting this bit to 1 suppresses the next count event,
thus decrementing T14.
This bit is cleared by hardware after decrementation.
0Prescaler disabled, T14 clocked with
1Prescaler enabled, T14 clocked with f
RUN0rwRTC Run Bit
0RTC stopped
1RTC runs
f
RTC
RTC
/8
User’s Manual15-6V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15.3RTC Operating Modes
The RTC can be configured for several operating modes according to the purpose it is
meant to serve. These operating modes are configured by selecting appropriate reload
values and interrupt signals.
PRE
1
MUX
0
Interrupt Sub Node
CNT
INT0
10 Bits6 Bits6 Bits10 Bits
CNT
INT1
REL-Register
CNT
INT2
CNT
INT3
RTCINT
f
RTC
RUN
8
T14REL
f
CNT
T14
T14-RegisterCNT-Register
10 Bits6 Bits6 Bits10 Bits
mcb04805_xc.vsd
Figure 15-3RTC Block Diagram
RTC Register Access
The actual value of the RTC is indicated by the three registers T14, RTCL, and RTCH.
As these registers are concatenated to build the RTC counter chain, internal overflows
occur while the RTC is running. When reading or writing the RTC value, such internal
overflows must be taken into account to avoid reading/writing corrupted values.
Care must be taken, when reading the timer(s), as this requires up to three read
accesses to the different registers with an inherent time delay between the accesses. An
overflow from T14 to RTCL and/or from RTCL to RTCH might occur between the
accesses, which needs to be taken into account appropriately.
For example, reading/writing 0000
to RTCH and then accessing RTCL could produce
H
a corrupted value as RTCL may overflow before it can be accessed. In this case, RTCH
would be 0001
. The same precautions must be taken for T14 and T14REL.
H
User’s Manual15-7V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
Timer T14 and its reload register are accessed via dedicated locations. The four RTC
counters CNT3 … CNT0 are accessed via the two 16-bit RTC timer registers, RTCH and
RTCL. The associated four reload values REL3 … REL0 are accessed via the two 16-bit
RTC reload registers, RELH and RELL.
Table 15-2Register Locations for Timer T14
Register NameLong/Short
Address
RTC_T14F0D2
H
/69
H
Reset
Value
0000
H
Notes
16-bit timer, can be used as prescaler
for the RTC block
RTC_T14RELF0D0
H
/68
H
0000
H
Timer T14 reload register
RTC_RTCH
RTC Timer High RegisterESFR (F0D6
1514131211109876543210
/6BH)Reset Value: 0000
H
H
CNT3CNT2
rwhrwh
RTC_RTCL
RTC Timer Low RegisterESFR (F0D4
1514131211109876543210
CNT1CNT0
rwhrwh
/6AH)Reset Value: 0000
H
FieldBitsTypeDescription
CNTx
(x = 3 … 0)
[15:6]
[5:0]
[15:10]
[9:0]
rwhRTC Timer Count Section CNTx
An overflow of this bitfield triggers a count pulse to
the next count section CNTx+1 (except for CNT3)
followed by a reload of CNTx from bitfield RELx.
In addition, an interrupt request is triggered.
H
User’s Manual15-8V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
RTC_RELH
RTC Reload High RegisterESFR (F0CE
1514131211109876543210
REL3REL2
rwrw
/67H)Reset Value: 0000
H
RTC_RELL
RTC Reload Low RegisterESFR (F0CC
1514131211109876543210
REL1REL0
rwrw
/66H)Reset Value: 0000
H
H
H
FieldBitsTypeDescription
RELx
(x = 3 … 0)
[15:6]
[5:0]
[15:10]
rwRTC Reload Value RELx
This bitfield is copied to bitfield CNTx upon an
overflow of count section CNTx.
[9:0]
Note: The registers of the RTC receive their reset values only upon a specific RTC reset.
This reset is not triggered upon a system reset, but via software.
User’s Manual15-9V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15.3.148-bit Timer Operation
The concatenation of timers T14 and COUNT0 … COUNT3 can be regarded as a 48-bit
timer which is clocked with the RTC input frequency, optionally divided by the prescaler.
The reload registers T14REL, RELL, and RELH must be cleared to produce a true binary
48-bit timer. However, any other reload value may be used. Reload values other than
zero must be used carefully, due to the individual sections of the RTC timer with their
own individual overflows and reload values.
48
The maximum usable timespan is 2
(≈ 1014) T14 input clocks (assuming no prescaler),
which would equal more than 200 years at an oscillator frequency of 32 kHz.
15.3.2System Clock Operation
A real time system clock can be maintained that keeps on running also during power
saving modes (optionally) and indicates the current time and date. This is possible
1)
because the RTC module is not affected by a system reset
The resolution for this clock information is determined by the input clock of timer T14. By
selecting appropriate reload values each cascaded timer can represent directly a part of
the current time and/or date. Due to its width, T14 can adjust the RTC to the intended
range of operation (time or date). The maximum usable timespan is achieved when
T14REL is loaded with 0000
and so T14 divides by 216.
H
.
System Clock Example
The RTC count clock is
f
(8:1 prescaler off). By selecting appropriate reload values
OSCa
the RTC timers directly indicate the current time (see Figure 15-4 and Table 15-3).
3E8
REL3
CNT3
Hours
H
04
H
REL2
CNT2
Minutes
04
H
REL1
CNT1
Seconds
018
H
REL0
CNT0
1/1000
Seconds
FFDF
H
T14REL
T14
Prescaler
f
=
CNT
32.768 kHz
MCA05414
Figure 15-4RTC Configuration Example
Note: This setup can generate an interrupt request every millisecond, every second,
every minute, every hour, or every day.
1) After a power on reset, however, the RTC registers are undefined.
User’s Manual15-10V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Each timer in the chain divides the clock by (2
<timer_width>
- <reload_value>) : 1, as the
Real Time Clock
timers count up. Table 15-3 shows the reload values which must be chosen for a specific
scenario (i.e. operating mode of the RTC).
1) T14 errors in the first example (ms) can be compensated either by choosing an adapted value for REL0, or by
using software correction.
Intr. Periodweekdayhourminutesecond
Week
15.3.3Cyclic Interrupt Generation
The RTC module can generate an interrupt request whenever one of the timers
overflows and is reloaded. This interrupt request may be used, for example, to provide
a system time tick independent of the CPU frequency without loading the general
purpose timers, or to wake up regularly from sleep mode. The interrupt cycle time can
be adjusted by choosing appropriate reload values and by enabling the appropriate
interrupt request.
In this mode, the other operating modes can be combined. For example, a reload value
of T14REL = F9C0
up the system regularly. Still the subsequent timers can be configured to represent the
time or build a binary counter, however with a different time base.
(216 - 1600) generates a T14 interrupt request every 50 ms to wake-
H
User’s Manual15-11V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
15.4RTC Interrupt Generation
The overflow signals of each timer of the RTC timer chain can generate an interrupt
request. The RTC’s interrupt subnode control register ISNC combines these requests to
activate the common RTC interrupt request line RTC_IRQ.
Each timer overflow sets its associated request flag in register ISNC. Individual enable
bits for each request flag determine whether this request also activates the common
interrupt line. The enabled requests are ORed together on this line (see Figure 15-5).
The interrupt handler can determine the source of an interrupt request via the specific
request flags and must clear them after appropriate processing (not cleared by
hardware). The common node request bit is automatically cleared when the interrupt
handler is vectored to.
Note: If only one source is enabled, no additional software check is required, of course.
Both the individual request and the common interrupt node must be enabled.
Register RTC_ISNC
CNT3 Overflow
CNT2 Overflow
CNT1 Overflow
CNT0 Overflow
T14 Overflow
Set
SW Clear
Set
SW Clear
Set
SW Clear
Set
SW Clear
Set
SW Clear
CNT3
IR
CNT2
IR
CNT1
IR
CNT0
IR
T14
IR
CNT3
IE
CNT2
IE
CNT1
IE
CNT0
IE
T14
IE
&
&
_
&
&
&
>1
Interrupt Request
RTC_IRQ
MCB05415
Figure 15-5Interrupt Block Diagram
User’s Manual15-12V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
Real Time Clock
RTC_ISNC
Interrupt Subnode Ctrl. Reg.ESFR (F10C
1514131211109876543210
------
------
CNT
CNT
3IR
rwhrwrwhrwrwhrwrwhrwrwhrw
3IE
/86H)Reset Value: 0000
H
CNT
CNT
2IR
2IE
CNT
1IR
CNT
1IE
CNT
0IR
CNT
0IE
T14 IRT14
IE
FieldBitsTypeDescription
CNTxIR
(x = 3 … 0)
9, 7, 5, 3rwhSection CNTx Interrupt Request Flag
0No request pending
1This source has raised an interrupt request
CNTxIE
(x = 3 … 0)
8, 6, 4, 2rwSection CNTx Interrupt Enable Control Bit
0Interrupt request is disabled
1Interrupt request is enabled
T14IR1rwhT14 Overflow Interrupt Request Flag
0No request pending
1This source has raised an interrupt request
H
T14IE0rwT14 Overflow Interrupt Enable Control Bit
0Interrupt request is disabled
1Interrupt request is enabled
Note: The interrupt request flags in register ISNC must be cleared by software. They are
not cleared automatically when the service routine is entered.
RTC_IC
RTC Interrupt Ctrl. Reg.ESFR (F1A0
1514131211109876543210
-------GPX
-------rw
/D0H)Reset Value: 0000
H
RTCIRRTC
IE
rwhrwrwrw
ILVLGLVL
Note: Please refer to the general Interrupt Control Register description for an
explanation of the control fields.
Register RTC_IC is not part of the RTC module and is reset with any system reset.
H
User’s Manual15-13V2.2, 2004-01
RTC_X8, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16The Analog/Digital Converter
The XC161 provides an Analog/Digital Converter with 8-bit or 10-bit resolution and a
sample & hold circuit on-chip. An input multiplexer selects between up to 12 analog input
channels (alternate functions of Port 5) either via software (fixed channel modes) or
automatically (auto scan modes).
To fulfill most requirements of embedded control applications the ADC supports the
following conversion modes:
•Fixed Channel Single Conversion
produces just one result from the selected channel
•Fixed Channel Continuous Conversion
repeatedly converts the selected channel
•Auto Scan Single Conversion
produces one result from each of a selected group of channels
•Auto Scan Continuous Conversion
repeatedly converts the selected group of channels
•Wait for ADDAT Read Mode
start a conversion automatically when the previous result was read
•Channel Injection Mode
start a conversion when a hardware trigger occurs,
can insert the conversion of a specific channel into a group conversion (auto scan)
A set of SFRs and port pins provide access to control functions and results of the ADC.
The enhanced-mode registers provide more detailed control functions for the ADC.
Data RegistersControl RegistersSystem Registers
ADC_DATADC_CONADC_CIC
ADC_DAT2
Compatibility Mode:
ADC_CONADC Control Register
ADC_CON1 ADC Control Register 1
Enhanced Mode:
ADC_CTR0 ADC Control Register 0
ADC_CTR2 ADC Control Register 2
ADC_CTR2IN ADC Control Injection Register
E
ADC_CON1
ADC_CTR0
ADC_CTR2
ADC_CTR2IN
Interrupt Control
P5
ADC_EIC
ADC_DATADC Result Register
ADC_DAT2 ADC Injection Result Register
ADC_CICADC End-of-Conversion Intr. Reg.
ADC_EICADC Conversion-Error Intr. Reg.
P5Port 5 Analog Input Port
(AN15...AN12, AN7...AN0)
P5DIDISPort 5 Digital Input Disable Reg.
P5DIDIS
SYSCON3
mc_adc0100_registers.vsd
E
Figure 16-1SFRs and Port Pins Associated with the A/D Converter
User’s Manual16-1V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The external analog reference voltages V
AREF
and V
The Analog/Digital Converter
are fixed. The separate supply
AGND
for the ADC reduces the interference with other digital signals. The reference voltages
must be stable during the reset calibration phase and during an entire conversion, to
achieve a maximum of accuracy.
The sample time as well as the conversion time is programmable, so the ADC can be
adjusted to the internal resistances of the analog sources and/or the analog reference
voltage supply (you may also want to refer to application note AP2428).
CTR0
CONCTR2
CON1CTR2IN
MUX
Injection
Requests
Conversion Control
ADC_CIRQ
ADC_EIRQ
AN0
AN7
AN12
AN15
MUX
Sample
&
Hold
8/10-bit
Capacitive Network
Conversion
DAT
DAT2
MCB05416
Figure 16-2Analog/Digital Converter Block Diagram
The ADC is implemented as a capacitive network using successive approximation
conversion. A conversion consists of 3 phases.
•During the sample phase, the capacitive network is connected to the selected analog
input and is charged or discharged to the voltage of the analog signal.
•During the actual conversion phase, the network is disconnected from the analog
input and is repeatedly charged or discharged via
V
during the steps of
AREF
successive approximation.
•After the (optional) post-calibration phase (to adjust the network to changing
conditions such as temperature) the result is written to the result register and an
interrupt request is generated.
There are two sets of control, data, and status registers, one set for compatibility mode
and one set for enhanced mode. Only one of these register sets may be active at a given
time. As most of the bits and bitfields of the registers of the two sets control the same
functionality or control the functionality in a very similar way, the following description is
organized according to the functionality, not according to the two register sets.
User’s Manual16-2V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.1Mode Selection
The analog input channels AN15 … AN12, AN7 … AN0 are alternate functions of Port 5
which is an input-only port. The Port 5 lines may either be used as analog or digital
inputs. For pins that shall be used as analog inputs it is recommended to disable the
digital input stage via register P5DIDIS. This avoids undesired cross currents and
switching noise while the (analog) input signal level is between
V
and VIH.
IL
The functions of the A/D converter are controlled by two sets of bit-addressable control
registers. In compatibility mode, registers ADC_CON and ADC_CON1 are used, in
enhanced mode, registers ADC_CTR0, ADC_CTR2, and ADC_CTR2IN are used. Their
bitfields specify the analog channel to be acted upon, the conversion mode, and also
reflect the status of the converter.
16.1.1Compatibility Mode
In compatibility mode (MD = 0), registers ADC_CON and ADC_CON1 select the basic
functions. The register layout is compatible with previous versions of the ADC module,
while providing limited options.
ADC_CON
ADC Control RegisterSFR (FFA0
1514131211109876543210
ADCTCADSTC
rwrwrwhrwrwrwhrwh-rwrw
AD
CRQ
AD
CIN
AD WRAD
BSY
/D0H)Reset Value: 0000
H
AD
ST
-ADMADCH
FieldBitsTypeFunction
ADCTC[15:14] rwADC Conversion Time Control (Defines the ADC
basic conversion clock
f
00
01
10
11
f
f
f
BC
BC
BC
BC
= f
= f
= f
= f
ADC
ADC
ADC
ADC
/4
/2
/16
/8
f
)
BC
ADSTC[13:12] rwADC Sample Time Control (Defines the ADC
sample time in a certain range)
00
01
10
11
t
t
t
t
BC
BC
BC
BC
× 8
× 16
× 32
× 64
H
ADCRQ11rwhADC Channel Injection Request Flag
ADCIN10rwADC Channel Injection Enable
User’s Manual16-3V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
FieldBitsTypeFunction
ADWR9rwADC Wait for Read Control
ADBSY8rhADC Busy Flag
0ADC is idle
1A conversion is active
ADST7rwhADC Start Bit
0Stop a running conversion
1Start conversion(s)
ADM[5:4]rwADC Mode Selection
00Fixed Channel Single Conversion
01Fixed Channel Continuous Conversion
10Auto Scan Single Conversion
11Auto Scan Continuous Conversion
ADCH[3:0]rwADC Analog Channel Input Selection
Selects the (first) ADC channel which is to be
converted.
ADC_CON1
ADC Control Register 1SFR (FFA6
1514131211109876543210
rw
SAM
PLE
CAL RESADCTCADSTC
rhrhrwrwrw
ICST
/D3H)Reset Value: 0000
H
FieldBitsTypeDescription
ICST15rwImproved Conversion and Sample Timing
Selects the active timing control bitfields
0Standard conversion and sample time control,
2-bit fields in ADC_CON (default after reset)
1Improved conversion and sample time control,
6-bit fields in ADC_CON1
SAMPLE14rhSample Phase Status Flag
0A/D Converter is not in sampling
1A/D Converter is currently in the sample phase
H
CAL13rhReset Calibration Phase Status Flag
0A/D Converter is not in calibration phase
1A/D Converter is in calibration phase
User’s Manual16-4V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
FieldBitsTypeDescription
RES12rwConversion Resolution Control
010-bit resolution (default after reset)
18-bit resolution
ADCTC[11:6]rwADC Conversion Time Control
Defines the ADC basic conversion clock:
f
BC
= f
/ (<ADCTC> + 1)
ADC
ADSTC[5:0]rwADC Sample Time Control
Defines the ADC sample time:
t
= tBC × 4 × (<ADSTC> + 1)
S
Note: The limit values for fBC (see data sheet) must not be exceeded when selecting
f
ADCTC and
ADC
.
16.1.2Enhanced Mode
In enhanced mode (MD = 1), registers ADC_CTR0, ADC_CTR2, and ADC_CTR2IN
select the basic functions. The register layout differs from the compatibility-mode layout,
but this mode provides more options.
Conversion timing is selected via registers ADC_CTR2(IN), where ADC_CTR2 controls
standard conversions and ADC_CTR2IN controls injected conversions.
ADC_CTR0
ADC Control Register 0SFR (FFBE
1514131211109876543210
SAM
MD
PLE
rwrhrwrwhrwrwrhrwhrwrwrw
ADCTS
AD
CRQADCINADWRADBSYADST
/DFH)Reset Value: 1000
H
ADM
CAL
OFF
ADCH
FieldBitsTypeDescription
MD15rwMode Control
0Compatibility Mode
1Enhanced Mode
Note: Any modification of control bit MD is forbidden
while a conversion is currently running. User
software must take care.
H
SAMPLE14rhSample Phase Status Flag
0A/D Converter is not in sample phase
1A/D Converter in sample phase
ADCRQ11rwhChannel Injection Request Flag
ADCIN10rwChannel Injection Enable Control
ADWR9rwWait for Read Control
ADBSY8rhBusy Flag
0ADC is idle
1A conversion is active
ADST7rwhADC Start/Stop Control
0Stop a running conversion
1Start conversion(s)
for
B
ADM[6:5]rwMode Selection Control
00Fixed Channel Single Conversion
01Fixed Channel Continuous Conversion
10Auto Scan Single Conversion
11Auto Scan Continuous Conversion
CALOFF4rwCalibration Disable Control
0Calibration cycles are executed
1Calibration is disabled (off)
Note: This control bit is active in both compatibility
and enhanced mode.
ADCH[3:0]rwAnalog Input Channel Selection
Selects the (first) ADC channel which is to be
converted
User’s Manual16-6V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
ADC_CTR2
ADC Control Register 2ESFR (F09C
1514131211109876543210
-RESADCTCADSTC
-rw rwrw
/4EH)Reset Value: 0000
H
ADC_CTR2IN
Injection Control Register 2ESFR (F09E
1514131211109876543210
-RESADCTCADSTC
rrw rwrw
/4FH)Reset Value: 0000
H
FieldBitsTypeDescription
H
H
RES[13:12] rwConverter Resolution Control
0010-bit resolution (default after reset)
018-bit resolution
1xReserved
ADCTC[11:6]rwADC Conversion Time Control
Defines the ADC basic conversion clock:
f
BC
= f
/ (<ADCTC> + 1)
ADC
ADSTC[5:0]rwADC Sample Time Control
Defines the ADC sample time:
t
= tBC × 4 × (<ADSTC> + 1)
S
Note: The limit values for fBC (see data sheet) must not be exceeded when selecting
f
ADCTC and
ADC
.
User’s Manual16-7V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.2ADC Operation
Channel Selection, ADCH
Bitfield ADCH controls the input channel multiplexer logic. In the Single Channel Modes,
it specifies the analog input channel which is to be converted. In the Auto Scan Modes,
it specifies the highest channel number to be converted in the auto scan round.
ADCH may be changed while a conversion is in progress. The new value will go into
effect after the current conversion is finished in the fixed channel modes, or after the
current conversion round is finished in the auto scan modes.
ADC Flags, ADBSY, SAMPLE
The ADC Busy Status Flag is set when the ADC is started (by setting ADST) and remains
set as long as the ADC performs conversions or calibration cycles.
ADBSY is cleared when the ADC is idle, meaning there are no conversion or calibration
operations in progress.
Bit SAMPLE is set during the sample phase.
ADC Start/Stop Control, ADST
Bit ADST is used to start or to stop the ADC. A single conversion or a conversion
sequence is started by setting bit ADST.
The busy flag ADBSY will be set and the converter then selects and samples the input
channel, which is specified by the channel selection field ADCH. The sampled level will
then be held internally during the conversion. When the conversion of this channel is
complete, the result together with the number of the converted channel is transferred into
the result register and the interrupt request is generated. The conversion result is placed
into bitfield ADRES.
ADST remains set until cleared either by hardware or by software. Hardware clears the
bit dependent on the conversion mode:
•In Fixed Channel Single Conversion mode, ADST is cleared after the conversion of
the specified channel is finished.
•In Auto Scan Single Conversion mode, ADST is cleared after the conversion of
channel 0 is finished.
Note: In the continuous conversion modes, ADST is never cleared by hardware.
Stopping the ADC via software is performed by clearing bit ADST. The reaction of the
ADC depends on the conversion mode:
•In Fixed Channel Single Conversion mode, the ADC finishes the conversion and then
stops. There is no difference to the operation if ADST was not cleared by software.
•In Fixed Channel Continuous Conversion mode, the ADC finishes the current
conversion and then stops. This is the usual way to terminate this conversion mode.
User’s Manual16-8V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
•In Auto Scan Single Conversion mode, the ADC continues the auto scan round until
the conversion of channel 0 is finished, then it stops. There is no difference to the
operation if ADST was not cleared by software.
•In Auto Scan Continuous Conversion mode, the ADC continues the auto scan round
until the conversion of channel 0 is finished, then it stops. This is the usual way to
terminate this conversion mode.
A restart of the ADC can be performed by clearing and then setting bit ADST. This
sequence will abort the current conversion and restart the ADC with the new parameters
given in the control registers.
Conversion Mode Selection, ADM
Bitfield ADM selects the conversion mode of the A/D converter, as listed in Table 16-1.
00Fixed Channel Single Conversion
01Fixed Channel Continuous Conversion
10Auto Scan Single Conversion
11Auto Scan Continuous Conversion
While a conversion is in progress, the mode selection field ADM and the channel
selection field ADCH may be changed. ADM will be evaluated after the current
conversion. ADCH will be evaluated after the current conversion (fixed channel modes)
or after the current conversion sequence (auto scan modes).
Conversion Resolution Control, RES
The ADC can produce either a 10-bit result (RES = 0) or an 8-bit result (RES = 1).
Depending on the application’s needs a higher conversion speed (an 8-bit conversion
requires less conversion time) or a higher resolution can be chosen.
User’s Manual16-9V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
Conversion Result
The result of a conversion is stored in the result register ADC_DAT, or in register
ADC_DAT2 for an injected conversion.
The position of the result depends on the basic operating mode (compatibility or
enhanced) and on the selected resolution (8-bit or 10-bit).
Note: Bitfield CHNR of register ADC_DAT is loaded by the ADC to indicate, which
channel the result refers to. Bitfield CHNR of register ADC_DAT2 is loaded by the
CPU to select the analog channel, which is to be injected.
ADC_DAT
ADC Result RegisterSFR (FEA0
1514131211109876543210
CHNRADRES
rwhrwh
/50H)Reset Value: 0000
H
H
ADC_DAT2
ADC Chan. Inj. Result Reg.ESFR (F0A0
1514131211109876543210
CHNRADRES
rw
/50H)Reset Value: 0000
H
rwh
FieldBitsTypeFunction
CHNR[15:12] rw[h]Channel Number (identifies the converted analog
channel)
ADRES[11:0]rwhA/D Conversion Result
The digital result of the most recent conversion.
In compatibility mode, the result is placed as follows:
8-bit: ADRES[9:2]
10-bit: ADRES[9:0]
In enhanced mode, the result is placed as follows:
8-bit: ADRES[11:4]
10-bit: ADRES[11:2]
H
Note: Unused bits of ADRES are always set to 0.
User’s Manual16-10V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.2.1Fixed Channel Conversion Modes
These modes are selected by programming the mode selection bitfield ADM to 00
(single conversion) or to 01B (continuous conversion). After starting the converter
through bit ADST the busy flag ADBSY will be set and the channel specified in bitfield
ADCH will be converted. After the conversion is complete, the interrupt request flag
ADCIR will be set.
In Single Conversion Mode the converter will automatically stop and reset bits ADBSY
and ADST.
In Continuous Conversion Mode the converter will automatically start a new
conversion of the channel specified in ADCH. ADCIR will be set after each completed
conversion.
When bit ADST is reset by software, while a conversion is in progress, the converter will
complete the current conversion and then stop and reset bit ADBSY.
B
User’s Manual16-11V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.2.2Auto Scan Conversion Modes
These modes are selected by programming the mode selection field ADM to 10B (single
conversion) or to 11
a sequence of analog channels, beginning with the channel specified in bitfield ADCH
and ending with channel 0, without requiring software to change the channel number.
After starting the converter through bit ADST, the busy flag ADBSY will be set and the
channel specified in bitfield ADCH will be converted. After the conversion is complete,
the interrupt request flag ADCIR will be set and the converter will automatically start a
new conversion of the next lower channel. ADCIR will be set after each completed
conversion. After conversion of channel 0 the current sequence is complete.
In Single Conversion Mode the converter will automatically stop and reset bits ADBSY
and ADST.
In Continuous Conversion Mode the converter will automatically start a new sequence
beginning with the conversion of the channel specified in ADCH.
When bit ADST is reset by software, while a conversion is in progress, the converter will
complete the current sequence (including conversion of channel 0) and then stop and
reset bit ADBSY.
(continuous conversion). Auto Scan modes automatically convert
B
Conversion
of Channel..
Write ADC_DAT
ADC_DAT Full
Generate Interrupt
Request
Read of ADC_DAT;
Result of Channel:
# 3
# x
# x# 3
# 3
# 2
# 1# 0
# 2
# 2# 1
# 1
# 3# 2
# 0# 3
ADC_DAT Full;
Channnel 0
Result Lost
MC_ADC0001_AUTOSCAN
# 3
Overrun Error
Interrupt Request
Figure 16-3Auto Scan Conversion Mode Example
Note: Auto Scan sequences that begin with channel numbers above 7 will generate (up
to) 4 invalid results from channels 11 … 8 which are not connected to input pins.
Starting an Auto Scan sequence with ADCH = E
will generate the following
H
15 results: 14, 13, 12, x, x, x, x, 7, 6, 5, 4, 3, 2, 1, 0.
Starting a sequence with ADCH = B
… 8H generates 4 … 1 invalid results at the
H
beginning of the sequence and therefore makes no sense in an application.
User’s Manual16-12V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.2.3Wait for Read Mode
If in default mode of the ADC a previous conversion result has not been read out of the
result register by the time a new conversion is complete, the previous result is lost
because it is overwritten by the new value, and the A/D overrun error interrupt request
flag ADEIR will be set.
In order to avoid error interrupts and the loss of conversion results especially when using
continuous conversion modes, the ADC can be switched to “Wait for Read Mode” by
setting bit ADWR.
If the result value has not been read by the time the current conversion is complete, the
new result is stored in a temporary buffer and the next conversion is suspended (ADST
and ADBSY will remain set in the meantime, but no end-of-conversion interrupt will be
generated). After reading the previous value the temporary buffer is copied into
ADC_DAT (generating an ADCIR interrupt) and the suspended conversion is started.
This mechanism applies to both single and continuous conversion modes.
Note: While in standard mode continuous conversions are executed at a fixed rate
(determined by the conversion time), in “Wait for Read Mode” there may be delays
due to suspended conversions. However, this only affects the conversions, if the
CPU (or PEC) cannot keep track with the conversion rate.
Conversion
of Channel..
Write ADC_DAT
ADC_DAT Full
Temp-Latch Full
Generate Interrupt
Request
Read of ADC_DAT;
Result of Channel:
# 3
# x
# x
# 2# 1wait
# 2# 3
Figure 16-4Wait for Read Mode Example
1
Hold Result in
Temp-Latch
# 3# 0
# 1# 0# 3
# 2# 3# 1
# 0
MC_ADC0002_WAITREAD
User’s Manual16-13V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.2.4Channel Injection Mode
Channel Injection Mode allows the conversion of a specific analog channel (also while
the ADC is running in a continuous or auto scan mode) without changing the current
operating mode. After the conversion of this specific channel the ADC continues with the
original operating mode.
Channel Injection mode is enabled by setting bit ADCIN and requires the Wait for Read
Mode (ADWR = 1). The channel to be converted in this mode is specified in bitfield
CHNR of register ADC_DAT2.
Note: Bitfield CHNR in ADC_DAT2 is not modified by the A/D converter, but only the
ADRES bitfield. Since the channel number for an injected conversion is not
buffered, bitfield CHNR of ADC_DAT2 must never be modified during the sample
phase of an injected conversion, otherwise the input multiplexer will switch to the
new channel. It is recommended to only change the channel number with no
injected conversion running.
Conversion
of Channel..
Write ADC_DAT;
ADC_DAT Full
Read ADC_DAT
Injected
Conversion
of Channel # y
ADC_DAT2 Full
Read ADC_DAT2
# x+1
# x
# x+1
# x-1
# x
# x
Channel Injection
Request
# x-2
# x-1
# x-1
Figure 16-5Channel Injection Example
# x-2
# x-2
# y
Write ADC_DAT2
Int. Request
ADEINT
# x-3
# x-4
# x-3# x-4
# x-3
MC_ADC0003_INJECT
# ...
# x-4
User’s Manual16-14V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
A channel injection can be triggered in two ways:
•setting of the Channel Injection Request bit ADCRQ via software
•a compare or a capture event of Capture/Compare register CC31 of the CAPCOM2
unit, which also sets bit ADCRQ.
The second method triggers a channel injection at a specific time, on the occurrence of
a predefined count value of the CAPCOM timers or on a capture event of register CC31.
This can be either the positive, the negative, or both the positive and the negative edge
of an external signal. In addition, this option allows recording the time of occurrence of
this signal.
Note: The channel injection request bit ADCRQ will be set on any interrupt request of
CAPCOM2 channel CC31, regardless whether the channel injection mode is
enabled or not. It is recommended to always clear bit ADCRQ before enabling the
channel injection mode.
After the completion of the current conversion (if any is in progress) the converter will
start (inject) the conversion of the specified channel. When the conversion of this
channel is complete, the result will be placed into the alternate result register
ADC_DAT2, and a Channel Injection Complete Interrupt request will be generated,
which uses the interrupt request flag ADEIR (for this reason the Wait for Read Mode is
required).
Note: The result of an injected conversion is directly written to ADC_DAT2. If the
previous result has not been read in the meantime, it is overwritten.
Standard conversions are suspended if the temporary buffer is full.
User’s Manual16-15V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
Arbitration of Conversions
Conversion requests that are activated while the ADC is idle immediately trigger the
respective conversion. If a conversion is requested while another conversion is currently
in progress the operation of the A/D converter depends on the kind of the involved
conversions (standard or injected).
Note: A conversion request is activated if the respective control bit (ADST or ADCRQ)
is toggled from 0 to 1, i.e. the bit must have been zero before being set.
Table 16-2 summarizes the ADC operation in the possible situations.
Table 16-2Conversion Arbitration
Conversion
in Progress
StandardInjected
StandardAbort running conversion,
and start requested new
conversion.
1)
New Requested Conversion
Complete running conversion,
start requested conversion after that.
InjectedComplete running conversion,
start requested conversion after
that.
Complete running conversion,
start requested conversion after that.
Bit ADCRQ will be 0 for the second
conversion, however.
1) If an injected conversion is pending when a standard conversion is re-started, the injected conversion is
executed before the newly started standard conversion.
User’s Manual16-16V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.3Automatic Calibration
The ADC of the XC161 features automatic self-calibration. This calibration corrects gain
errors, which are mainly due to process variation, and offset errors, which are mainly due
to temperature changes.
Two types of calibration are supported:
•Reset calibration performs a thorough basic calibration of the ADC after a reset. In
particular this is required after a power-on reset.
•Post-calibration performs one small calibration step after each conversion.
Reset Calibration
After a reset, a thorough power-up calibration is performed automatically to correct gain
and offset errors of the A/D converter. To achieve best calibration results, the reference
voltages as well as the supply voltages must be stable during the power-up calibration.
During the calibration sequence a series of calibration cycles is executed, where the step
width for adjustments is reduced gradually. The total number of executed calibration
cycles depends on the actual properties of the respective ADC module. The maximum
duration of the power-up calibration is 11,696 cycles of the basic clock
Status flag CAL is set as long as this power-up calibration takes place.
f
BC
.
Post-Calibration
After each conversion a small calibration step can be executed. For 8-bit and 10-bit
conversions post-calibration is not mandatory in order not to exceed the total unadjusted
error (TUE) specified in the data sheet. Post-calibration can be disabled by setting bit
CALOFF in register ADC_CTR0. When disabled, the post-calibration cycles are skipped
which reduces the total conversion time.
Note: Calibration may be disabled only after the reset calibration is complete.
User’s Manual16-17V2.2, 2004-01
ADC_X1, V2.1
XC161 Derivatives
Peripheral Units (Vol. 2 of 2)
The Analog/Digital Converter
16.4Conversion Timing Control
When a conversion is started, first the capacitances of the converter are loaded via the
respective analog input pin to the current analog input voltage. The time to load the
capacitances is referred to as sample time. Next the sampled voltage is converted to a
digital value in successive steps, which correspond to the resolution of the ADC. During
these phases (except for the sample time) the internal capacitances are repeatedly
charged and discharged via pins
The current that has to be drawn from the sources for sampling and changing charges
depends on the time that each respective step takes, because the capacitors must reach
their final voltage level within the given time, at least with a certain approximation. The
maximum current, however, that a source can deliver, depends on its internal resistance.
The time that the two different actions during conversion take (sampling, and converting)
can be programmed within a certain range in the XC161 relative to the CPU clock. The
absolute time that is consumed by the different conversion steps therefore is
independent from the general speed of the controller. This allows adjusting the A/D
converter of the XC161 to the properties of the system:
V
AREF
and V
AGND
.
Fast Conversion can be achieved by programming the respective times to their
absolute possible minimum. This is preferable for scanning high frequency signals. The
internal resistance of analog source and analog supply must be sufficiently low,
however.
High Internal Resistance can be achieved by programming the respective times to a
higher value, or the possible maximum. This is preferable when using analog sources
and supply with a high internal resistance in order to keep the current as low as possible.
The conversion rate in this case may be considerably lower, however.
Control Bitfields
For the timing control of the conversion and the sample phase two mechanisms are
provided:
•Standard timing control uses two 2-bit fields in register ADC_CON to select
prescaler values for the general conversion timing and the duration of the sample
phase. This provides compact control, while limiting the prescaler factors to a few
steps.
•Improved timing control uses two 6-bit fields in register ADC_CON1 (compatibility
mode) or register ADC_CTR2/ADC_CTR2IN (enhanced mode). This provides a wide
range of prescaler factors, so the ADC can be better adjusted to the internal and
external system circumstances.
Improved timing control is selected by setting bit ICST in register ADC_CON1 in
compatibility mode, or by selecting enhanced mode.
User’s Manual16-18V2.2, 2004-01
ADC_X1, V2.1
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.