cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 TIM1CC

michael239955
Associate III
Posted on March 12, 2017 at 18:33

I can't seem to get TIM1's CC channel 1 ISR to fire.

 FanTimerHandle.Instance =TIM1;

  memset(&sConfig, 0, sizeof(sConfig));

  /* Initialize TIMx peripheral as follow:

       + Period = 0xFFFF

       + Prescaler = 0

       + ClockDivision = 0

       + Counter direction = Up

  */

  FanTimerHandle.Init.Period = 0xFFFF;

  FanTimerHandle.Init.Prescaler = 512;

  FanTimerHandle.Init.ClockDivision = 0;

  FanTimerHandle.Init.CounterMode = TIM_COUNTERMODE_UP; 

  FanTimerHandle.Init.RepetitionCounter = 0;

  if(HAL_TIM_IC_Init(&FanTimerHandle) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }

 

  /* Configure the Input Capture of channel 1 */

  sConfig.ICPolarity    = TIM_ICPOLARITY_RISING;

  sConfig.ICSelection   = TIM_ICSELECTION_DIRECTTI;

  sConfig.ICPolarity    = TIM_ICPSC_DIV1;

  sConfig.ICFilter      = 0;

  if(HAL_TIM_IC_ConfigChannel(&FanTimerHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)

  {

    /* Configuration Error */

    Error_Handler();

  }

  /*##-4- Start the Input Capture in interrupt mode ##########################*/

  if(HAL_TIM_IC_Start_IT(&FanTimerHandle, TIM_CHANNEL_1) != HAL_OK)

  {

    /* Starting Error */

    Error_Handler();

  }

 

and GPIO :

__HAL_RCC_TIM1_CLK_ENABLE();

       

      /* Enable GPIO channels Clock */

      FAN_TIMER_CHANNEL_PORT();

     

      /* Configure  (TIMx_Channel) in Alternate function, push-pull and 100MHz speed */

      GPIO_InitStruct.Pin = GPIO_PIN_8;

      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

      GPIO_InitStruct.Pull = GPIO_PULLUP;

      GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

      GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;

      HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

      /*##-2- Configure the NVIC for TIMx #########################################*/

      /* Sets the priority grouping field */

      HAL_NVIC_SetPriority(TIM1_CC_IRQn, 1, 1);

     

      /* Enable the TIM4 global Interrupt */

      HAL_NVIC_EnableIRQ(TIM1_cc_IRQn);
8 REPLIES 8
Posted on March 13, 2017 at 00:07

What's the stimulus? What is  the observed behaviour and how does it depart from the expected one?

JW

Posted on March 13, 2017 at 13:08

Purpose is to measure the frequency of a square wave. I have a 50hz square wave on the input pins and nothing triggers. If I switch everything to timer 3 I get the expected interrupt.

michael239955
Associate III
Posted on March 13, 2017 at 15:46

yeah, the comment 'TIM4' was a left over comment from when I used Timer4 to prove out that interrupts do work for my application.

Posted on March 13, 2017 at 14:57

PE8 is TIM1_CH1N (The negated output), you'd want to be using PE9 TIM1_CH1

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 13, 2017 at 15:09

that was my first observation after my original post  so I changed to PE9. Same result, no trigger. To test this code before incorporating it in my target board, I am running this code on an STM32F407 discovery devkit. I have my function generator negative lead on the devkit's ground and the positive on PE9. With the following code change:

from

GPIO_InitStruct.Pin = GPIO_PIN_8;

to

GPIO_InitStruct.Pin = GPIO_PIN_9;

seems I have something misconfigured with the capture compare register(s) relative to Timer1.

Posted on March 13, 2017 at 15:16

TIM1 is an advanced timer, it has more registers/fields

sConfig.ICPolarity    = TIM_ICPSC_DIV1; // This seems wrong ICPrescaler perhaps?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 13, 2017 at 15:38

Observe the related capture register (TIM1_CCR1) in debugger.

Not changing? Then problem is on the input side: incorrect GPIO setting or incorrect CCMR/CCER settings.

Changing? Then problem is on the output side: incorrect DIER setting, not enabled interrupt, wrong ISR name.

JW

PS.      

/* Enable the TIM

4

global Interrupt */

      HAL_NVIC_EnableIRQ(TIM1_cc_IRQn);

?

Posted on March 13, 2017 at 15:56

That too, but I meant mainly the lowercase cc