AnsweredAssumed Answered

timer3 capture issue on stm32f103c8 device

Question asked by anton.bogdan on Jun 19, 2016
Latest reply on Jun 19, 2016 by anton.bogdan
hello all.
i have a signal of 1800us period which consists of 1500us tON and 300us tOFF.
this signal is provided to PB0 and PB1 which are the timer3 inputs 3&4
my timer3 clock is 72mhz ,
the init code is bellow

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA , ENABLE);
 
       
       
       
       
 
      GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0 | GPIO_Pin_1;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
      GPIO_Init(GPIOB, &GPIO_InitStructure);
       
     
       
     
     GPIO_InitTypeDef GPIO_InitStructure;
     TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
     TIM_ICInitTypeDef  TIM_ICInitStructure;
     NVIC_InitTypeDef NVIC_InitStructure;
        
       
 // configure Timer 3 time base    
    TIM_TimeBaseStructure.TIM_Prescaler = 65000;
    TIM_TimeBaseStructure.TIM_Period = 71;
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
 // configure Timer3 Channel 3
 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 = 0x00;
 TIM_ICInit(TIM3, &TIM_ICInitStructure);
    
    
 // configure Timer3 Channel 4
 TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;
 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
 TIM_ICInitStructure.TIM_ICFilter = 0x00;
 TIM_ICInit(TIM3, &TIM_ICInitStructure);
      
 // Configure Timer3 Interupt Sources 
 TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE); // enable Channel 3 capture interupt
 TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);// enable Channel 4 capture interupt
    
 TIM_SelectInputTrigger(TIM3,TIM_TS_TI1FP1);
 TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
 
 
//enable tim3 irq
 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =6;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 TIM_Cmd(TIM3, ENABLE);  // Start the Timer


now comes the irq handler

void TIM3_IRQHandler(void)
{
  
  if(TIM_GetITStatus(TIM3, TIM_IT_CC3) == SET){  // If Low-Hi transition occured
 
     TIM_ClearITPendingBit(TIM3, TIM_IT_CC3);      
 
     sss[0] = TIM_GetCapture3(TIM3);   // Get timer counts
               
     }
      
 
       if(TIM_GetITStatus(TIM3, TIM_IT_CC4) == SET){ // If Hi-Low transition occured
          TIM_ClearITPendingBit(TIM3, TIM_IT_CC4);                               
        
             sss[1]  = TIM_GetCapture4(TIM3);      // Get timer counts
          
            delta=sss[1]-sss[0];
      
         }
  
  }


So, from my judgement the counter is configured to tick at a rate of 1us ( 1MHZ), this means the CNT regiter is counting with a speed of 1us.

My problem is i am not able to read the expected values from the counter register in the falling edge ( channel4) the return value is always 0..2,  and i would expect at least 1000 ticks, why is that?

Outcomes