Used to read incoming PWM signals from RC channels

Dependents:   A-Quad

Committer:
KarimAzzouz
Date:
Tue Jan 08 15:01:22 2013 +0000
Revision:
2:4abac72addb7
Parent:
1:eaf70ff4df07
Reduced ISR functions to a minimum

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KarimAzzouz 0:1a57c7f88422 1 #include "PulseIn.h"
KarimAzzouz 0:1a57c7f88422 2
KarimAzzouz 0:1a57c7f88422 3 PulseIn::PulseIn(PinName p) : _k(p)
KarimAzzouz 0:1a57c7f88422 4 {
KarimAzzouz 2:4abac72addb7 5 _k.mode(PullDown);
KarimAzzouz 0:1a57c7f88422 6 _k.rise(this, &PulseIn::rise);
KarimAzzouz 0:1a57c7f88422 7 _k.fall(this, &PulseIn::fall);
KarimAzzouz 0:1a57c7f88422 8 _duration=0;
KarimAzzouz 0:1a57c7f88422 9
KarimAzzouz 0:1a57c7f88422 10 }
KarimAzzouz 1:eaf70ff4df07 11
KarimAzzouz 0:1a57c7f88422 12 int PulseIn::read()
KarimAzzouz 0:1a57c7f88422 13 {
KarimAzzouz 0:1a57c7f88422 14 return _duration;
KarimAzzouz 0:1a57c7f88422 15 }
KarimAzzouz 0:1a57c7f88422 16
KarimAzzouz 1:eaf70ff4df07 17
KarimAzzouz 0:1a57c7f88422 18 void PulseIn::rise()
KarimAzzouz 1:eaf70ff4df07 19 {
KarimAzzouz 0:1a57c7f88422 20 t.start();
KarimAzzouz 0:1a57c7f88422 21 }
KarimAzzouz 0:1a57c7f88422 22
KarimAzzouz 0:1a57c7f88422 23 void PulseIn::fall()
KarimAzzouz 0:1a57c7f88422 24 {
KarimAzzouz 0:1a57c7f88422 25 t.stop();
KarimAzzouz 2:4abac72addb7 26 _duration = t.read_us();
KarimAzzouz 1:eaf70ff4df07 27 t.reset();
KarimAzzouz 0:1a57c7f88422 28 }