Simplest Way to Read DC Average of a PWM signal

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AnRa_1522781
Level 2
Level 2

Hi,

   

I have a PWM signal coming as an input. I want to read the DC average of the signal. What is the simplest way to do this?

   

Will using an analog pin do the trick? Or do I have to use a counter ?

   

-Best Regards

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

AFAIK a PWM signal is a digital signal with a specified duty cycle (0 to 100%). Converting that to a DC it would be sufficient to measure period and high time of the signal where period/high time will give the duty cycle. Indeed this can be done best with counters / timers.

   

 

   

Bob 

0 Likes
AnRa_1522781
Level 2
Level 2

Hi,

   

I found a thread with some solutions that would fit my needs. Specifically post number #12 has example project by danaknight. 

   

http://www.cypress.com/forum/psoc-5-device-programming/pwm-measurement

   

But it uses UDB components to detect the falling edges. How do I detect the falling edges without UDB which are not available in PSoC 4100M series. 

   

regards

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Setup the pin's interrupt on your needed edge.

   

 

   

Bob

0 Likes

I have implemented duty cycle calculation with counter/timer. But PWM on a pin requires one counter.

   

Is there a way to calculate duty cycle of multiple PWM signals using one counter?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Setup a pin interrupt for each of the PWMs you have to read. In the handler read a counter used as a time-base. So you can calculate the duty cycle. Are you reading servo-controls in the range of 1 to 2ms?

   

 

   

Bob

0 Likes

Sorry for the noob question. I didn't understand what you meant by counter used as time-base. Did you mean to setup the interrupt on both rising and falling edges and read a normal up-counter to know the duty-cycle?

   

The signals are not servo controls. I have six PWM signals that could turn on any time. They are 100Hz signals. They have variable duty cycle. I have to find the duty cycle of the signals when the PWM starts. Some of these signals could also be running simultaneously.  

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you mean to setup the interrupt on both rising and falling edges and read a normal up-counter to know the duty-cycle?  Yes, right. You need 6 input pins, each with an own interrupt.

   

 

   

Bob

0 Likes
AnRa_1522781
Level 2
Level 2

Hi,

   

Thanks for the tips. I implemented your suggested method of getting counts from rising and falling edge interrupts on a pin. 

   

The PWM are on Port6 of PSoC4100M series. I get the following error when I try to connect the interrupts to pins of port 6

   

 Port 6 can only support one interrupt at a time and cannot include pin component "Pin_PWM_2" since the port is already assigned an interrupt from "Pin_PWM_1"

   

Does that mean that I can't use more than one interrupt on the Port-6 and I will have to connect the PWM on other ports?

   

Regards

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Does that mean that I can't use more than one interrupt on the Port-6 and I will have to connect the PWM on other ports?

   

Yes. On PSoC4 ports >= 4 are restricted in interconnections and interrupt handling.This has been corrected with the newly introduced _S and -L series.

   

 

   

Bob

0 Likes
AnRa_1522781
Level 2
Level 2

Okay, now I am facing the same problem with Port2 and Port3. Also I have tried this now on the Pioneer Kit - CY8CKIT-042-BLE. 

   

Does this have something to do with the fact that "PSoC has a single GPIO interrupt vector which is common for all the GPIO pins." as mentioned in the post here 

   

http://www.cypress.com/blog/psoc-hacker-blog/handling-multiple-gpio-interrupts-psoc-1?source=search&...

   

You also have comment in this thread saying that " Since all enabled GPIOs use the same interrupt it is evident to read the states of all engaged pins and exit the ISR as soon as possible because no other GPIO-interrupt can be handled during that time." But this post is quite old. 

   

Best Regards

0 Likes