Notice: Please use two pins which use same TIMER to synchronize timer phase. Sample program: http://mbed.org/users/spiralray/code/Nucleo_motor_LockedAntiphase/
Dependents: Nucleo_motor_LockedAntiphase
Diff: motor_lockedantiphase.h
- Revision:
- 0:62943ca4f7a0
diff -r 000000000000 -r 62943ca4f7a0 motor_lockedantiphase.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor_lockedantiphase.h Wed Apr 23 16:32:53 2014 +0000 @@ -0,0 +1,60 @@ +/* + * motor_lockedantiphase.h + * + * Created on: 2014/04/23 + * Author: spiralray + */ + +#ifndef MOTOR_LOCKEDANTIPHASE_H_ +#define MOTOR_LOCKEDANTIPHASE_H_ + +#include "mbed.h" + +class Motor_LockedAntiphase +{ +public: + + Motor_LockedAntiphase(PwmOut ma, PwmOut mb); + ~Motor_LockedAntiphase(); + + /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. + * + * @note + * The resolution is currently in microseconds; periods smaller than this + * will be set to zero. + */ + void period(float seconds) { + motora.period(seconds); + motorb.period(seconds); + } + + /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. + */ + void period_ms(int ms) { + motora.period_ms(ms); + motorb.period_ms(ms); + } + + /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. + */ + void period_us(int us) { + motora.period_us(us); + motorb.period_us(us); + } + +#ifdef MBED_OPERATORS + /** A operator shorthand for write() + */ + Motor_LockedAntiphase& operator= (float value) { + motora.write(0.5f+value/2); + motorb.write(0.5f-value/2); + return *this; + } +#endif + +private: + PwmOut motora,motorb; + +}; + +#endif /* MOTOR_LOCKEDANTIPHASE_H_ */