An interface to read a PWM input signal, using InterruptIn. Fork of https://os.mbed.com/users/simon/code/PwmIn/ and update for MbedOS6+
Revision 2:1863adb10730, committed 2022-03-25
- Comitter:
- JohnnyK
- Date:
- Fri Mar 25 05:34:31 2022 +0000
- Parent:
- 1:6d68eb9b6bbb
- Commit message:
- Update for MbedOS6+
Changed in this revision
| PwmIn.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/PwmIn.cpp Thu Sep 02 18:17:35 2010 +0000
+++ b/PwmIn.cpp Fri Mar 25 05:34:31 2022 +0000
@@ -23,8 +23,8 @@
#include "PwmIn.h"
PwmIn::PwmIn(PinName p) : _p(p) {
- _p.rise(this, &PwmIn::rise);
- _p.fall(this, &PwmIn::fall);
+ _p.rise(callback(this, &PwmIn::rise));
+ _p.fall(callback(this, &PwmIn::fall));
_period = 0.0;
_pulsewidth = 0.0;
_t.start();
@@ -43,10 +43,10 @@
}
void PwmIn::rise() {
- _period = _t.read();
+ _period = chrono::duration_cast<chrono::milliseconds>(_t.elapsed_time()).count();
_t.reset();
}
void PwmIn::fall() {
- _pulsewidth = _t.read();
+ _pulsewidth = chrono::duration_cast<chrono::milliseconds>(_t.elapsed_time()).count();
}
Jan Kamidra