AnsweredAssumed Answered

STM32F4-Discovery timer PWM input mode - prescaler doesn't work

Question asked by bednarek.michal on Mar 2, 2014
Hi.
I downloaded to my Discovery PWM input peripheral example. I've changed it little bit to use 32-bit timer 5.
TIM5 initialization code:
GPIO_InitTypeDef GPIOA_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* TIM5 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
  
  /* GPIOB clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  
  /* TIM5 chennel2 configuration : PA.01 */
  GPIOA_InitStructure.GPIO_Pin   = GPIO_Pin_1;
  GPIOA_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIOA_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIOA_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
  GPIO_Init(GPIOA, &GPIOA_InitStructure);
  
  /* Connect TIM pin to AF2 */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
  
  /* Enable the TIM5 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  TIM5_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
  TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM5_ICInitStructure.TIM_ICFilter = 0x0;
  
  TIM_PWMIConfig(TIM5, &TIM5_ICInitStructure);
  
  /* Select the TIM5 Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(TIM5, TIM_TS_TI2FP2);
  
  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(TIM5, TIM_SlaveMode_Reset);
  TIM_SelectMasterSlaveMode(TIM5,TIM_MasterSlaveMode_Enable);
  
  /* TIM enable counter */
  TIM_Cmd(TIM5, ENABLE);
  
  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM5, TIM_IT_CC2, ENABLE);
In readmy file is written:
TIM counter clock is 84MHz
and
Frequency = TIM counter clock / TIM4_CCR2 in Hz, 
so in interrupt I've got:
Frequency = 84000000 / IC2Value;
 To that moment everything work perfectly.
Problem became when I've changed prescaler to 2 so I've changed in code:
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV2;
and, following on from that:
Frequency = 42000000 / IC2Value;
After that I should get the same frequency like before but it isn't. I've got previous frequency divided by 2. What is wrong?
Thanks
Michael

Outcomes