2014-01-22 02:35 AM
Hi,
I've got some problems with my F3Discovery. I have a perfectly working TIM2 PWM-input-capture, but if I want to change it to timer1 it does not call the interrupt handler at all anymore. The code for the initialisation is:void PwmInputInit(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* GPIOA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* TIM1 channel1 configuration : PA.08 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM pin to AF2 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);
/* Enable the TIM1 CC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1 ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
//dont know which is right, neither works...
TIM_ICInit(TIM1, &TIM_ICInitStructure);
//TIM_PWMIConfig(TIM1, &TIM_ICInitStructure);
/* Select the TIM1 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); // not sure, none of them works
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM1,TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM1, ENABLE);
/* Enable the CC1 Interrupt Request */
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
}
and the Interrupt handler (which is never called) is only
void TIM1_CC_IRQHandler(void)
{
STM_EVAL_LEDOn(LED7);
}
Anybody can help me which initialisation I forgot?
Thanks,
Michael
#pwminput #stm32f3 #timers
2014-01-22 04:11 AM
Hi
''/* Select the TIM1 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1); // not sure, none of them works'' '' /* Enable the CC1 Interrupt Request */ TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE); '' Timer1 is not the same type as Timer2 from the reference manual. Check the block diagram for Timer1. Make sure that the CaptureCompare output goes to CCR1. You have enabled the IRQ for CCR1.2014-01-22 05:26 AM
''Check the block diagram for Timer1. Make sure that the CaptureCompare output goes to CCR1. You have enabled the IRQ for CCR1.''
So how do I do that?! I searched through the datasheet for hours but cant find the solution. Especially because it is hard to find out which registers were already set by the
drivers functions.2014-01-22 06:51 AM
In the block diagram, I have circled the info you are looking for! However, this was taken for Timer2-5. I cannot see the section for Timer1 in the reference manual.
2014-01-22 07:08 AM
Sorry, The image paste did not work!
If you look at the block diagram in RM0038 (DocID15965 Rev 8) Page341 fig 82 : On the right ''TIMx_CH1'' is where the signal outputs the device. Inside the device it is labled ''OC1'' and links to box ''output control''. Next to that it shows which CCR register it uses. (A picture is worth a thousand words!)2014-01-22 09:09 AM
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM1/TIM8 are special, also make sure to fully qualifyTIM_ICInitStructure
2014-01-27 02:49 PM
thanks for your replys! I spent many hours on this until I figured out that the Pins I wanted to use are also used by some Discovery Board features and therefore can not be used.
Now I want to use Timer 4 instead, but with Input compare mode, not PWM mode. this way I can use all the 4 channels. It is not working perfectly yet but we will see ;)