cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect a timer overflow in PWM Input mode?

NTosi
Associate III

Hi, I use the timer3 to detect PWM Duty cycle from the input signal.

The signal is an angle sensor from a BLDC Motor. That means 0% DCy is 0 grad and 100% is 2pi grad. The sensor has 4096 bit resolution.

But I have a problem to detect an overflow interrupt, because in PWM Mode, Rising Edge and Falling Edge Interrupts are also active and seems that all three interrupts call the function HAL_TIM_PeriodElapsedCallback after an event update.

The problem in my application is, that in transition from 2pi to 0 grad, the PWM goes from 100% DCy to 0%DCy, that means for a whole period I don't have a Rising edge signal to detect the new period.

I thought that with an overflow interrupt I can reveal that the period is over and if a rising edge does not occur then I am on the transition.

Do u have any ideas?

2 REPLIES 2

I am not trying to understand fully your problem. I don't use Cube/HAL, but if HAL_TIM_PeriodElapsedCallback() is Cube's way to handle the Update event, you may want to set TIMx_CR1.URS to prevent Update events to be generated by the Slave-mode controller being set in Reset mode (as that's what "PWM Input" entails).

JW

Thanks, I think URS bit is the solution.

I searched in c code from CubeMX and seems that there is no option to change this bit.

Maybe I have an older version, but no URS bit can be changed with cubemx.