cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

user_4495571
New Contributor II

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?

0 Likes
1 Solution
Len_CONSULTRON
Honored Contributor II

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:

Len_CONSULTRON_0-1618272066691.png

 

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
6 Replies
user_4495571
New Contributor II

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..

0 Likes
Len_CONSULTRON
Honored Contributor II

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:

Len_CONSULTRON_0-1618272066691.png

 

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
Ekta
Moderator
Moderator

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:

Ekta_0-1618293108593.png

Using a "lesser than" option with a not gate should resolve the issue.

Thank and Regards

Ekta

0 Likes
user_4495571
New Contributor II

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?

0 Likes
Len_CONSULTRON
Honored Contributor II

The PWM counter is reloaded with the period value.  The period value IS GREATER than the compare value.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Ekta
Moderator
Moderator

Hi @user_4495571 

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

0 Likes