TIM_InputCapture_Init Example Description

Use of the TIM peripheral to measure a periodic signal frequency provided either by an external signal generator or by another timer instance. This example is based on the STM32C0xx TIM LL API. The peripheral initialization uses LL unitary service functions for optimization purposes (performance and size).

TIM1_CH1 is configured in input capture mode. The TIM1CLK frequency is set to its maximum value (Prescaler is /2 * 2 = 1) in order to get the best possible resolution. So the TIM1 counter clock is SystemCoreClock.

SystemCoreClock is set to 48 MHz for STM32C0xx Devices.

The “uwMeasuredFrequency” variable contains the measured signal frequency. It is calculated within the capture/compare 1 interrupt service routine.

The minimum frequency value to measure is TIM1 counter clock / TIMx_CCR1 MAX = 48 MHz / 65535

Due to TIM1 interrupt routine processing time (around 1.4us), the maximum frequency value to measure is around 700 KHz.

TIM3_CH1 is configured to generate a PWM signal. User push-button can be used to change the frequency of this signal from 2 kHz up to 20 kHz by steps of 2 kHz. It is then possible to run this example without a signal generator by connecting TIM3_CH1 to TIM1_CH1.

Keywords

Timers, Frequency, Input, Capture, External Signal, Measurement

Directory contents

Hardware and Software environment

How to use it ?

In order to make the program work, you must do the following :