cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 TIM16_CH1N and TIM17_CH1N input capture not work

u23
Senior
Posted on February 20, 2018 at 10:30

Hi,

I have configure the TIM16_CH1N and TIM17_CH1N timers as input capture to PB6 and PB7 pin respectively:

uint8_t Tim16_17_Init ( void )

{

    GPIO_InitTypeDef GPIO_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    TIM_ICInitTypeDef TIM_ICInitStructure;

   

  /* TIM clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16 | RCC_APB2Periph_TIM17, ENABLE);

  /* GPIOB clock enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

 

  /* pin configuration */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Connect TIMx pins to AFx */

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_2);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_2);

 

  /* Enable the TIM16 and TIM17 global Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn | TIM17_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    

    // Initialize channel 1

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

  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 = 0x0F;

 

    TIM_ICInit(TIM16, &TIM_ICInitStructure);

    TIM_ICInit(TIM17, &TIM_ICInitStructure);

   

  /* Enable the CC1 Interrupt Request */

  TIM_ITConfig(TIM16, TIM_IT_CC1, ENABLE);

    TIM_ITConfig(TIM17, TIM_IT_CC1, ENABLE);

  return 0;

}

but not work!!!

Thanks

3 REPLIES 3
u23
Senior
Posted on February 20, 2018 at 13:54

is there anyone who used these timers as input capture?

thanks

Posted on February 20, 2018 at 20:24

The Negated Output channels are NOT inputs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 21, 2018 at 09:23

Thank you Clive!