cancel
Showing results for 
Search instead for 
Did you mean: 

help with a millisecond timer

gilmotta
Associate
Posted on September 24, 2009 at 16:46

help with a millisecond timer

3 REPLIES 3
gilmotta
Associate
Posted on May 17, 2011 at 13:24

I'm trying to create a millisecond timer but it is not working. Perhaps my understanding of how the timer works is not solid so I would like to ask for some help.

I'm using the following parameters to create my mS timer:

assuming

/* PCLK2 = HCLK */

RCC_PCLK2Config(RCC_HCLK_Div1); // 72Mhz

/* PCLK1 = HCLK/2 */

RCC_PCLK1Config(RCC_HCLK_Div2); // 36Mhz

then I created the following:

TelTimersSetConfiguration TIM7,

TIM7_IRQChannel,

13, // priority

32, // prescaler

22500, // period

TIM_CounterMode_Up, // counter mode

TIM_CKD_DIV1,

0) // repetition

My formula to calculate these numbers is:

Period=72000000/(100*32)

however my interrupts are occuring every 100us.

What do you think is wrong?

Thanks very much.

[ This message was edited by: gilmotta on 24-09-2009 19:45 ]

bagrowicz
Associate II
Posted on May 17, 2011 at 13:24

For 36MHz -> 36 000 000 / (3 600 * 10) = 1000 cycles

1s / 1000 cycles = 0.001s = 1ms :-]

Try something like this for 36MHz:

TIM_TimeBaseStructure.TIM_Period = 3600;

TIM_TimeBaseStructure.TIM_Prescaler = 10;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;

Or for 72MHz

TIM_TimeBaseStructure.TIM_Period = 7200;

TIM_TimeBaseStructure.TIM_Prescaler = 10;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;

It's works for me. I've got nice 1ms period :)

tomas23
Associate II
Posted on May 17, 2011 at 13:24

What's inside the function? Is it yours or from some library?

Btw. with the parameters set, I'd expect 10 ms interrupts, not 100 us. If you enter such parameters, 72 MHz/(32*22500)=100 Hz.

Did you check with the scope (using eg. SEV instruction or GPIO toggling in interrupt)?

Tomas