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: Teensy_Mot_QEI_Ser_20180111 Axis Axis_20181108 Axis_version2
Fork of MotCon by
MotCon.cpp
- Committer:
- jebradshaw
- Date:
- 2016-05-19
- Revision:
- 2:23cd902e1774
- Parent:
- 1:69e79f1db999
File content as of revision 2:23cd902e1774:
#include "MotCon.h"
MotCon::MotCon(PinName pwm, PinName dir) : _pwm(pwm), _dir(dir) {
_pwm.period_us(50);
_pwm = 0.0;
_dir = 0;
}
// dc is signed duty cycle (+/-1.0)
void MotCon::mot_control(float dc){
if(dc>1.0)
dc=1.0;
if(dc<-1.0)
dc=-1.0;
if(dc > 0.001){
_dir = 0;
_pwm = dc;
}
else if(dc < -0.001){
_dir = 1;
_pwm = abs(dc);
}
else{
_dir = 0;
_pwm = 0.0;
}
}
// dc is signed duty cycle (+/-1.0)
void MotCon::mot_control(float dc, int invert){
if(dc>1.0)
dc=1.0;
if(dc<-1.0)
dc=-1.0;
if(invert==0){
if(dc > 0.001){
_dir = 0;
_pwm = dc;
}
else if(dc < -0.001){
_dir = 1;
_pwm = abs(dc);
}
else{
_dir = 0;
_pwm = 0.0;
}
}
else{
if(dc > 0.001){
_dir = 1;
_pwm = dc;
}
else if(dc < -0.001){
_dir = 0;
_pwm = abs(dc);
}
else{
_dir = 0;
_pwm = 0.0;
}
}
}
