
Timer/PWM (S08TPMV2)
MC9S08QG8 and MC9S08QG4 Data Sheet, Rev. 1.01
240
Freescale Semiconductor
transferred to the corresponding timer channel registers only after both 8-bit bytes of a 16-bit register have
beenwrittenandthetimercounteroverflows(reversesdirectionfromup-countingtodown-countingatthe
end of the terminal count in the modulus register). This TPMCNT overflow requirement only applies to
PWM channels, not output compares.
Optionally, when TPMCNTH:TPMCNTL = TPMMODH:TPMMODL, the TPM can generate a TOF
interrupt at the end of this count. The user can choose to reload any number of the PWM buffers, and they
will all update simultaneously at the start of a new period.
Writing to TPMSC cancels any values written to TPMMODH and/or TPMMODL and resets the
coherency mechanism for the modulo registers. Writing to TPMCnSC cancels any values written to the
channel value registers and resets the coherency mechanism for TPMCnVH:TPMCnVL.
16.5
TPM Interrupts
The TPM generates an optional interrupt for the main counter overflow and an interrupt for each channel.
The meaning of channel interrupts depends on the mode of operation for each channel. If the channel is
configured for input capture, the interrupt flag is set each time the selected input capture edge is
recognized. If the channel is configured for output compare or PWM modes, the interrupt flag is set each
time the main timer counter matches the value in the 16-bit channel value register. See the
Resets,
Interrupts, and System Configuration
chapter for absolute interrupt vector addresses, priority, and local
interrupt mask control bits.
ForeachinterruptsourceintheTPM,aflagbitissetonrecognitionoftheinterruptconditionsuchastimer
overflow, channel input capture, or output compare events. This flag may be read (polled) by software to
verify that the action has occurred, or an associated enable bit (TOIE or CHnIE) can be set to enable
hardware interrupt generation. While the interrupt enable bit is set, a static interrupt will be generated
whenever the associated interrupt flag equals 1. It is the responsibility of user software to perform a
sequence of steps to clear the interrupt flag before returning from the interrupt service routine.
16.5.1
Clearing Timer Interrupt Flags
TPM interrupt flags are cleared by a 2-step process that includes a read of the flag bit while it is set (1)
followed by a write of 0 to the bit. If a new event is detected between these two steps, the sequence is reset
and the interrupt flag remains set after the second step to avoid the possibility of missing the new event.
16.5.2
Timer Overflow Interrupt Description
The conditions that cause TOF to become set depend on the counting mode (up or up/down). In
up-countingmode,the16-bittimercountercountsfrom0x0000through0xFFFFandoverflowsto0x0000
on the next counting clock. TOF becomes set at the transition from 0xFFFF to 0x0000. When a modulus
limit is set, TOF becomes set at the transition from the value set in the modulus register to 0x0000. When
thecounterisoperatinginup-/down-countingmode,theTOFflaggetssetasthecounterchangesdirection
atthetransitionfromthevaluesetinthemodulusregisterandthenextlowercountvalue.Thiscorresponds
to the end of a PWM period. (The 0x0000 count value corresponds to the center of a period.)