6 years, 8 months ago.

Can this program be used for LPC1768?

Hi, can this program be used for LPC1768?

include "mbed.h" 
class PwmIn 
{ 
public: PwmIn(PinName p) : _p(p)
 {
 _p.rise(this, &PwmIn::rise);
 _p.fall(this, &PwmIn::fall);
 _period = 0.0; _pulsewidth = 0.0; _t.start();
 }
void rise()
 { 
_period = _t.read(); _t.reset();
 }
void fall() { _pulsewidth = _t.read(); 
}
float period()
 {
 return _period;
 }
 float pulsewidth()
 {
 return _pulsewidth;
 } 
float dutycycle()
 { 
return _pulsewidth / _period; 
}
protected: InterruptIn _p; Timer _t; float _pulsewidth, _period; };
PwmOut x(p21);
 PwmOut y(p22);
PwmIn a(p5); 
PwmIn b(p6);
int main()
 {
 x = 0.5; y = 0.2;
 while(1)
 {
 printf("a: pw = %f, period = %f\n", a.pulsewidth(), a.period());
 printf("b: pw = %f, period = %f\n", b.pulsewidth(), b.period());
 wait(2);
 }
 }

1 Answer

6 years, 8 months ago.

Hello Zaiyan,

Yes, that program can be used for LPC1768.

Accepted Answer

Thanks Zoltan !

posted by Zaiyan Qayyum 21 Apr 2018