AnsweredAssumed Answered

STM32F103RB timers input capture Both Edges

Question asked by smurygin.ivan on Nov 29, 2012
Latest reply on Sep 29, 2014 by Karpovski
Hi all!!!
I want to measure a signal with help of timer. I tried to use 
TIM_ICPolarity_BothEdge
but then i uderstand that it doesn't work correctly. So i measured my signal with help of two chanel of one timer. But it was interesting for me how i can to use Both Edge?

I found in Aplication note some information about timers:
"For the STM32F10x family, polarity selection for both edges can be achieved by using
TI1F_ED, but only for TI1 input." 

Is this mean that i may use only 1 channel for capturing signal on both Edges?

So i do follow steps to init my timer.
    /*********Timer4 Inizialization*************/
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
     
    TIM_TimeBaseStructure.TIM_Period = 65535; //20 mS
    TIM_TimeBaseStructure.TIM_Prescaler = 7; //1 uS 1 MHz
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
     
    TIM_ICConfig.TIM_Channel            = TIM_Channel_1;
    TIM_ICConfig.TIM_ICPolarity   = TIM_ICPolarity_BothEdge;
    TIM_ICConfig.TIM_ICSelection  = TIM_ICSelection_DirectTI;
    TIM_ICConfig.TIM_ICPrescaler  = TIM_ICPSC_DIV1;
  TIM_ICConfig.TIM_ICFilter         = 0;
    TIM_ICInit(TIM4, &TIM_ICConfig);
     
    TIM_SelectInputTrigger(TIM4, TIM_TS_TI1F_ED);  /// SET  /*********Timer4 Inizialization*************/
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
     
    TIM_TimeBaseStructure.TIM_Period = 65535; //20 mS
    TIM_TimeBaseStructure.TIM_Prescaler = 7; //1 uS 1 MHz
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
     
    TIM_ICConfig.TIM_Channel            = TIM_Channel_1;
    TIM_ICConfig.TIM_ICPolarity   = TIM_ICPolarity_BothEdge;
    TIM_ICConfig.TIM_ICSelection  = TIM_ICSelection_DirectTI;
    TIM_ICConfig.TIM_ICPrescaler  = TIM_ICPSC_DIV1;
  TIM_ICConfig.TIM_ICFilter         = 0;
    TIM_ICInit(TIM4, &TIM_ICConfig);
     
    TIM_SelectInputTrigger(TIM4, TIM_TS_TI1F_ED);
      TIM_ITConfig(TIM4, TIM_IT_CC1 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE);
    TIM_ClearITPendingBit(TIM4, TIM_IT_CC1 | TIM_IT_CC3 |  TIM_IT_CC4);
     
  /* Enable timer */
  TIM_Cmd(TIM4, ENABLE);
 
    NVIC_InitStructure.NVIC_IRQChannel =  TIM4_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

and it is counting on one edge. What i did wrong?

With best regards Ivan.

Outcomes