PSoC 6 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...
 
int32_t Cy_SysClk_PiloTrim (uint32_t piloFreq)
 Trims the PILO to be as close to 32,768 Hz as possible. 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_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 using
the ECO. All peripherals clocked using the PILO are disabled. */
#define ECO_FREQ 24000000UL /* 24 MHz ECO */
/* 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);
/* Attempt to trim the PILO by 1 iteration step */
uint32_t trimDelta = Cy_SysClk_PiloTrim(measuredFreq);
if(0UL != trimDelta)
{
/* Not yet trimmed to nominal 32.768 kHz. Repeat measurement and trim. */
}