Mbed LPC1768- Ref: PwmOut22

14 Feb 2014

Hi Guys I'm new to mbed coding and I'm facing certain difficulties while using PwmOut (pin 22). Couple of regular members suggested me to post my problem in here.

So by using PwmOut(p22) , I want to generate 200 kHz square wave and from that wave I need 1kHz square wave.

I got very limited time to finish this stuff and I seek help from you guys.

I have tried to make a code and below is the picture;

/media/uploads/RavneetSingh/pwmout.png

14 Feb 2014

Anyone Please...

14 Feb 2014

Well I made some improvement. I used a code as shown below and I got square wave of 200kHz with 50% duty cycle.

/media/uploads/RavneetSingh/newupdatedcode.png

/media/uploads/RavneetSingh/oscilloscope.jpg

14 Feb 2014

Hi Chris, let me test this on oscilloscope. I will get back to you in few mins.

14 Feb 2014

Chris

Actually from 200 kHz wave , I need 1 kHz perfect square wave.

14 Feb 2014

I have tested this code on oscilloscope and I got 200 kHz. But what I require is 1 kHz square wave from 200 kHz wave.

14 Feb 2014

Nothing appeared with this....

14 Feb 2014

I dont need frequency modulation.

All I need is 1KHz square wave from 200 kHz wave.

14 Feb 2014

What kind of 1kHz square wave do you need? If you just need a 1kHz square wave, what has 200kHz to do with it? A 1kHz square wave = 1kHz square wave, there is nothing related to another frequency in it. So you first need to make clear what that 1kHz wave must be, not square apparantly. Maybe upload a drawing of what it is supposed to look like.

14 Feb 2014

/media/uploads/RavneetSingh/photo.jpg

That's a 1kHz square wave.

14 Feb 2014

200kHz/1Khz = 200 Cycles.

14 Feb 2014

As a I said before, From 200kHz square wave, I want to generate 1kHz square wave.

14 Feb 2014

Your picture doesn't work.for me.

Edit: I can do a guess? Should it be 100 cycles 50% duty cycle, then 100 cycles 0% duty cycle? Which would be on-off keying of the 200kHz carrier. (And not the same as 1kHz square wave).

14 Feb 2014

I got it.

  1. include "mbed.h"

PwmOut PwmPin (p22);

int main() { PwmPin.period(0.000005); Set frequency to 200,000 Hz (period = 5 us)

while(1){ infinite loop PwmPin.write(0); Set the duty cycle to 0%

wait_us(500); wait 100 PWM cyles

PwmPin.write(1); Set the duty cycle to 100%

wait_us(500); wait 100 PWM cycles } }

14 Feb 2014

Thank you Erik and Chris.You guys been so helpful... :)

14 Feb 2014

(y)

14 Feb 2014

Yea that's what it was.. :). Doing this coding stuff is really frustrating. lol

17 Feb 2014

Guys I'm further working on the same code and trying to generate sine wave ( 1kHz) from it.