|
Input Capture Library (STM32F4)
To measure the frequency and duty cycle of a PWM signal, I created these libraries.
(there is also an extra LIB if only the frq should be measured)
There is one library each for the timers "TIM2, TIM3, TIM4, TIM5".
The timers are operated in PWM InputCapture mode, with MasterSlave and Autoreset. The interrupt function is triggered by the signal at each hi-edge and determines the period duration and the pulse length of the signal.
Only one signal can be measured per timer in this mode. And there are only channels 1 or 2 available.
The channel and port pin to be used must be entered in the C file.
In the H-file, the clock frequency is set by the timer. This affects the resolution and the minimum frequency that can be measured.
Note: the function for reading the frequency only transfers the timer value of the period. The conversion into a frequency must be made extra if necessary. If there is no signal (or the measurement is not finished yet), the return value = 0. This means that a missing signal can be detected.
Image :
|
|