cancel
Showing results for 
Search instead for 
Did you mean: 

PWM input works on TIM2 Ch2 but not Ch3

colinconstant
Associate II
Posted on March 14, 2015 at 11:40

Hi, I'm measuring the pulse width on one line, using TIM2. Everthing is fine if I use Ch2 (on PD4 or PB3) but I can't get a reading using Ch3 (on PD7).

I'm using : TIM_GetCapture1(TIM2)

Here is the init code, thanks very much for any ideas.

  //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //PB3

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);  //PD4 or PD7

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);   //enable the TIM2 clock

 

 /* Pin configuration */

  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;   

  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(GPIOB, &GPIO_InitStructure);  //PB3

 GPIO_Init(GPIOD, &GPIO_InitStructure);  //PD4 or PD7

 

  //GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_1); //PB3 and AF1

  GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_2); //PD7 and AF2

 

 /* Input configuration */

 //TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; //PB3 or PD4

 TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;  //PD7

  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;

  TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);

 TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);

  TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

  TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);

 

  TIM_Cmd(TIM2, ENABLE); //enable timer

2 REPLIES 2
Posted on March 14, 2015 at 14:33

PWM Input pairs channel 1 and 2, where TS_TI2FP2 selects channel 2.

Channel 3 and 4 are not options provided by the hardware. You'd have to use Input Capture and delta multiple measurements to compute period/duty.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
colinconstant
Associate II
Posted on March 14, 2015 at 16:40

Thank you Clive.

Colin