Question
stm32 f3 discovery tim2 to capture 4 pwm input
Posted on January 23, 2014 at 06:24
the office pwm input example is work ok, but i want to capture 4pwm with one timer,so i find this:https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FPWM%20Input%20capture%20doesnt%20work%20on%20Ch34%20pair&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=642
and this: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fMultiple%20PWM%20input%20capture%20on%20one%20timer&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1418 but above two way i can't run it, so i modifie the standard example like this;
static
void
TIM_Config(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIOB clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* TIM2 chennel2 configuration : PA.01 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
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(GPIOA, &GPIO_InitStructure);
/* Connect TIM pin to AF1 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_1);
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//TIM_DeInit(TIM2);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
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 enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
}
void
TIM2_IRQHandler(
void
)
{
RCC_GetClocksFreq(&RCC_Clocks);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
IC2Value = TIM_GetCapture2(TIM2);
Frequency = RCC_Clocks.HCLK_Frequency;
}
this code can work,but when change to TIM_IT_CC1,TIM_IT_CC3,TIM_IT_CC4.
it not work,why?like below
static
void
TIM_Config(
void
)
{
......
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
......
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
}
void
TIM2_IRQHandler(
void
)
{
RCC_GetClocksFreq(&RCC_Clocks);
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
IC2Value = TIM_GetCapture1(TIM2);
Frequency = RCC_Clocks.HCLK_Frequency;
}
#stm32 #discovery #f3 #pwm-input