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.
soft_pwm.cpp
- Committer:
- Oschofield
- Date:
- 2015-11-17
- Revision:
- 16:e9e1b134f498
File content as of revision 16:e9e1b134f498:
#include "soft_pwm.h" SoftPwm::SoftPwm(float initalPeriod, float initialDutyCycle) { this->period = initalPeriod; //set initial Period this->dutyCycle = initialDutyCycle; //set initial Duty Cycle this->timer.start(); //PWM timer start } float SoftPwm::getPeriod(){ //return current period value return this->period; } float SoftPwm::getDutyCycle(){ //returns current Duty Cycle value return this->dutyCycle; } void SoftPwm::setPeriod(float newPeriod){ //updates the period to a specified value this->period = newPeriod; return; } void SoftPwm::setDutyCycle(float newDutyCycle){ //updates the Duty cycle to the specified value this->dutyCycle = newDutyCycle; } bool SoftPwm::isOn(){ float onPhaseDuration = this->dutyCycle * this->period; float currentTime = this->timer.read(); if (currentTime > period) this->timer.reset(); if (currentTime < onPhaseDuration){ return true; } else { return false; } }