2014-03-27 02:12 AM
Hello, I want to capture PWM input with TIM_CH3/TIM3_CH4 is that possible? Because I tried my code, and it cannot be shown when I observed the register either CCR1 for duty cycle or CCR2 for frequency.
This is my code :RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time Base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xFF0;
TIM_TimeBaseStructure.TIM_Prescaler = 0x22;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/* TIM3 Channel3 Configuration ---------------------------------------------------*/
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
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_ICInit(TIM8, &TIM_ICInitStructure);
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
/* Select the TIM3 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
TIM_CtrlPWMOutputs(TIM3, ENABLE);
Thank you in advance.
#pwm #input #ch3 #ch4
2014-03-27 04:05 AM
CH1/CH2 pair, as do CH3/4, please review the block diagram more critically.
Thus you results will be in CCR3 and CCR4 respectively, and you'd interrupt on CC42014-03-27 09:18 AM
Hello clive, thank you very much for your respond. I have tried your suggestions to look at register CCR3 and CCR4, but it is no different. Is there something wrong with my code? Despite TIM8 in the code, its my mistake not to change it first. :) Is TIM_SelectInputTrigger must be change? What is the right mode in GPIO Configuration for PWM input? Thank you very much.
2014-03-27 08:32 PM
It might be difficult to reset the counter via ch3/4. What you could do is use CH3/4 to in input capture mode, and have the two channels capturing on opposite edges of the signal, and then using the values to compute period and duty.