AnsweredAssumed Answered

stm32f100x discovery board input capture problem

Question asked by r_s.adarsh on Dec 13, 2014
Latest reply on Dec 13, 2014 by Clive One
Hello every one ,
          I am using stm32vl discovery board for PWM input capture.I am using TIM3 channel 2 and counter clock frequency is 24MHz  with this i can measure the frequency and duty cycle of input PWM only till 367Hz.But i am facing problems in configuring prescalar value  to measure even lesser input frequency . please help me out in  setting prescalar value  . code which i am using is as below


main code


int main(void)
{
   
       
  /* System Clocks Configuration */
  RCC_Configuration();


  /* NVIC configuration */
  NVIC_Configuration();


  /* Configure the GPIO ports */
  GPIO_Configuration();


  
  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_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);


  while (1);
}




void RCC_Configuration(void)
{
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);


  /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}




void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;


  /* TIM3 channel 2 pin (PA.07) configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;


  GPIO_Init(GPIOA, &GPIO_InitStructure);
}




void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;


  /* Enable the TIM3 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}


Timer interrupt handler code 



void TIM3_IRQHandler(void)
{
  /* Clear TIM3 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);


  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM3);


  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;


    /* Frequency computation */
    Frequency = SystemCoreClock / IC2Value;
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
  }
}
 

Outcomes