AnsweredAssumed Answered

PWMInput problem

Question asked by valencia.juan on Aug 19, 2014
Latest reply on Aug 20, 2014 by valencia.juan
Hi,
I am trying to get the signal from a RC receiver (typical servo's signal) but i am not getting any reads even though the timer interrupt is working.

PWMI - PB10 -CH3

Signal: 50 HZ (Duty 5 - 10 %)

void TIM2_Config (void){
     
    TIM_ICInitTypeDef  TIM_ICInitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef timerInitStructure; //Timer info
 
     
  /* Time base configuration */
  timerInitStructure.TIM_Prescaler = 30;
  timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  timerInitStructure.TIM_Period = 65535;
  timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  timerInitStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM2, &timerInitStructure);
 
  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 
  /* GPIOB clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
   
  /* TIM2 chennel3 configuration : PB.10 */
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
   
  /* Connect TIM pin to AF2 */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_TIM2);
 
  /* Enable the TIM4 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
     
    /* TIM Configuration */
    TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
  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(TIM2, &TIM_ICInitStructure);
 
  /* Select the TIM2 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);
 
  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
  TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);
 
  /* TIM enable counter */
  TIM_Cmd(TIM2, ENABLE);
 
  /* Enable the CC3 Interrupt Request */
   TIM_ITConfig(TIM2, TIM_IT_CC3, ENABLE);
     
     
}
void TIM2_IRQHandler(void)
{
     
  RCC_ClocksTypeDef RCC_Clocks;
  RCC_GetClocksFreq(&RCC_Clocks);
 
  /* Clear TIM2 Capture compare interrupt pending bit */
  TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
 
  /* Get the Input Capture value */
  IC2Value = TIM_GetCapture2(TIM2);
 
  if (IC2Value != 0)
  {
    /* Duty cycle computation */
    DutyCycle = (TIM_GetCapture1(TIM2) * 100.) / IC2Value;
 
    /* Frequency computation
    TIM4 counter clock = (RCC_Clocks.HCLK_Frequency)/2 */
 
    Frequency = ((RCC_Clocks.HCLK_Frequency)/60) / IC2Value;
         
         
sprintf(&output, "F= %d", Frequency)    ;   
TM_ILI9341_Puts(10, 50, &output, &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK);
sprintf(&output, "D= %.2f", DutyCycle)  ;   
TM_ILI9341_Puts(10, 80, &output, &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK);
  }
  else
  {
    DutyCycle = 0;
    Frequency = 0;
        GPIO_SetBits(GPIOG, GPIO_Pin_13);
  }
}

I tried the example and it worked.

STM32F429 - DISCO.

Thanks.

Outcomes