MTB CAT1 Peripheral driver library

General Description

Functions

int32_t Cy_SysClk_IloTrim (uint32_t iloFreq)
 Trims the ILO to be as close to 32,768 Hz as possible. More...
 
void Cy_SysClk_IloSetTrim (uint32_t trimVal)
 Set ILO Trim Value. More...
 
uint32_t Cy_SysClk_IloGetTrim (void)
 Gets the ILO Trim Value. More...
 
int32_t Cy_SysClk_PiloTrim (uint32_t piloFreq)
 Trims the PILO to be as close to 32,768 Hz as possible. More...
 
void Cy_SysClk_PiloInitialTrim (void)
 Initial trims the PILO to be as close to 32,768 Hz as possible. More...
 
void Cy_SysClk_PiloUpdateTrimStep (void)
 Calculates and updates the PILO trim step size (stepSize variable). More...
 

Function Documentation

◆ Cy_SysClk_IloTrim()

int32_t Cy_SysClk_IloTrim ( uint32_t  iloFreq)

Trims the ILO to be as close to 32,768 Hz as possible.

Parameters
iloFreqcurrent ILO frequency. Call Cy_SysClk_StartClkMeasurementCounters and other measurement functions to obtain the current frequency of the ILO.
Returns
Change in trim value - 0 if done; that is, no change in trim value.
Note
The watchdog timer (WDT) must be unlocked before calling this function.
Function Usage
/* Scenario: ILO needs to be trimmed to +/- 1.5% of nominal 32.768 kHz using
the IMO. The WDT is unlocked and all peripherals clocked using
the ILO are disabled. */
#define IMO_FREQ 8000000UL /* 8 MHz IMO */
/* Start the ILO clock measurement using the IMO */
(void)Cy_SysClk_StartClkMeasurementCounters(CY_SYSCLK_MEAS_CLK_ILO, /* Counter 1 clock = ILO */
0x7FUL, /* Counter 1 period = 128 */
CY_SYSCLK_MEAS_CLK_IMO); /* Counter 2 clock = IMO */
/* Wait for counter 1 to reach 0 */
/* Measure clock 1 with the IMO clock cycles (counter 2) */
uint32_t measuredFreq = Cy_SysClk_ClkMeasurementCountersGetFreq(false, IMO_FREQ);
/* Attempt to trim the ILO by 1 iteration step */
int32_t trimDelta = Cy_SysClk_IloTrim(measuredFreq);
if(0 != trimDelta)
{
/* Not yet trimmed to 1.5% of nominal 32.768 kHz. Repeat measurement and trim. */
}

◆ Cy_SysClk_IloSetTrim()

void Cy_SysClk_IloSetTrim ( uint32_t  trimVal)

Set ILO Trim Value.

Parameters
trimValTrim value to be set for ILO.
Note
The function is applicable only for a CAT1B Devices.

◆ Cy_SysClk_IloGetTrim()

uint32_t Cy_SysClk_IloGetTrim ( void  )

Gets the ILO Trim Value.

Returns
ILO Trim Value.
Note
The function is applicable only for a CAT1B Devices.

◆ Cy_SysClk_PiloTrim()

int32_t Cy_SysClk_PiloTrim ( uint32_t  piloFreq)

Trims the PILO to be as close to 32,768 Hz as possible.

Parameters
piloFreqcurrent PILO frequency. Call Cy_SysClk_StartClkMeasurementCounters and other measurement functions to obtain the current frequency of the PILO.
Returns
Change in trim value; 0 if done, that is, no change in trim value.
Function Usage
/* Scenario: PILO needs to be trimmed to +/-250 ppm of nominal 32.768 kHz
All peripherals clocked using the PILO are disabled. */
#define ECO_FREQ 24000000UL /* 24 MHz ECO */
#ifdef CY_IP_MXBLESS
/* Call PILO Initial trim */
/* Find out and store step size into stepSize variable */
#endif /* CY_IP_MXBLESS */
/* Start the PILO clock measurement using the ECO */
(void)Cy_SysClk_StartClkMeasurementCounters(CY_SYSCLK_MEAS_CLK_PILO, /* Counter 1 clock = PILO */
0x3FFUL, /* Counter 1 init value = 1024 */
CY_SYSCLK_MEAS_CLK_ECO); /* COunter 2 clock = ECO */
/* Wait for counter 1 to reach 0 */
/* Measure clock 1 with the ECO clock cycles (counter 2) */
uint32_t measuredFreq = Cy_SysClk_ClkMeasurementCountersGetFreq(false, ECO_FREQ);
uint32_t trimDelta;
do
{
/* Attempt to trim the PILO with calculated stepSize via */
trimDelta = Cy_SysClk_PiloTrim(measuredFreq);
}while (0UL != trimDelta);

◆ Cy_SysClk_PiloInitialTrim()

void Cy_SysClk_PiloInitialTrim ( void  )

Initial trims the PILO to be as close to 32,768 Hz as possible.

This function takes ECO ALTHF as reference clock and calculate Fine PILO frequency trimming, by using binary search algorithm.

This function requires configured BLE ECO ALTHF clock. Use ModusToolbox Device Configurator to configure BLE ECO ALTHF clock.

Note
This function must be call after every power-up.
Function Usage
/* Perform initial PILO trimming and update the trim step size.
* \note:
* 1. Call those functions after every power-up.
* 2. Those functions require a configured BLE ECO ALTHF clock.
* Use ModusToolbox Device Configurator to configure the BLE ECO BLE ECO ALTHF
* clock. The recommended frequency is 16 Mhz. */

◆ Cy_SysClk_PiloUpdateTrimStep()

void Cy_SysClk_PiloUpdateTrimStep ( void  )

Calculates and updates the PILO trim step size (stepSize variable).

The stepSize value is used by Cy_SysClk_PiloTrim function during periodical PILO calibration.

This function requires configured BLE ECO ALTHF clock. Use ModusToolbox Device Configurator to configure BLE ECO ALTHF clock.

Note
This function must be call after every power-up after call of Cy_SysClk_PiloInitialTrim function.
To achieve best trimming results it is recommended to configure BLE ECO ALTHF reference clock to 16 MHz.
Function Usage
/* Perform initial PILO trimming and update the trim step size.
* \note:
* 1. Call those functions after every power-up.
* 2. Those functions require a configured BLE ECO ALTHF clock.
* Use ModusToolbox Device Configurator to configure the BLE ECO BLE ECO ALTHF
* clock. The recommended frequency is 16 Mhz. */