2020-03-24 07:35 AM
Hi,
Sometimes in my program, I use a timer in PWM mode, and sometimes it is off. How can I check the timer status, on or off? Thanks.
Solved! Go to Solution.
2020-03-24 10:17 AM
The most straighforward is to check TIMx_CR1.CEN - that's the bit which enables the timer. It should then be running, if it runs out of the internal clock, and if the ARR register is not set to 0.
JW
2020-03-24 07:43 AM
I'm not exactly sure what do you exactly mean.
If the timer channel output is mapped to an external pin, you can check the corresponding GPIO IDR bit to see if the output is high or low.
You can request interrupts on the compare or update events, which mark the edges of the PWM signal.
2020-03-24 08:49 AM
Thank you for having answered. Yes, my question is not completely clear, I restate it:
Is there a register bit or an HAL macro showing if the timer is running?
Thank you.
2020-03-24 10:17 AM
The most straighforward is to check TIMx_CR1.CEN - that's the bit which enables the timer. It should then be running, if it runs out of the internal clock, and if the ARR register is not set to 0.
JW
2020-03-24 11:20 AM
Indeed, I made:
if(TIM1->CR1 & TIM_CR1_CEN){
// do what I want
}
... and it makes what I wanted.
Thanks a lot, Jan
Bernard