ピン変化割り込みによる回転数検出。 ロータリーエンコーダのゼロ点信号(Z)を p9 に接続すること。

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
j11332
Date:
Tue May 15 22:18:43 2018 +0000
Commit message:
First Commit; ;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r bfc0fcedcc5e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 15 22:18:43 2018 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+#define PIN_MOTOR_TACH_INPUT p9
+
+Serial con(USBTX, USBRX);
+Timer tc;
+
+int tach_pulse_period;
+
+void handler(void){
+    tc.stop();
+    tach_pulse_period = tc.read_us();
+    tc.reset();
+    tc.start();
+}
+
+int main() {
+    
+    InterruptIn tach(PIN_MOTOR_TACH_INPUT);
+    tach.fall(handler);
+    
+    tc.reset();
+    tc.start();
+    
+    con.baud(9600);
+    con.printf("init\r\n");
+    while(1) {
+        con.printf("%d [us]\r\n", tach_pulse_period);
+        wait_ms(100);
+    }
+}
diff -r 000000000000 -r bfc0fcedcc5e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 15 22:18:43 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file