It is possible to use the UPDI to get a accurate measurement of the system clock
frequency, by using the UPDI event connected to TCB with Input Capture capabilities. A
recommended setup flow for this feature is given by the following steps:
- Set up TCB.CTRLB with setting
CNTMODE=0x3, Input Capture frequency measurement mode. See for details.
- Write CAPTEI=1 in TCB.EVCTRL to
enable Event Interrupt. Keep EDGE = 0 in TCB.EVCTRL.
- Configure the Event System as
described in Events
- For the SYNCH character used to
generate the UPDI events, it is recommended to use a slow baud rate in the range
of 10kbps - 50kbps to get a more accurate measurement on the value captured by
the timer between each UPDI event. One particular thing is that if the capture
is set up to trigger an interrupt, the first captured value should be ignored.
The second captured value based on the input event should be used for the
measurement. See the figure below for an example using 10kbps UPDI SYNCH
character pulses, giving a capture window of 200µs for the Timer.
- It is possible to read out the
captured value directly after the SYNCH character, by reading the TCB.CC
register, or the value can be written to memory by the CPU once the capture is
done.
Figure 1. UPDI System Clock Measurement
Events