Skip to main content
jgauthier
Senior
December 2, 2021
Solved

HAL_TIM_PWM_PulseFinishedCallback() not getting called

I've created a single pulse that executes for about 150ms. When it's complete I was expecting HAL_TIM_PWM_PulseFinishedCallback() to be called, however, it never is.

Doing this:

if (HAL_TIM_OnePulse_Start(&htim1, TIM_CHANNEL_1) != HAL_OK) {
		/* Starting Error */
		Error_Handler();
	}

Then in the main while() loop when a certain condition is met:

__HAL_TIM_ENABLE(&htim1);

My oscilloscope shows the pulse occurs at the correct time for the correct duration.

Why wouldn't the callback execute?

Thanks,

This topic has been closed for replies.
TDK
TDKBest answer
December 2, 2021

HAL_TIM_OnePulse_Start() is a blocking function and doesn't use interrupts.

If you want a callback, you can use HAL_TIM_OnePulse_Start_IT() instead which will call HAL_TIM_PWM_PulseFinishedCallback in the HAL IRQ handler. The interrupt needs to be enabled prior to this call. CubeMX can generate the code and interrupt function handler for you.

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
December 2, 2021

HAL_TIM_OnePulse_Start() is a blocking function and doesn't use interrupts.

If you want a callback, you can use HAL_TIM_OnePulse_Start_IT() instead which will call HAL_TIM_PWM_PulseFinishedCallback in the HAL IRQ handler. The interrupt needs to be enabled prior to this call. CubeMX can generate the code and interrupt function handler for you.

"If you feel a post has answered your question, please click ""Accept as Solution""."
jgauthier
jgauthierAuthor
Senior
December 3, 2021

Well, that makes perfect sense. Thanks for pointing that out.