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.
Dependents: qonly_controller foc-ed_in_the_bot_compact foc-ed_in_the_bot_compact CurrentModeSine ... more
Fork of FastPWM by
FastPWM.cpp
- Committer:
- Sissors
- Date:
- 2012-07-12
- Revision:
- 2:4b8de6ae5885
- Parent:
- 0:f8c1b0ad5371
- Child:
- 3:3094d3806cfc
File content as of revision 2:4b8de6ae5885:
#include "FastPWM.h"
FastPWM::FastPWM(PinName pin) : PWMObject(pin){
_duty=0;
_period=0.02;
if (pin==p26||pin==LED1)
MR=&LPC_PWM1->MR1;
else if (pin==p25||pin==LED2)
MR=&LPC_PWM1->MR2;
else if (pin==p24||pin==LED3)
MR=&LPC_PWM1->MR3;
else if (pin==p23||pin==LED4)
MR=&LPC_PWM1->MR4;
else if (pin==p22)
MR=&LPC_PWM1->MR5;
else if (pin==p21)
MR=&LPC_PWM1->MR6;
else
error("No hardware PWM pin\n\r");
period(_period);
}
void FastPWM::period(double seconds) {
LPC_PWM1->MR0 = (unsigned int) (seconds * (double)F_CLK);
pulsewidth(_duty*seconds);
_period = seconds;
}
void FastPWM::period_ms(int ms) {
period((double)ms/1000.0);
}
void FastPWM::period_us(int us) {
period((double)us/1000000.0);
}
void FastPWM::period_us(double us) {
period(us/1000000.0);
}
void FastPWM::pulsewidth(double seconds) {
*MR=(unsigned int) (seconds * (double)F_CLK);
}
void FastPWM::pulsewidth_ms(int ms) {
pulsewidth((double)ms/1000.0);
}
void FastPWM::pulsewidth_us(int us) {
pulsewidth((double)us/1000000.0);
}
void FastPWM::pulsewidth_us(double us) {
pulsewidth(us/1000000.0);
}
void FastPWM::write(double duty) {
_duty=duty;
pulsewidth(duty*_period);
}
double FastPWM::read( void ) {
return _duty;
}
FastPWM & FastPWM::operator= (double value) {
write(value);
return(*this);
}
FastPWM::operator double() {
return _duty;
}
