CAT2 Peripheral Driver Library

Functions

cy_en_sysclk_status_t Cy_SysClk_CalibStart (cy_en_meas_clks_t clock1, uint16_t count1, cy_en_meas_clks_t clock2)
 Assigns clocks to the clock measurement counters, and starts counting. More...
 
uint32_t Cy_SysClk_CalibGetFreq (bool measuredClock, uint16_t count1)
 Calculates the frequency of the indicated measured clock (clock1 or clock2). More...
 
bool Cy_SysClk_CalibDone (void)
 Checks if clock measurement counting is done, that is, counter1 has counted down to zero. More...
 

Detailed Description

Function Documentation

◆ Cy_SysClk_CalibStart()

cy_en_sysclk_status_t Cy_SysClk_CalibStart ( cy_en_meas_clks_t  clock1,
uint16_t  count1,
cy_en_meas_clks_t  clock2 
)

Assigns clocks to the clock measurement counters, and starts counting.

The counters let you measure a clock frequency using another clock as a reference. There are two counters.

  • One counter (counter1), which is clocked by clock1, is loaded with an initial value and counts down to zero.
  • The second counter (counter2), which is clocked by clock2, counts up until the first counter reaches zero.

Either clock1 or clock2 can be a reference clock; the other clock becomes the measured clock. The reference clock frequency is always known.
After calling this function, call Cy_SysClk_CalibDone() to determine when counting is done; that is, counter1 has counted down to zero. Then call Cy_SysClk_CalibGetFreq() to calculate the frequency of the measured clock.

Parameters
clock1The clock for counter1
count1The initial value for counter1, from which counter1 counts down to zero.
clock2The clock for counter2
Returns
Error / status code:
CY_SYSCLK_INVALID_STATE if already doing a measurement
CY_SYSCLK_BAD_PARAM if invalid clock input parameter. Source have zero frequency. Or overflow expected
else CY_SYSCLK_SUCCESS
Note
The counters are both 16-bit, so the maximum value of count1 is 0xFFFF. If clock2 frequency is greater than clock1, make sure that count1 is low enough that counter2 does not overflow before counter1 reaches zero.
The time to complete a measurement is count1 / clock1 frequency.
The clocks for both counters must have a nonzero frequency, or Cy_SysClk_CalibGetFreq() incorrectly reports the result of the previous measurement.
Both clock1 and clock2 clocks must be running or the measurement will not complete.
Due to internal clock synchronization count1 should be at least 5 times the 1/frequency2.
Do not enter a device low power mode (Sleep, Deep Sleep) while doing a measurement; the measured clock frequency may not be accurate.
The calibration counters are available only in Active/Sleep modes. Counter values are not retained and will be in default state after wakeup from deepsleep.
Function Usage
/* set clock1 (time window) as HPOSC
* set clock2 (low frequency) as ILO
* set time window as 0xFFFF counts of the HPOSC
*/
if (retVal == CY_SYSCLK_SUCCESS)
{
/* get real ILO frequency */
/*
* measured clock is clock2 = true,
* time window was 0xFFFF counts of the clock1
*/
frequency = Cy_SysClk_CalibGetFreq(true, 0xFFFF);
}

◆ Cy_SysClk_CalibGetFreq()

uint32_t Cy_SysClk_CalibGetFreq ( bool  measuredClock,
uint16_t  count1 
)

Calculates the frequency of the indicated measured clock (clock1 or clock2).

  • If clock1 is the measured clock, its frequency is: clock1 frequency = (count1 / count2) * clock2 frequency
  • If clock2 is the measured clock, its frequency is: clock2 frequency = (count2 / count1) * clock1 frequency

Call this function only after counting is done; see Cy_SysClk_CalibDone().

Parameters
measuredClockFalse (0) if the measured clock is clock1; true (1) if the measured clock is clock2.
count1The initial value for counter1, from which counter1 counts down to zero. See Cy_SysClk_CalibStart()
Returns
The frequency of the measured clock, in Hz.
Warning
The function returns zero, if during measurement device was in the Deep Sleep or partially blocking flash operation occurred. It means that current measurement is not valid and you should call the Cy_SysClk_CalibStart() function once again.
Function Usage
/*
* measured clock is clock2 = true,
* time window was 0xFFFF counts of the clock1
*/
frequency = Cy_SysClk_CalibGetFreq(true, 0xFFFF);

◆ Cy_SysClk_CalibDone()

bool Cy_SysClk_CalibDone ( void  )

Checks if clock measurement counting is done, that is, counter1 has counted down to zero.

Call Cy_SysClk_CalibStart() before calling this function.

Returns
Status of calibration counters:
true = done
false = in progress