Using the Signal Frequency Analyzer (SFA) to Measure the FRO 6M Frequency
Overview
The Signal Frequency Analyzer (SFA) is a specialized hardware peripheral available in NXP’s KW45, MCXW71, KW47, and MCXW72 microcontrollers. It is designed to provide precise, real-time measurement and analysis of digital signal characteristics, including frequency, period, and timing intervals. This makes it a valuable tool for applications requiring accurate timing diagnostics, signal validation, and system debugging.
By utilizing internal 32-bit counters and configurable trigger mechanisms, the SFA enables high-resolution capture of signal transitions, supporting robust system monitoring and fault detection.
Functional Capabilities of the SFA
The SFA module supports the following measurements:
It operates using two 32-bit counters:
Measurement is performed by comparing the counts of both clocks until predefined target values are reached.
FRO 6M Frequency Failure Scenarios
The 6 MHz Free Running Oscillator (FRO6M) may occasionally output an incorrect frequency under certain conditions:
To mitigate potential issues caused by incorrect FRO6M output, it is the application developer’s responsibility to verify the oscillator’s frequency and apply corrective measures as needed.
Monitoring the FRO 6M Using the SFA
To monitor the FRO6M signal, the following configuration is recommended:
SFA Configuration Parameters
Code Implementation
The presented functions are meant to be implemented in users application, the inner functions are part of the implementations of the SFA driver from the NXP’s SDK.
It can be used on MCXW71, MCXW72, KW45, kKW47, just make sure
void init_SFA_peripheral(void)
{
/* Enable SFA interrupt. */
EnableIRQ(SFA_IRQn);
/* Set SFA interrupt priority. */
NVIC_SetPriority(SFA_IRQn, 1);
SFA_Init(DEMO_SFA_BASEADDR);
SFA_InstallCallback(DEMO_SFA_BASEADDR, EXAMPLE_SFA_CALLBACK);
}
void EXAMPLE_SFA_CALLBACK(status_t status)
{
if (status == kStatus_SFA_MeasurementCompleted)
{
SfaMeasureFinished = true;
}
sfa_callback_status = status;
}
This function sets up the measurement of the FRO6M signal using the CPU clock as the reference.
uint8_t SFA_freq_measurement_6M_FRO(void)
{
uint8_t ratio = 0;
uint32_t freq = 0UL;
sfa_config_t config;
CLOCK_SetClkOutSel(kClockClkoutSelSirc); //set clokout to SIRC
SFA_GetDefaultConfig(&config); //Get SFA default config
config.mode = kSFA_FrequencyMeasurement0;
config.refSelect = kSFA_REFSelect1; //Set CPU clk as ref clk
config.cutSelect = kSFA_CUTSelect1; //Set clkout as CUT
config.refTarget = 0xFFFFFFUL;
config.cutTarget = 0xFFFFUL;
config.enableCUTPin = true;
freq = get_ref_freq_value(CPU_CLK);
SFA_SetMeasureConfig(DEMO_SFA_BASEADDR, &config);
SFA_MeasureNonBlocking(DEMO_SFA_BASEADDR);
while (1)
{
if (SfaMeasureFinished)
{
SfaMeasureFinished = false;
if(kStatus_SFA_MeasurementCompleted == sfa_callback_status)
{
freq = SFA_CalculateFrequencyOrPeriod(DEMO_SFA_BASEADDR, freq);//Calculate the FRO freq
if(FREQ_6MHZ + TOLERANCE <= freq )
{
ratio = 1;
}
else
{
if(FREQ_3MHZ + TOLERANCE <= freq)
{
ratio = 2;
}
else
{
if(FREQ_2MHZ + TOLERANCE <= freq)
{
ratio = 3;
}
else
{
ratio = 4;
}
}
}
break;
}
}
else
{
__WFI();
}
}
return ratio;
}
Result Interpretation and Usage
To test the FRO 6M after adding the above functions the FRO can be tested after executing:
The measured FRO6M frequency is printed to the serial terminal for human-readable diagnostics. Developers can use this result to:
Steps to Reconfigure Peripheral Clocking When FRO6M output frequency is lower
Use the SFA measurement as described earlier to determine if the FRO6M is operating below its expected frequency (6 MHz). If the result is significantly lower, proceed to reconfigure.
Most NXP MCUs offer multiple internal and external clock sources. Common alternatives include:
Choose one that is:
Use the SDK’s CLOCK_Set... APIs to change the clock source.
You may also need to:
Example Scenario: Measuring the FRO and Adjusting UART Based on Frequency Ratio
Imagine your application relies on the 6 MHz Free Running Oscillator (FRO), and its accuracy directly affects UART communication. To ensure reliable operation, you can use the System Frequency Adjustment (SFA) feature to monitor the FRO output and dynamically adjust the UART configuration.
After measuring the 6 MHz FRO using the recommended method, the system returns a frequency ratio value. This value ranges from 1 to 4, where:
Using this ratio, you can initialize and configure the UART peripheral and its driver to compensate for any frequency variation, ensuring stable and accurate communication.
*/
int main(void)
{
BOARD_InitHardware();
uint8_t ch = 0;
uint8_t FRO_ratio = 0;
init_SFA_peripheral();
/*Measure FRO6M output frequency*/
FRO_ratio = SFA_freq_measurment_6M_FRO();
/*Init debug console and compensate in case a different frequency is output */
if(0 == FRO_ratio)
{
assert(0);//this user defined return value means something went wrong while measuring 6Mz FRO
}
uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ/FRO_ratio;//Compensate the src frequency set for uart module
CLOCK_EnableClock(kCLOCK_Lpuart1);
CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro6M);
DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
......
}
SDK 25.0.00 Enhancements for FRO6M Calibration
To address known reliability issues with the 6 MHz Free Running Oscillator (FRO6M), particularly during transitions from low-power modes, SDK version 25.06.00 introduces a set of software enhancements aimed at improving oscillator validation and calibration.
Key Features Introduced
Two new functions have been added to facilitate runtime verification of the FRO6M frequency:
These functions provide a lightweight and efficient mechanism to detect and respond to oscillator misbehavior, ensuring system stability and timing accuracy.
Use Case and Benefits
These enhancements are particularly valuable in applications where:
By integrating these calibration routines, developers can proactively detect and correct FRO6M frequency anomalies, improving overall system robustness and reducing the risk of runtime errors due to clock instability.