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

Files at this revision

API Documentation at this revision

Comitter:
spiralray
Date:
Wed Apr 23 16:32:53 2014 +0000
Commit message:
A motor control library using two PWM outputs.

Changed in this revision

motor_lockedantiphase.cpp Show annotated file Show diff for this revision Revisions of this file
motor_lockedantiphase.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor_lockedantiphase.cpp	Wed Apr 23 16:32:53 2014 +0000
@@ -0,0 +1,19 @@
+/*
+ * motor_lockedantiphase.cpp
+ *
+ *  Created on: 2014/04/23
+ *      Author: spiralray
+ */
+
+#include "motor_lockedantiphase.h"
+
+Motor_LockedAntiphase::Motor_LockedAntiphase(PwmOut ma, PwmOut mb): motora(ma), motorb(mb){
+  motora.period_us(50);
+  motorb.period_us(50);
+  motora =0.5f;
+  motorb =0.5f;
+}
+
+Motor_LockedAntiphase::~Motor_LockedAntiphase(){
+
+}
--- /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_ */