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.
Revision 0:810f315ba3dc, committed 2012-10-23
- Comitter:
- jksoft
- Date:
- Tue Oct 23 15:24:30 2012 +0000
- Child:
- 1:051a7ecff13e
- Child:
- 2:ad4e7374e5c1
- Commit message:
- TB6612FNG???????????????????
Changed in this revision
| TB6612.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TB6612.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6612.cpp Tue Oct 23 15:24:30 2012 +0000
@@ -0,0 +1,71 @@
+/**
+ * Motor Driver TB6612 Control Library
+ *
+ * -- TB6612 is a device of the TOSHIBA.
+ *
+ * Copyright (C) 2012 Junichi Katsu (JKSOFT)
+ */
+
+
+#include "TB6612.h"
+
+// TB6612 Class Constructor
+TB6612::TB6612(PinName pwm, PinName fwd, PinName rev):
+ _pwm(pwm), _fwd(fwd), _rev(rev) {
+
+ _fwd = 0;
+ _rev = 0;
+ _pwm = 0.0;
+ _pwm.period(0.001);
+
+ bspeed = 0.0;
+ timer_flag = false;
+}
+
+// Speed Control
+// arg
+// float speed -1.0 - 0.0 - 1.0
+void TB6612::speed(float speed) {
+
+ if( timer_flag == true ) return;
+
+ bspeed = speed;
+
+ if( speed > 0.0 )
+ {
+ _pwm = speed;
+ _fwd = 1;
+ _rev = 0;
+ }
+ else if( speed < 0.0 )
+ {
+ _pwm = -speed;
+ _fwd = 0;
+ _rev = 1;
+ }
+ else
+ {
+ _fwd = 1;
+ _rev = 1;
+ }
+}
+
+
+// Speed Control with time-out
+// arg
+// float sspeed:-1.0 - 0.0 - 1.0
+// float time :0.0-
+void TB6612::move(float sspeed , float time)
+{
+ speed(sspeed);
+ timer_flag = true;
+ timer.attach(this,&TB6612::timeout,time);
+}
+
+
+void TB6612::timeout()
+{
+ timer_flag = false;
+ speed(bspeed);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6612.h Tue Oct 23 15:24:30 2012 +0000
@@ -0,0 +1,35 @@
+/**
+ * Motor Driver TB6612 Control Library
+ *
+ * -- TB6612 is a device of the rohm.
+ *
+ * Copyright (C) 2012 Junichi Katsu (JKSOFT)
+ */
+
+#ifndef MBED_TB6612_H
+#define MBED_TB6612_H
+
+#include "mbed.h"
+
+class TB6612 {
+public:
+ TB6612(PinName pwm, PinName fwd, PinName rev);
+ void speed(float speed);
+ void move(float speed , float time);
+ void operator= ( float value )
+ {
+ speed(value);
+ }
+
+protected:
+ PwmOut _pwm;
+ DigitalOut _fwd;
+ DigitalOut _rev;
+ Timeout timer;
+ float bspeed;
+ bool timer_flag;
+ void timeout();
+
+};
+
+#endif