cancel
Showing results for 
Search instead for 
Did you mean: 

How can i configure Timer1 to generate an interrupt with 50 Hz ???

naceur2311
Associate II
Posted on May 21, 2013 at 20:37

I want to measure the frequency of an input signal with the STM32F4 Discovery Board. But i want to configure Timer 1 (in mode Input capture) to generate an interrupt every 50 Hz (or any other fixed value). How can i do this ???

Thank you.

7 REPLIES 7
Posted on May 21, 2013 at 20:55

So set up the timebase period and prescaler to divide the source clock down to 50 Hz. Factor in a manner of your choosing. Enable the Update interrupt

For an 84 MHz TIMCLK

Prescale = 28 - 1;

Period = 60000 - 1;

Your input compare will be a modulo 60000 value now. Ticks will be in 3 MHz units, ie 333.333 ns, update at 20 ms (50 Hz)

50 * 28 * 60000 = 84000000
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Jessy J
Associate II
Posted on June 11, 2018 at 11:58

HELLO

Turvey.Clive

I want to ask you how to know the value of TIMCLK please ??

I activated timer 14 for mode compare output no output mode and I want to set its interrupt every 100 ms

thank you for your reply in advance

henry.dick
Senior II
Posted on June 11, 2018 at 12:07

'

But i want to configure Timer 1 (in mode Input capture) to generate an interrupt every 50 Hz (or any other fixed value). '

since you are using the input capture mode to generate interrupts, you just need to configure the timer to interrupt on every rising / falling edge and feed it a 50Hz signal.

'How can i do this ???'

by coding to the datasheet.

the other approach highlighted earlier is incorrect.

Jessy J
Associate II
Posted on June 11, 2018 at 12:14

henry.****

I want to ask you how to know the value of TIMCLK please ??

Posted on June 11, 2018 at 13:41

Review the Clock Tree in the Reference Manual, the TIMCLK is derived from the APB Clock the TIM being used is attached too.

ie if APB1, in all cases other than the DIV1 setting the TIMCLK = APB1CLK * 2;

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 11, 2018 at 22:57

For what you are trying to do, the value in timclk is irrelevant - basically the in out pulse train determines the maximum frequency of (input capture) interrupts.

If you insist, two easy ways to know the value of timclk:

1. Go through the datasheet and your code.

2. Run your code in a debugger and inspect the register.

Jessy J
Associate II
Posted on June 14, 2018 at 10:27

Turvey.Clive

For an 84 MHz TIMCLK Prescale = 28 - 1;

Period = 60000 - 1;

Your input compare will be a modulo 60000 value now. Ticks will be in 3 MHz units, ie 333 ns, update at 20 ms (50 Hz)

50 * 28 * 60000 = 84000000

In cubMX in the configuration shall we write 28 as prescale value or 27 ?? same as periode value please ??

thank you for your reply