Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL345 ADXL345_I2C IMUfilter ITG3200 Servo fishgait mbed-rtos mbed pixy_cam
Fork of robotic_fish_ver_4_8 by
PwmIn.cpp
- Committer:
- sandwich
- Date:
- 2014-06-05
- Revision:
- 22:807d5467fbf6
- Parent:
- 8:0574a5db1fc4
File content as of revision 22:807d5467fbf6:
#include "PwmIn.h"
PwmIn::PwmIn(PinName p, float dutyMin, float dutyMax)
: _p(p) {
_p.rise(this, &PwmIn::rise);
_p.fall(this, &PwmIn::fall);
_period = 20000;
_pulsewidth = 0;
_t.start();
_risen = false;
_dutyMin = dutyMin;
_dutyMax = dutyMax;
_dutyDelta = dutyMax - dutyMin;
}
float PwmIn::period() {
return float(_period)/1000000;
}
float PwmIn::pulsewidth() {
return float(_pulsewidth)/1000000;
}
float PwmIn::dutycycle() {
return float(_pulsewidth) / float(_period);
}
float PwmIn::dutycyclescaledup() {
float duty = float(_pulsewidth) / float(_period);
float dutyAdjusted = (duty > _dutyMin) ? ((duty-_dutyMin)/_dutyDelta) : 0.0;
return (dutyAdjusted < 1.0) ? dutyAdjusted : 1.0;
}
void PwmIn::rise()
{
_tmp = _t.read_us();
if(_tmp > 19000) {
_period = _tmp;
_risen = true;
_t.reset();
}
}
void PwmIn::fall()
{
_tmp = _t.read_us();
if(_tmp > 500 && _tmp < 5000 && _risen == true) {
_pulsewidth = _tmp;
_risen = false;
}
}
