cancel
Showing results for 
Search instead for 
Did you mean: 

STM32(F4) Timers - many different varieties, with different features and functionality. Very hard to understand from the datasheet which to use for what, timing, pwm output, external pulse counter etc. Any clear guidance to be found?

Alexmouse
Senior

I had an application that demanded input counter mode, and the four timers I picked (10, 11, 13, 14) turned out to be unable to perform this function.

9 REPLIES 9
Imen.D
ST Employee

Hello @Alexmouse​ ,

The reference manual of your STM32F4 products detailed the features that you need.

You can also have a look at these resources:

  • AN4013 Application note STM32 cross-series timer overview (present the various modes and features of the timer peripherals and explain how to use them)
  • AN4776 Application note General-purpose timer cookbook for STM32 microcontrollers

Hope my answer helped you!

When your question is answered, please close this topic by choosing "Select as Best".

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Alexmouse
Senior

I couldn't find a clear answer in the part datasheet (F407) or family reference manual.

I want to count pulses on four incoming channels, and had tried to use timers 10, 11, 13 & 14, but it seems they can't do this.

I would have thought it a pretty basic function but I can't see it described in these documents.

Am I missing something?

This is one of these due diligence, learn by doing exercises.

I'd take the Data Sheet and identify all the TIM*_ETR pins on the device(s) (pin count) I was interested in.

Most would also perhaps work in Encoder Mode via CH1/CH2 in a pinch.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Alexmouse
Senior

It is a sad reflection upon the data sheet if the only way to determine device behaviour is by trial and error.​ it would be helpful if the timer variants were tabulated against operating modes. I don't recall any mention of pulse counter functionality, even against the two timers apparently capable of this operation. I found a solution, but less than optimal.

> I want to count pulses on four incoming channels,

There's only one counter in each timer.

JW

I'm aware there's one counter per channel. I made it work on timers 10, 11, 13 and 14, but it is less than optimal. My request was for clearer documentation explaining the types of timer and operating modes. I've seen the app notes, cookbooks etc. But none address the simple input pulse stream counting application.

> I'm aware there's one counter per channel.

No, there is one counter per *timer*, not per *channel*. The formulation of some of your posts sounds much like you would like to count on multiple channels of one timer.

What you call "pulse stream counting" is called "external clock" in the STM32 realm, and is described directly in RM, in the TIM chapter in the External clock source mode 1 and External clock source mode 2 subchapters.

RM0090 in the TIM9-TIM12 chapter's Clock selection subchapter (which contains the external clock modes description) quite clearly states, that external clock mode is available only for TIM9 and TIM12 out of the bunch; it's even said there in bold typeface. Absence of TIMx_SMCR in TIM10/11/13/14 is a clear indication of the same. It's also quite obvious if you look at General-purpose timer block diagram (TIM10/11/13/14) figure at the beginning of the TIM9-TIM12 chapter, expecially if you compare it to the similar block diagrams for other timers - for TIM10/11/13/14, the clock straighforwardly comes from the internal clock only, as compared to clock being fed from the Slave-mode controller on the block diagram for other timers.

The external clock how these modes are selected through the TIMx_SMCR register. While it's not directly said, it quite straighforwardly indicates (similarly to the block diagrams) that it's the role of the slave-mode controller to select the clock (together with some other features, e.g. the encoder mode and the "synchronization" features like triggering and resetting from sources outside of the given timer). Then, if you refer to AN4013 Imen gave link to above, you can see in Table 4 that the single-channel timers don't have the "slave synchronization" features; the previous two tables help you to identify which timers for given family belong to which cathegory, including single-channel timers, to which the TIM10/11/13/14 in 'F407 belong.

I don't say the documentation can't be written clearer or can't be improved, but then it's also quite difficult to cater for all possible specific questions which may come up, in description of a relatively complex circuitry, so you might be required to read the whole chapter carefully to find the answers.

JW

Yes, that thread helped me find a workaround. In hindsight it is easier to understand, but I know I'm not alone in finding the data sheet description challenging. ​