cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 Timer10/11 - Compare capture interrupt

JAN R
Associate III
Posted on June 26, 2018 at 17:20

Hi,

I want to use TIM10 or 11 for generating the interrupt when the counter CNT reaches the value stored in CCR1 register (capture/compare). I want NO output  to be generated on output pins. I also want run from internal clock.

My problem? - no interrupt occurs even the CNT value is higher than CCR1 value.

My TIM init:

/* TIM11 init function */

void MX_TIM11_Init(void)

{

      TIM_ClockConfigTypeDef sClockSourceConfig;

      TIM_OC_InitTypeDef sConfigOC;   

      htim11.Instance = TIM11;

      htim11.Init.Prescaler = 2097;      // run from 2,097 Mhz - so now 1 tick = 1 ms

      htim11.Init.CounterMode = TIM_COUNTERMODE_UP;

      htim11.Init.Period = 65535;

      htim11.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

      if (HAL_TIM_Base_Init(&htim11) != HAL_OK)

      {

         _Error_Handler(__FILE__, __LINE__);

      }

   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

if (HAL_TIM_ConfigClockSource(&htim11, &sClockSourceConfig) != HAL_OK)

{

      _Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_OC_Init(&htim11) != HAL_OK)

{

      _Error_Handler(__FILE__, __LINE__);

}

sConfigOC.OCMode = TIM_OCMODE_TIMING;      //just timing - no output

sConfigOC.Pulse = 1000;                                             //Want interrupt after 1000 cycles

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

if (HAL_TIM_OC_ConfigChannel(&htim11, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

{

      _Error_Handler(__FILE__, __LINE__);

}

}

Now I enable the interrupt after Compare match:

LL_TIM_DisableIT_CC1(TIM11);

LL_TIM_ClearFlag_CC1(TIM11); //Clear flag Compare interrupt

LL_TIM_EnableIT_CC1(TIM11); //Enable Compare interrupt

Now Clear the counter and start the counter:

LL_TIM_SetCounter(TIM_SERVER,0); //star count from zero

LL_TIM_OC_SetCompareCH1(TIM_SERVER,obj->CompareValue);

Finally the callback function from cube...

void TIM11_IRQHandler(void)

{

      /* USER CODE BEGIN TIM11_IRQn 0 */

      /* USER CODE END TIM11_IRQn 0 */

      HAL_TIM_IRQHandler(&htim11);

       /* USER CODE BEGIN TIM11_IRQn 1 */

        /* USER CODE END TIM11_IRQn 1 */

}

But no interrupt is generated, Could you please help me what I do wrong?

Thank you, Jan.

#tim10 #output-compare #compare #stm32l1 #tim11
7 REPLIES 7
Posted on June 26, 2018 at 17:46

I don't understand the Cube gobbledygook, but make sure that

- you enable the timer, i.e. TIMx_CR1.CEN=1

- you enable the interrupt in NVIC

Also, make sure that the interrupt service routine has the same name as the one in the vector table in startup file, note that if you compile as C++ the name may get mangled. You can chcek it in the mapfile or disassembly.

JW

henry.dick
Senior II
Posted on June 27, 2018 at 01:48

'no interrupt occurs even the CNT value is higher than CCR1 value.'

1. make s ure that the counter is running;

2. make sure that the CCR1 has the right value;

3. make sure that the OC flag is set;

'      htim11.Init.Prescaler = 2097;      // run from 2,097 Mhz - so now 1 tick = 1 ms'

2097Mhz? you must be the first human to visit us from the distant future!

JAN R
Associate III
Posted on June 27, 2018 at 09:29

I got it. I had a wrong name of Callback service routine! Thanks all for help 🙂 

Jan.

Posted on June 27, 2018 at 09:00

I will chech all the points...

dhenry wrote:

2097Mhz? you must be the first human to visit us from the distant future!

No - I wrote 2,097 MHz -  In my country we use comma instead of dot... 2,097 is sure 2.097 Mhz

Posted on June 27, 2018 at 15:36

https://en.wikipedia.org/wiki/Decimal_separator ♯ Hindu%E2%80%93Arabic_numeral_system

has an interesting lists of countries (and a map) using either dot or comma as decimal separator - the former beling labelled as 'English' and the latter as 'French' influence...

JW

Posted on July 05, 2018 at 07:20

Hi JAN,

Could you please tell me what was the correct name for Callback service routine? Thanks.

Posted on July 05, 2018 at 13:44

here is a chained 32-bit timer where the master TIM16/TIM17 was configured as OC without output: 

https://github.com/dannyf00/STM32-Chaining-16bit-timers/tree/master/TIM16_17_15

 

it is for a different chip but you may find that portion of the code helpful.

the interrupt can be implemented via NVIC-EnableIRQ(). the name of the ISR can be different from chip to chip and can be found in the start-up file.