Nucleo F303K8とSG90を用いたサーボ信号変更における処理時間の測定

Dependencies:   mbed

Revision:
0:e7072f95dcaf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 09 11:00:42 2017 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+#define ON  1
+#define OFF 0
+
+PwmOut servo1(D10);
+Serial pc(USBTX, USBRX);
+Timer timer1;
+Timer timer2;
+
+int main()
+{
+    float pwidth;
+    int miri=1000;
+    servo1.period_ms(20);// pulse cycle = 20ms
+
+    while(1) {
+        for(pwidth=0.001; pwidth<=0.002; pwidth+=0.000001) { // 1ms ~ 2ms
+            timer1.reset();
+            timer1.start();
+            servo1.pulsewidth(pwidth); // pulse servo out
+            timer1.stop();
+            float t1=timer1.read();
+            float time1=t1*miri;
+            pc.printf("time1= %f ms\n",time1);
+            wait(0.001);
+        }
+
+        for(pwidth=0.002; pwidth>=0.001; pwidth-=0.000001) { // 1ms ~ 2ms
+            timer2.reset();
+            timer2.start();
+            servo1.pulsewidth(pwidth); // pulse servo out
+            timer2.stop();
+            float t2=timer2.read();
+            float time2=t2*miri;
+            pc.printf("time2= %f ms\n",time2);
+            wait(0.001);
+        }
+    }
+}
\ No newline at end of file