2009-09-24 07:46 AM
help with a millisecond timer
2011-05-17 04:24 AM
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 ]2011-05-17 04:24 AM
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 :)2011-05-17 04:24 AM
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