AnsweredAssumed Answered

TIM1 and TIM2 of STM32F103 both are working same APB frequency?

Question asked by Nikhil Ingale on Aug 4, 2016
Latest reply on Aug 4, 2016 by Clive One
Hi,

I have configured the TIM1 and TIM2  in following way.

void timer1Init(void)
{
     NVIC_InitTypeDef NVIC_InitStructure;


     RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);          
     NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
     
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
     
     timerStruct.TIM_Prescaler                     = 71;
     timerStruct.TIM_CounterMode                = TIM_CounterMode_Up;
     timerStruct.TIM_Period                               = 60000;
     timerStruct.TIM_ClockDivision           = TIM_CKD_DIV1;


  TIM_TimeBaseInit(TIM1, &timerStruct);
  TIM_ClearFlag(TIM1, TIM_FLAG_Update);
  TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
  TIM_Cmd(TIM1, ENABLE);


}


void timer2Init(void)
{
     NVIC_InitTypeDef NVIC_InitStructure;


     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);          
     NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
     
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
     
     timerStruct.TIM_Prescaler                     = 71;
     timerStruct.TIM_CounterMode                = TIM_CounterMode_Up;
     timerStruct.TIM_Period                               = 60000;
     timerStruct.TIM_ClockDivision           = TIM_CKD_DIV1;


  TIM_TimeBaseInit(TIM2, &timerStruct);
  TIM_ClearFlag(TIM2, TIM_FLAG_Update);
  TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
  TIM_Cmd(TIM2, ENABLE);


}


void TIM2_IRQHandler()
{
   if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
   {
     TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
           status = !status;
           GPIO_WriteBit(GPIOF,GPIO_Pin_7,status);
      }     
}


void TIM1_UP_IRQHandler()
{
   if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)
   {
     TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
           status = !status;
           GPIO_WriteBit(GPIOF,GPIO_Pin_7,status);
      }     
}

in main loop i am calling only one timerInit at a time. As it is mentioned in the datasheet that TIM1 is working on 72MHz and TIM2 is working on 36MHz. 

I have set the same value for prescalar and period member of structure in both timer1Init() and timer2Init() functions, it is showing the same pulse period for both the timers. for TIM1 period should be 60ms and for TIM2 it should be 30ms

why its showing the same period for both.

Hoping for quick response...
thanks 






Outcomes