1.40.10 Frequency Meter (FREQM)
The Frequency Meter (FREQM) can be used to accurately measure the frequency of a clock by comparing it to a known reference clock.
Using The Library
AFEC converts all the enabled channels on software or hardware triggers. It provides both polling and callback methods to indicate the end of conversion to read the converted data from the result registers.
-
With polling, the application will need to continuously poll to check if the conversion is completed.
-
With callback, the registered callback function will be called once the conversion is completed. This means the application do not have to poll continuously.
Callback method
This example demonstrates frequency measurement with callback.
void AFEC_EventHandler(uintptr_t context) { uint32_t frequencyInHertz; if(FREQM_ErrorGet() == FREQM_ERROR_NONE) { frequencyInHertz = FREQM_FrequencyGet(); } } int main(void) { FREQM_CallbackRegister(&FREQ_EventHandler,(uintptr_t)NULL); FREQM_MeasurementStart(); }
Polling method
This example demonstrates frequency measurement with polling
uint32_t frequencyInHertz; /* Start Frequency Measurement */ FREQM_MeasurementStart(); /* Wait for measurement completion */ while(FREQM_IsBusy()); /* Read the result */ if(FREQM_ErrorGet() == FREQM_ERROR_NONE) { frequencyInHertz = FREQM_FrequencyGet(); }
Library Interface
Frequency Meter peripheral library provides the following interfaces:
Functions
Name | Description |
---|---|
FREQM_Initialize | Initializes FREQM module |
FREQM_MeasurementStart | This function starts the frequency measurement |
FREQM_CallbackRegister | Allows application to register a callback function |
FREQM_IsBusy | Returns the measurement status of an on-going frequency measurement operation |
FREQM_FrequencyGet | Returns the measured frequency in Hz |
FREQM_ErrorGet | Returns error that may have occurred during the frequency measurement process |
Data types and constants
Name | Type | Description |
---|---|---|
FREQM_ERROR | Enum | Identifies the possible FREQM module errors |
FREQM_CALLBACK | Typedef | Pointer to a FREQM CallBack function |