cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F3 PWM input

micha2
Associate II
Posted on January 22, 2014 at 11:35

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
6 REPLIES 6
chen
Associate II
Posted on January 22, 2014 at 13:11

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.

micha2
Associate II
Posted on January 22, 2014 at 14:26

''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.
chen
Associate II
Posted on January 22, 2014 at 15:51

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.

chen
Associate II
Posted on January 22, 2014 at 16:08

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!)

Posted on January 22, 2014 at 18:09

TIM_CtrlPWMOutputs(TIM1, ENABLE);

TIM1/TIM8 are special, also make sure to fully qualify

TIM_ICInitStructure

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
micha2
Associate II
Posted on January 27, 2014 at 23:49

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 ;)