2015-03-14 03:40 AM
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 timer2015-03-14 06:33 AM
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.2015-03-14 08:40 AM
Thank you Clive.
Colin