2013-08-14 05:25 AM
Strange problem...Timer 2 works great when debugging. When I turn my supply off and reboot, everything is hunky dory except timer2. Any clues?
TIM_DeInit(TIM2);
//ENABLE CLOCKS
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//TIM2 INIT
TIM_TimeBaseInitTypeDef TIM2_struct; TIM2_struct.TIM_ClockDivision = 0; TIM2_struct.TIM_CounterMode = TIM_CounterMode_Up; TIM2_struct.TIM_Period = 4000; //Timer2 is clcoked at 48MHz with prescaler of 0; SOLVE(1/48000000 * X = 1/8000, X) gives interrupt time of 100uS when being used. Perfect for our SPI TIM2_struct.TIM_RepetitionCounter = 0; //This is only valid for timer 1 and 8TIM_TimeBaseInit(TIM2, &TIM2_struct);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
TIM_ARRPreloadConfig(TIM2, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE); //INTERRUPT CONFIG NVIC_InitTypeDef TIM2_isr_struct; TIM2_isr_struct.NVIC_IRQChannel = TIM2_IRQn; TIM2_isr_struct.NVIC_IRQChannelCmd = ENABLE; TIM2_isr_struct.NVIC_IRQChannelPreemptionPriority = 0; TIM2_isr_struct.NVIC_IRQChannelSubPriority = 1;NVIC_Init(&TIM2_isr_struct);
/* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 , ENABLE);2013-08-14 05:45 AM
What is hunky dory?
How do you know that the ISR is not firing? Post a minimal but complete compilable example exhibiting the problem. JW2013-08-14 06:31 AM
Hunky dory is just saying all is fine.
If I place the following code in the isr, it makes a square wave when debugging. Then stops when I reboot. This tells me that the isr is not firing. if(toggle) GPIO_SetBits(GPIOF, GPIO_Pin_0); else GPIO_ResetBits(GPIOF, GPIO_Pin_0); toggle = !toggle;2013-08-14 07:12 AM
The request for minimal but functional code has several purposes, one of them is to give the OP an impulse to rethink his problem. Other is to increase chances that somebody else is willing to have a look at it.
You neglect to initialize your TIM_TimeBaseInitStruct, namely the prescaler field. JW2013-08-14 07:28 AM
If this is C++ (mid function variables), then make sure it's not mangling the IRQHandler name.
Also not sure the reason for CC1 and Pulse=0, might make more sense to use Update? Finally, needs 4000-1 for the period, and as Jan mentions the Prescaler is probably some random stack junk at this point.2013-08-14 11:39 AM
Thanks for the replies. It was the prescaler. Stupid mistake. Overlooked that one for many hours.