How to check Timer PWM activity?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-24 7: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.
- Labels:
-
TIM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-24 7: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-24 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
