AnsweredAssumed Answered

4 channel frequency measurement on a single timer

Question asked by gip.jack on Jul 7, 2015
Latest reply on Jul 7, 2015 by Clive One
I've been testing a STM32F4 Discovery since I'm new to ST Microcontrollers and I wanted to use one timer to measure 4 different channel frequencies, as I want to measure more signals than there are timers. I do not care about PWM widths etc. For example, use TIM4 to measure the frequency of different digital signals on the TIM4 channels 1 to 4.

Using STM32CubeMX with the default settings with the following changes to TIM4, quickly managed to get the 4 capture/compare registers to copy the counter value on each active edge. I let the counter count to a value of 0xFFFF (ARR) before it resets to 0x0.


Although this is only good for first frequency measurement when the capture/compare registers (CCRx where x is channel) are their default value 0, since the period of the signal is the difference between the final and initial counter values: CCRx - 0

Is it possible to measure frequency using this method after the first active edge, i.e. once the CCRx registers are not their default value for the initial counter value?

On Figure 160 of the reference manual, it looks like it might be possible. I was thinking enabling capture and capture_transfer signals at exactly the same time so on each channels active edge, the value of the counter gets transferred to the shadow register and then on the next active edge, transfer into the preload register, like a 2 stage shift register. This shift register action happens continuously. Then when you want the frequency, disable both  capture and capture_transfer signals of Figure 160 at exactly the same time so they no longer update continuously, and use the MCU to get the preload and shadow register values to calculate the difference in counter values, determining the period. Does that sound logical or possible for this microcontroller?

In all other examples they only measure the frequency of only one channel for a timer, as they reset the counter on each active edge of one channel, then read counter value for the period.