33.3.4 System Clock Measurement with UPDI
It is possible to use the UPDI to get an 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 TCBn.CTRLB with setting CNTMODE=0x3, Input Capture Frequency Measurement mode.
- Write CAPTEI=1 in TCBn.EVCTRL to enable Event Interrupt. Keep EDGE = 0 in TCBn.EVCTRL.
- Configure the Event System as described in 33.3.8 Events.
- For the SYNCH character used to generate the UPDI events, it is recommended to use a slow baud rate in the range of 10 kbps - 50 kbps 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 10 kbps 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 TCBn.CCMP register or the value can be written to memory by the CPU once the capture is done.