| Xmega IEC60730 Class B Library 1.0 |

All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Submodules
CPU Frequency Test

## Detailed Description

This is the self-diagnostic test for the CPU frequency. The test consists in monitoring the frequency of a Timer/Counter (TC) using the Real Time Counter (RTC) module as a time reference. Note that the TC has the same clock domain as the CPU and that the RTC module in XMEGA can have a clock source independent from the CPU clock domain. Note that CLASSB_FREQ_TEST has to be defined. For more details see Real Time Counter Driver.

The test is implemented as follows. Firstly, an RTC compare interrupt is scheduled periodically with classb_rtc_setup() and a TC is started with classb_freq_setup_timer(). Secondly, the RTC interrupt calls classb_freq_callback(), which compares the absolute difference between the count in the TC and a predefined reference. If it should be greater than expected, the error handler CLASSB_ERROR_HANDLER_FREQ() would be called.

The TC overflow interrupt increases a counter that can be used as most significant word (bits 31 to 16) for the TC counter value. Further, there is a configurable limit for the number of overflows. If this was exceeded, the program would assume that the RTC was not working correctly and the error handler would be called as well.

The test is flexible and it is possible to choose some settings for the TC and RTC. However, it is important to choose values for CLASSB_RTC_INT_PERIOD, CLASSB_RTC_FREQ, CLASSB_TC_PRESCALER and CLASSB_TOLERANCE so that the frequency of the CPU F_CPU is estimated reliably. Further, there should not be an overflow in CLASSB_TC_COUNT_REF. Suggested values have been included in the documentation.

## Submodules
| Settings
| This should be configured by the user.
| Functions
| Functions related to the CPU frequency self-test.