2.46 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

NameDescription
FREQM_InitializeInitializes FREQM module
FREQM_MeasurementStartThis function starts the frequency measurement
FREQM_CallbackRegisterAllows application to register a callback function
FREQM_IsBusyReturns the measurement status of an on-going frequency measurement operation
FREQM_FrequencyGetReturns the measured frequency in Hz
FREQM_ErrorGetReturns error that may have occurred during the frequency measurement process

Data types and constants

NameTypeDescription
FREQM_ERROREnumIdentifies the possible FREQM module errors
FREQM_CALLBACKTypedefPointer to a FREQM CallBack function
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.