Skip to main content
Bernard M
Associate
March 24, 2020
Solved

How to check Timer PWM activity?

  • March 24, 2020
  • 4 replies
  • 3142 views

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.
Best answer by waclawek.jan

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
March 24, 2020

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
March 24, 2020

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
March 24, 2020

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
March 24, 2020

Indeed, I made:

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

... and it makes what I wanted.

Thanks a lot, Jan

Bernard