Mirjana Radosavljevic / Mbed 2 deprecated BMS_Master-Test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PwmIn.cpp Source File

PwmIn.cpp

00001 #include "PwmIn.h"
00002 
00003 PwmIn::PwmIn(PinName p) : _p(p) {
00004     _p.rise(this, &PwmIn::rise);
00005     _p.fall(this, &PwmIn::fall);
00006     _period = 0.0;
00007     _pulsewidth = 0.0;
00008     _t.start();
00009 }
00010 
00011 float PwmIn::period() {
00012     return _period;
00013 }
00014 
00015 float PwmIn::pulsewidth() {
00016     return _pulsewidth;
00017 }
00018 
00019 float PwmIn::dutycycle() {
00020     return _pulsewidth / _period;
00021 }
00022 
00023 void PwmIn::rise() {
00024     _period = _t.read();
00025     _t.reset();
00026 }
00027 
00028 void PwmIn::fall() {
00029     _pulsewidth = _t.read();
00030 }