MAX32665-MAX32668 User Guide
Maxim Integrated Page 344 of 457
16.11 Capture/Compare Mode (111b)
In Capture/Compare mode, the timer starts counting after the first external timer input transition occurs. The transition, a
rising edge or falling edge on the timer’s input signal, is set using the TMRn_CN.tpol bit.
Each subsequent transition, after the first transition of the timer input signal, captures the TMRn_CNT value, writing it to
the TMRn_PWM register (capture event). When a capture event occurs, a timer interrupt is generated, the TMRn_CNT
value is reset to 0x0000 0001, and the timer resumes counting.
If no capture event occurs, the timer counts up to the TMRn_CMP value. At the end of the cycle where the TMRn_CNT
equals the TMRn_CMP value, a timer interrupt is generated, the TMRn_CNT value is reset to 0x0000 0001, and the timer
resumes counting.
16.11.1 Capture/Compare Timer Period
The timer period ends when the selected transition occurs on the timer pin, or on the clock cycle following TMRn_CNT
= TMRn_CMP.
The timer peripheral automatically performs the following actions at the end of the timer period:
If the end of the timer period was caused by a transition on the timer pin:
1. The value in TMRn_CNT is copied to TMRn_PWM.
2. TMRn_CNT is reset to 0x0000 0001. The timer remains enabled and continues incrementing.
3. The timer interrupt bit, TMRn_INT.irq, is set. If the timer’s interrupt is enabled a Timer IRQ is generated
automatically.
4. If the end of the timer period was caused by a transition on the timer pin:
5. TMRn_CNT is reset to 0x0000 0001. The timer remains enabled and continues incrementing..
6. The timer interrupt bit TMRn_INT.irq will be set. An interrupt will generated if enabled.
16.11.2 Capture/Compare Configuration
Configure the timer for Capture/Compare mode by doing the following:
1. Set TMRn_CN.ten = 0 to disable the timer.
2. Set TMRn_CN.tmode to 111b to select Capture/Compare mode.
3. Set TMRn_CN.pres3:TMRn_CN.pres to set the prescaler that determines the timer frequency.
4. Configure the timer pin:
a. Configure the pin as a timer input and configure the electrical characteristics as needed.
b. Set TMRn_CN.tpol to select the positive edge (TMRn_CN.tpol = 0) or negative edge (TMRn_CN.tpol = 0)
transition causes the capture event.
5. If using the timer interrupt, enable the interrupt and set the interrupt priority.
6. Write an initial value to TMRn_CNT, if desired. This effects only the first period; subsequent timer periods always
reset TMRn_CNT= 0x0000 0001.
7. Set TMRn_CN.ten to 1 to enable the timer. Counting starts after the first transition of the timer’s input signal.
Note: No interrupt is generated by the first transition of the input signal.
In Capture/Compare mode, the elapsed time from the timer start to the capture event is calculated using Equation 16-11,
below.