2013-08-21 07:41 AM
My timebase for TIM3 does seem to obey the laws of timebase calculation! I think I've had this problem before, what am I doing wrong.
TIMCLK = 36MHz TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* Time Base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 10 - 1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* TIM enable counter */ TIM_Cmd(TIM3, ENABLE); /* Enable the Interrupt Request */ TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);And in my ISR: GPIOB->ODR ^= GPIO_Pin_0; TIM_ClearITPendingBit(TIM3, TIM_IT_Update);When I use the above, the pulse width of my trace on PB0 is 5ms. Shouldn't it be 10ms?Also when I use Pre = 36000 and Period of anything greater than 2000, the ISR never fires. I'm trying to get a toggle greater than 1sec.2013-08-21 08:19 AM
According to the Clock Tree for TIM2,3, 4 ''If (APB1 prescaler =1) x1 else x2''.
Likely your clock is 72MHz?2013-08-21 08:27 AM
1 Hz interrupt should be
TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1; TIM_TimeBaseStructure.TIM_Period = 2000 - 1; Period 4000 - 1 for 0.5 Hz (2 sec) Period 8000 - 1 for 0.25 Hz (4 sec) Period can be up to 65535 for 16-bit timers Be sure to also enable NVIC for TIM interrupt If you don't get an update interrupt, then something else is wrong.2013-08-21 08:38 AM
Verified in debug, PCLK1 = 36MHZ.
I went back to the 3210E demo board to make sure I don't have a hardware problem.Here's what the scope tells me:36000/2000 = 1sec int36000/4000 = nothing36000/1000 = 500ms2013-08-21 08:40 AM
Found the problem, I have some ADC stuff in the ISR that was hanging it up.
Thanks!2013-08-21 08:43 AM
TIM3CLK = PCLK1 * 2, per Clock Tree
36000/4000 = nothing Yes, that would be bizarre. Present a complete example.