cancel
Showing results for 
Search instead for 
Did you mean: 

F4 Timers - frequency divider?

martinmartin9129
Associate II
Posted on March 28, 2013 at 12:14

Hello,

sorry for maybe stupid question, but I can't understand - how to make the frequency divider using STM32F4's timers?

I mean how to divede the frequency of the external signal and output it from CPU?

Tnanks.

#stm32-timer
10 REPLIES 10
Posted on March 28, 2013 at 12:33

This is far from being simple (any non-trivial use of the STM32 timers is, given their complexity).

First, you'd need to use one of the external clock modes, there are two of them. You'll find the details under ''Clock selection'' in the Timer chapter of manual.

Then you need to run the timer as counter, perhaps setting the autoreload value (TIMx_ARR register) to the desired ''divider'' value.

Then you need to output the ''divided'' clock. One of the options is to set one of the CC units to Compare, set half the ARR value to it, and set one of the PWM modes.

JW

Posted on March 28, 2013 at 12:41

What kind of frequencies are we talking about? What kind of division, fixed, range?

There are often much better solutions than the micro, and it's timers. The STM32 is endowed with some pretty lame integer dividers, so not the most flexible choice for clock generation.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
martinmartin9129
Associate II
Posted on March 28, 2013 at 14:21

Hi CLive,

I'm talcking about frequencies 30-40MHz and not binary division  - 3, 5, etc.

All hardware solutions that I know, are more then one logic chip (2-3), cost is not an issue, but pcb space - yes.

jj2
Associate II
Posted on March 28, 2013 at 14:49

Better to include such (30-40MHz) spec w/in initial post.  (and - Jan deserves some acknowledgement)

These are RF (HF band) frequencies - seems that an RF ''Mixer'' may be a better means to ''scale'' these - so they better ''fit'' MCU handling.

As Clive states - these MCUs not ''best/brightest'' for this task - far simpler/smaller logic ICs may be better alternative...

martinmartin9129
Associate II
Posted on March 28, 2013 at 14:59

OK, its a pity :(

jpetersen
Associate
Posted on March 28, 2013 at 15:18

Have you tried a PLD?  I think you could do it with a single chip rather than the 2-3 you're talking about.

jj2
Associate II
Posted on March 28, 2013 at 15:47

Alex: ''its a pity :(''

Or not!

MCU is much like race-horse - should not be used for ''all tasks.''

Might your need instead have been for a certain, ''frequency generation?''  While dividing down an existing frequency has appeal - the 30-40MHz is bit much for most MCUs.

The MCU is quite good at generating various frequencies - often eased by use of an MCU Timer operated in PWM Mode.  (enables fine control of both freq. and duty cycle)

Too often - a vague ''specification'' produces limited or incorrect response...

Posted on March 28, 2013 at 17:27

Perhaps I2S could be abused for this task, using the external clock input into PC9 and and MCK output onto PC6.

But I am afraid the smallest possible odd divider would be 5.

JW

Posted on March 28, 2013 at 17:32

Have you tried a PLD?  I think you could do it with a single chip rather than the 2-3 you're talking about.

The logic in question would certainly fit in a PAL type device, perhaps there is some other logic or function you can mop up with a small programmable part?

Other potential avenues are to clock the STM32F4 with an external source, or slave an SPI port into sending out a waveform/bitstream in a cyclic fashion.

The resynchronizer on the front end of the STM32 timer pins might also add quite a lot of jitter to a 40 MHz signal.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..