AnsweredAssumed Answered

STM32F103ZE TIM1 InputCapture

Question asked by Richard on Feb 19, 2014
Latest reply on Feb 20, 2014 by Clive One
HI,

I'm trying to configure TIMER1 CHANNEL2 for InputCapture to measure a pulse from some external hardware. My init code looks like this:

  ////////////////////////////////////////////////
  // Enable Timer1 clock and release reset
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1,DISABLE);

  TIM_InternalClockConfig(TIM1);

  RCC_GetClocksFreq(&RCC_Clocks);

  Int32U Tim1Clock = RCC_Clocks.PCLK2_Frequency ;

  if(RCC_Clocks.HCLK_Frequency != RCC_Clocks.PCLK2_Frequency)
  {
    Tim1Clock = 2*RCC_Clocks.PCLK2_Frequency ;
  }
  // Time base configuration
  TIM_TimeBaseStructure.TIM_Prescaler = 1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 65535;          
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);

  // Channel 2 Configuration in InputCapture
  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_ICInit(TIM1, &TIM_ICInitStructure);
 
  /* Enable the TIM1 global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

At the moment I just want to catch the rising edge to calculate frequency but in the next revision I want to time between a rising and the next falling edge.

My interrupt handler is not getting called. I have a logic analyser on the pins and can see the signals so I know the hardware is working OK.

I think I have missed something silly and hope someone can kindly point me in the right direction.

Many thanks,

Richard.

Outcomes