11 years, 1 month ago.

Pwm Output

Hey guys, Need some help with the code, i can't figure it out whats the problem.

"PwmOut my_pwm(PB_3,PB_4,PB_5);" i got used to c programming, and i don't know how to write multiple output ports here. because this one is not working and it gives me an error.

Thank you in advance!

1 Answer

11 years, 1 month ago.

A pwm output only has one pin which is why you can't specify one with 3.

If you want 3 different PWM outputs then you need to declare 3 different pwms. While you could in theory do it all in one line it's more normal to put each one on it's own line.

pwmOut my_pwm1(PB_3);
pwmOut my_pwm2(PB_4);
pwmOut my_pwm3(PB_5);

Oh, thank you very much Andy. That help me a lot! I got used to C programming codes, and it's more like C++ , so i got a bit confused with that.

posted by Karolis Kaciucevicius 28 Oct 2014

There's a reason it's more like c++, it is c++, all the mbed code is. ;-)

pwmOut is a class, we are creating 3 instances of it and calling the constructor for each one with the pin to use.

posted by Andy A 29 Oct 2014