AnsweredAssumed Answered

input capture mode

Question asked by kaka on Jun 5, 2015
Latest reply on Jun 7, 2015 by kaka
hej,
i am getting a wrong values when i measuring the signal in input capture mode.can anyone help me what i am doing wrong and also i am new to this .i am using stm32f407vg
the below oen is intialization.
/new one
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
          TIM_TimeBaseStructure.TIM_Prescaler =168 - 1;
          TIM_TimeBaseStructure.TIM_Period = 65535;
          TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
          TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
          TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

         GPIO_InitTypeDef GPIO_IniStructure;
          NVIC_InitTypeDef NVIC_IniStructure;

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
          RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

          GPIO_IniStructure.GPIO_Pin   = GPIO_Pin_11;
          GPIO_IniStructure.GPIO_Mode  = GPIO_Mode_AF;
          GPIO_IniStructure.GPIO_Speed = GPIO_Speed_100MHz;
          GPIO_IniStructure.GPIO_OType = GPIO_OType_PP;
          GPIO_IniStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
          GPIO_Init(GPIOE, &GPIO_IniStructure);

          GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_TIM1); //timer alternative function mapping

          NVIC_IniStructure.NVIC_IRQChannel                   = TIM1_CC_IRQn;  //TIM1 Capture Compare Interrupt
          NVIC_IniStructure.NVIC_IRQChannelPreemptionPriority = 0;
          NVIC_IniStructure.NVIC_IRQChannelSubPriority        = 1;
          NVIC_IniStructure.NVIC_IRQChannelCmd                = ENABLE;
          NVIC_Init(&NVIC_IniStructure);


          TIM_ICInitTypeDef  TIM_ICInitStructure;
          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_ICInit(TIM1, &TIM_ICInitStructure);
          TIM_Cmd(TIM1, ENABLE);
          TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);



the below one has to give me proper value but i am not measuring the proper signal .

void TIM1_CC_IRQHandler(void)
{
  if(TIM_GetITStatus(TIM1, TIM_IT_CC2) == SET)
  {


    TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);
    if(CaptureNumber == 0)
    {

        //sprintf(processcommand, "%d", IC3ReadValue2);
         //printf( "IC3ReadValue2 %d \n", IC3ReadValue1 );
         //usart_SEND (USART6,processcommand);

        IC3ReadValue1 = TIM_GetCapture2(TIM2);



      CaptureNumber = 1;
    }
    else if(CaptureNumber == 1)
    {

        IC3ReadValue2 = TIM_GetCapture2(TIM1);
      //printf( "IC3ReadValue2 %d \n", IC3ReadValue2 );


      if (IC3ReadValue2 > IC3ReadValue1)
      {
          Capture = 0;
        Capture = (IC3ReadValue2 - IC3ReadValue1);

      }
      else if (IC3ReadValue2 < IC3ReadValue1)
      {
          Capture = 0;
        Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2);
      }
      else
      {
        Capture = 0;
      }

      TIM1Freq = (uint32_t) SystemCoreClock / Capture;
      sprintf(processcommand, "%d", TIM1Freq);
      usart_SEND (USART6,processcommand);
      usart_SEND (USART6,"\n\r");
      //TIM1Freq = (uint32_t) SystemCoreClock / Capture1;
      CaptureNumber = 0;
    }
  }
}
i am using timer 1 and the clock frequency of that is 168MHZ.
 thank you ..

Outcomes