Here is how I did it:
This is where I measure it:
/* We are using input capture with timer channel to measure the frequency.
* To build an average, we measure CHA_TICK_NOF_SAMPLES falling edges,
* and then divide the time by CHA_TICK_NOF_SAMPLES
*/
static uint32_t CHA_freqCharger; /* charger frequency in kHz */
#define CHA_TICK_NOF_SAMPLES 16 /* number of edges to count */
static U_Freq_TU1_TValueType CHA_Ticks[2]; /* array with the time for the first edge and the last one */
static int CHA_TicksIdx = 0; /* index into CHA_Ticks[] */
static volatile bool CHA_Ticks_Done = FALSE, CHA_Ticks_Overflow = FALSE;
void CHA_OnCounterRestart(void) {
CHA_Ticks_Overflow = TRUE;
U_Freq_TU1_Disable(U_Freq_TU1_DeviceData); /* disable timer */
}
void CHA_OnChannel0(void) {
if (CHA_TicksIdx==0) {
(void)U_Freq_TU1_GetCaptureValue(U_Freq_TU1_DeviceData, 0, &CHA_Ticks[0]);
} else if (CHA_TicksIdx==CHA_TICK_NOF_SAMPLES) {
(void)U_Freq_TU1_GetCaptureValue(U_Freq_TU1_DeviceData, 0, &CHA_Ticks[1]);
U_Freq_TU1_Disable(U_Freq_TU1_DeviceData); /* disable timer */
CHA_Ticks_Done = TRUE;
}
CHA_TicksIdx++;
}
void CHA_MeasureFrequency(void) {
int32_t cntrUs;
#define WAIT_TIME_US 100
CHA_Ticks_Done = CHA_Ticks_Overflow = FALSE; /* init flags */
CHA_TicksIdx = 0;
cntrUs = 200; /* wait for max 200 us */
(void)U_Freq_TU1_ResetCounter(U_Freq_TU1_DeviceData);
U_Freq_TU1_Enable(U_Freq_TU1_DeviceData);
while(!CHA_Ticks_Done && !CHA_Ticks_Overflow && cntrUs>=0) {
/* wait for the number of edges or timer overflow */
WAIT1_Waitus(WAIT_TIME_US); /* busy-wait, as in tickless idle mode we will not get interrupts */
cntrUs -= WAIT_TIME_US;
}
if (!CHA_Ticks_Overflow) { /* overflow ISR already disabled the device */
U_Freq_TU1_Disable(U_Freq_TU1_DeviceData); /* disable device */
}
if (CHA_Ticks_Done) {
CHA_freqCharger = (U_Freq_TU1_CNT_INP_FREQ_U_0/1000)/((CHA_Ticks[1]-CHA_Ticks[0])/CHA_TICK_NOF_SAMPLES); /* in kHz */
} else { /* Time out. Period of measured signal is too long */
CHA_freqCharger = 0; /* no value measured */
}
}
I'm counting the numer of falling edges, for a given period, and then calculate the frequency based on the number of samples/period.
The events get called from Events.c:
/*
** ===================================================================
** Event : U_Freq_TU1_OnCounterRestart (module Events)
**
** Component : U_Freq_TU1 [TimerUnit_LDD]
*/
/*!
** @brief
** Called if counter overflow/underflow or counter is
** reinitialized by modulo or compare register matching.
** OnCounterRestart event and Timer unit must be enabled. See
** [SetEventMask] and [GetEventMask] methods. This event is
** available only if a [Interrupt] is enabled.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. The pointer passed as
** the parameter of Init method.
*/
/* ===================================================================*/
void U_Freq_TU1_OnCounterRestart(LDD_TUserData *UserDataPtr)
{
CHA_OnCounterRestart();
}
/*
** ===================================================================
** Event : U_Freq_TU1_OnChannel0 (module Events)
**
** Component : U_Freq_TU1 [TimerUnit_LDD]
*/
/*!
** @brief
** Called if compare register match the counter registers or
** capture register has a new content. OnChannel0 event and
** Timer unit must be enabled. See [SetEventMask] and
** [GetEventMask] methods. This event is available only if a
** [Interrupt] is enabled.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data. The pointer passed as
** the parameter of Init method.
*/
/* ===================================================================*/
void U_Freq_TU1_OnChannel0(LDD_TUserData *UserDataPtr)
{
CHA_OnChannel0();
}
}
I'm using the TimerUnit_LDD as input capture:

The input capture is configured like this:

I hope this helps.
Erich