AnsweredAssumed Answered

stm32 f3 discovery tim2 to capture 4 pwm input

Question asked by jipeng.sun on Jan 23, 2014
Latest reply on Jan 26, 2014 by Clive One
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&currentviews=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&currentviews=1418
but above two way i can't run it, so i modifie the standard example like this;
01.static void TIM_Config(void)
02.{
03.  GPIO_InitTypeDef GPIO_InitStructure;
04.  NVIC_InitTypeDef NVIC_InitStructure;
05. 
06.  /* TIM2 clock enable */
07.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
08. 
09.  /* GPIOB clock enable */
10.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
11.   
12.  /* TIM2 chennel2 configuration : PA.01 */
13.  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
14.  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
15.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
16.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
17.  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
18.  GPIO_Init(GPIOA, &GPIO_InitStructure);
19.   
20.  /* Connect TIM pin to AF1 */
21.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_1);
22. 
23.  /* Enable the TIM2 global Interrupt */
24.  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
25.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
26.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
27.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
28.  NVIC_Init(&NVIC_InitStructure);
29.  //TIM_DeInit(TIM2); 
30.    
31.  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
32.  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
33.  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
34.  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
35.  TIM_ICInitStructure.TIM_ICFilter = 0x0;
36. 
37. 
38.  /* TIM enable counter */
39.  TIM_Cmd(TIM2, ENABLE);
40. 
41.  /* Enable the CC2 Interrupt Request */
42.  TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
43.}
44. 
45.void TIM2_IRQHandler(void)
46.{
47.    RCC_GetClocksFreq(&RCC_Clocks);
48.    TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
49.    IC2Value = TIM_GetCapture2(TIM2);
50.    Frequency = RCC_Clocks.HCLK_Frequency;
51.}

this code can work,but when change to TIM_IT_CC1,TIM_IT_CC3,TIM_IT_CC4.
it not work,why?like below
01.static void TIM_Config(void)
02.{
03.......
04.  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
05.......
06.  /* Enable the CC2 Interrupt Request */
07.  TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
08.}
09. 
10.void TIM2_IRQHandler(void)
11.{
12.    RCC_GetClocksFreq(&RCC_Clocks);
13.    TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
14.    IC2Value = TIM_GetCapture1(TIM2);
15.    Frequency = RCC_Clocks.HCLK_Frequency;
16.}

Outcomes