10 years, 9 months ago.

Distortion square wave

I am trying to generate a square wave with PWMOUT. But when i increase the frequency, the wave would have distortion. what causes this problem? And, if the frequency is over 50KHz, there's no wave coming out. Why? How can i get higher frequency, such as 50MHz.

What are you using to view the square wave?

posted by Amador Valley High School Robotics Team 08 Jul 2013

1 Answer

10 years, 9 months ago.

I assume you are using the LPC1768. With default mbed libraries you should be able to get a signal up to 500kHz at 50% duty cycle. If you mean by distortion some overshoot for example, that isn't really a problem. If you are using a probe on your scope that can also create overshoot if it isn't properly compensated (should be a little screw on top of the probe connector).

With http://mbed.org/users/Sissors/code/FastPWM/ you can get PWM frequencies up to 48MHz at 50% duty cycle.

Accepted Answer

Thank you very much. Yeah, I'm using LPC1768. But why can I only get a signal up to 500KHz with default mbed libraries? And I also used FastPWM, which did increase the frequency. So what's the difference between the two libraries? For the distortion, I still don't know what cause this ? I meant that when the frequency was high, the waveform would change from sqaure to triangle almost. Thanks again. I'm a bigginer in this field.

posted by Shenghao Feng 08 Jul 2013

If it went from square to something like sine/triangle, you probably have either a large capacitive load on it, or your measurement device simply isn't fast enough.

The reason it is 500kHz with default library is that it has 1us resolution. So 1us high, 1us low = 500kHz. The hardware can get up to resolution of a clock period. Clock runs at 96MHz, and FastPWM allows for that resolution. So then you got 1 clock cycle low, 1 clock cycle high = 48MHz.

posted by Erik - 08 Jul 2013

Thanks! That really helps.

posted by Shenghao Feng 08 Jul 2013

Hi, I'm trying to understand the code of FastPWM.cpp in order to figure out how it allows pwm to generate 48MHz, since the PwmOut can only be up to 500KHz. I would really appreciate it if you could explain that code to me! Thank you!

posted by Shenghao Feng 06 Aug 2013