- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I need an PWM signal so that I can trigger specific action depending on the level of the PWM. So I set up the PWM with interrupts enabled for terminal count event and compare 1 event. I expected to get an interrupt when the compare value matches the counter and at the end when the counter reaches zero. But I get two interrupts simultaneously, or only microseconds apart.
I clock the PWM with 10 kHz and set the period to 12000 and the compare value to 9000. The compare type is greater. I get a PWM signal with 300ms high value and a period of 1200ms as expected. But not compare 1 interrupt after 300ms as expected.
What do I miss here?
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
user,
Simple. The issue is that the PWM is a count-down counters. Therefore the count starts with period value and counts down. A "Greater than" occurs once the period value is reloaded into the counter after the terminal count.
The simple fix is to use "Lesser than" and use a NOT gate on the PWM output.
I've attached an example project with these changes.
Here's a scope pic of the outputs:
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I change CMP Type 1 from greater to less I get two distinct interrupts 300ms apart. I need to start with a high pulse though..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
user,
Simple. The issue is that the PWM is a count-down counters. Therefore the count starts with period value and counts down. A "Greater than" occurs once the period value is reloaded into the counter after the terminal count.
The simple fix is to use "Lesser than" and use a NOT gate on the PWM output.
I've attached an example project with these changes.
Here's a scope pic of the outputs:
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @user_4495571 ,
As correctly mentioned by Len the PWM is implemented as a count down counter, this is mentioned in the PWM datasheet as well:
Using a "lesser than" option with a not gate should resolve the issue.
Thank and Regards
Ekta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
thank you Len and Ekta.
Yes, I already realized it counts down and a lesser compare type helps. What i still don't understand: The 'Interrupt On Compare 1 Event' gets fired the first time the counter is greater than the compare value? So that is why it fires immediately on period start?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The PWM counter is reloaded with the period value. The period value IS GREATER than the compare value.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have set the compare type is greater, that the reason the Interrupt On Compare 1 Event' gets fired the first time the counter is greater than the compare value.
Best Regards
Ekta