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

Committer:
spiralray
Date:
Wed Apr 23 16:32:53 2014 +0000
Revision:
0:62943ca4f7a0
A motor control library using two PWM outputs.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spiralray 0:62943ca4f7a0 1 /*
spiralray 0:62943ca4f7a0 2 * motor_lockedantiphase.h
spiralray 0:62943ca4f7a0 3 *
spiralray 0:62943ca4f7a0 4 * Created on: 2014/04/23
spiralray 0:62943ca4f7a0 5 * Author: spiralray
spiralray 0:62943ca4f7a0 6 */
spiralray 0:62943ca4f7a0 7
spiralray 0:62943ca4f7a0 8 #ifndef MOTOR_LOCKEDANTIPHASE_H_
spiralray 0:62943ca4f7a0 9 #define MOTOR_LOCKEDANTIPHASE_H_
spiralray 0:62943ca4f7a0 10
spiralray 0:62943ca4f7a0 11 #include "mbed.h"
spiralray 0:62943ca4f7a0 12
spiralray 0:62943ca4f7a0 13 class Motor_LockedAntiphase
spiralray 0:62943ca4f7a0 14 {
spiralray 0:62943ca4f7a0 15 public:
spiralray 0:62943ca4f7a0 16
spiralray 0:62943ca4f7a0 17 Motor_LockedAntiphase(PwmOut ma, PwmOut mb);
spiralray 0:62943ca4f7a0 18 ~Motor_LockedAntiphase();
spiralray 0:62943ca4f7a0 19
spiralray 0:62943ca4f7a0 20 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
spiralray 0:62943ca4f7a0 21 *
spiralray 0:62943ca4f7a0 22 * @note
spiralray 0:62943ca4f7a0 23 * The resolution is currently in microseconds; periods smaller than this
spiralray 0:62943ca4f7a0 24 * will be set to zero.
spiralray 0:62943ca4f7a0 25 */
spiralray 0:62943ca4f7a0 26 void period(float seconds) {
spiralray 0:62943ca4f7a0 27 motora.period(seconds);
spiralray 0:62943ca4f7a0 28 motorb.period(seconds);
spiralray 0:62943ca4f7a0 29 }
spiralray 0:62943ca4f7a0 30
spiralray 0:62943ca4f7a0 31 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
spiralray 0:62943ca4f7a0 32 */
spiralray 0:62943ca4f7a0 33 void period_ms(int ms) {
spiralray 0:62943ca4f7a0 34 motora.period_ms(ms);
spiralray 0:62943ca4f7a0 35 motorb.period_ms(ms);
spiralray 0:62943ca4f7a0 36 }
spiralray 0:62943ca4f7a0 37
spiralray 0:62943ca4f7a0 38 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
spiralray 0:62943ca4f7a0 39 */
spiralray 0:62943ca4f7a0 40 void period_us(int us) {
spiralray 0:62943ca4f7a0 41 motora.period_us(us);
spiralray 0:62943ca4f7a0 42 motorb.period_us(us);
spiralray 0:62943ca4f7a0 43 }
spiralray 0:62943ca4f7a0 44
spiralray 0:62943ca4f7a0 45 #ifdef MBED_OPERATORS
spiralray 0:62943ca4f7a0 46 /** A operator shorthand for write()
spiralray 0:62943ca4f7a0 47 */
spiralray 0:62943ca4f7a0 48 Motor_LockedAntiphase& operator= (float value) {
spiralray 0:62943ca4f7a0 49 motora.write(0.5f+value/2);
spiralray 0:62943ca4f7a0 50 motorb.write(0.5f-value/2);
spiralray 0:62943ca4f7a0 51 return *this;
spiralray 0:62943ca4f7a0 52 }
spiralray 0:62943ca4f7a0 53 #endif
spiralray 0:62943ca4f7a0 54
spiralray 0:62943ca4f7a0 55 private:
spiralray 0:62943ca4f7a0 56 PwmOut motora,motorb;
spiralray 0:62943ca4f7a0 57
spiralray 0:62943ca4f7a0 58 };
spiralray 0:62943ca4f7a0 59
spiralray 0:62943ca4f7a0 60 #endif /* MOTOR_LOCKEDANTIPHASE_H_ */