Skip to main content
Bernard M
Associate
Mar 24, 2020 2:35 PM UTC
Solved

How to check Timer PWM activity?

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.

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Mar 24, 2020 5:17 PM UTC

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

4 replies

berendi
Principal
Mar 24, 2020 2:43 PM UTC

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.

Bernard M
Bernard MAuthor
Associate
Mar 24, 2020 3:49 PM UTC

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.

waclawek.jan
waclawek.janBest answer
Super User
Mar 24, 2020 5:17 PM UTC

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

Bernard M
Bernard MAuthor
Associate
Mar 24, 2020 6:20 PM UTC

Indeed, I made:

	 if(TIM1->CR1 & TIM_CR1_CEN){
		 // do what I want
	 }

... and it makes what I wanted.

Thanks a lot, Jan

Bernard