cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 Input PWM TIM3_CH3/TIM3_CH4

liviana
Associate II
Posted on March 27, 2014 at 10:12

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
3 REPLIES 3
Posted on March 27, 2014 at 12:05

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 CC4

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
liviana
Associate II
Posted on March 27, 2014 at 17:18

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.

Posted on March 28, 2014 at 04:32

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..