2014-04-22 01:05 PM
Hello All,
I trying the following configuration of TIM4 on STM32L152
void Timer4Init(void) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
// Zero cross in - counter start CH3 PB8
GPIO_InitStructure.GPIO_Pin = ZERO_CROSS_TIM4_IN_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(ZERO_CROSS_TIM4_IN_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(ZERO_CROSS_TIM4_IN_PORT, ZERO_CROSS_TIM4_IN_PIN_SOURCE, GPIO_AF_TIM4);
/* Time base configuration -----------------------------------------------*/
TIM_TimeBaseStructure.TIM_Period = 10;
TIM_TimeBaseStructure.TIM_Prescaler = 20;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* TIM4 PWM2 Mode configuration: Channel1 -----------------------------------------------*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; //no GPIO output
TIM_OCInitStructure.TIM_Pulse = 1; //short impuls
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
/* configuration in Input Capture Mode -----------------------------------------------*/
//falling edge on PB8 starts timer
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
/* One Pulse Mode selection */
TIM_SelectOnePulseMode(TIM4, TIM_OPMode_Single);
/* Input Trigger selection ----------------------------------------------- */
TIM_SelectInputTrigger(TIM4, TIM_TS_TI3FP3);
/* Slave Mode selection: Trigger Mode */
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Trigger);
Timer4DMAInit();
}
and I'm getting errors on line:
TIM_SelectInputTrigger(TIM4, TIM_TS_TI3FP3);
TIM_TS_TI3FP3 is undefined but in datasheet RM0038 (page 341) I see it should be defined (see attached image).
What am I missing here? thanks and regards Tom #tim_ts_ti3fp3-tim4-stm32l12014-04-22 01:18 PM
2014-04-24 05:35 AM
Thanks Clive,
I don't know what the hell I was looking at ;)RegardsTom2014-04-24 06:05 AM
Thanks Clive,
So, as CH1 to CH3 as XORed I can still use TI1FP1 as trigger while the input signal is on TIMx_CH3 but I have to use input capture channel 1 ? RegardsTom