2018-06-26 08:20 AM
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 interruptNow 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 #tim112018-06-26 08:46 AM
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
2018-06-26 04:48 PM
'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!
2018-06-27 12:29 AM
I got it. I had a wrong name of Callback service routine! Thanks all for help :)
Jan.
2018-06-27 02:00 AM
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
2018-06-27 08:36 AM
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
2018-07-05 12:20 AM
Hi JAN,
Could you please tell me what was the correct name for Callback service routine? Thanks.
2018-07-05 06:44 AM
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.