cancel
Showing results for 
Search instead for 
Did you mean: 

How to check Timer PWM activity?

Bernard M
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
berendi
Principal

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
Associate II

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.

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
Associate II

Indeed, I made:

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

... and it makes what I wanted.

Thanks a lot, Jan

Bernard