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

Dependencies:   mbed

Committer:
j11332
Date:
Tue May 15 22:18:43 2018 +0000
Revision:
0:bfc0fcedcc5e
First Commit; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j11332 0:bfc0fcedcc5e 1 #include "mbed.h"
j11332 0:bfc0fcedcc5e 2
j11332 0:bfc0fcedcc5e 3 #define PIN_MOTOR_TACH_INPUT p9
j11332 0:bfc0fcedcc5e 4
j11332 0:bfc0fcedcc5e 5 Serial con(USBTX, USBRX);
j11332 0:bfc0fcedcc5e 6 Timer tc;
j11332 0:bfc0fcedcc5e 7
j11332 0:bfc0fcedcc5e 8 int tach_pulse_period;
j11332 0:bfc0fcedcc5e 9
j11332 0:bfc0fcedcc5e 10 void handler(void){
j11332 0:bfc0fcedcc5e 11 tc.stop();
j11332 0:bfc0fcedcc5e 12 tach_pulse_period = tc.read_us();
j11332 0:bfc0fcedcc5e 13 tc.reset();
j11332 0:bfc0fcedcc5e 14 tc.start();
j11332 0:bfc0fcedcc5e 15 }
j11332 0:bfc0fcedcc5e 16
j11332 0:bfc0fcedcc5e 17 int main() {
j11332 0:bfc0fcedcc5e 18
j11332 0:bfc0fcedcc5e 19 InterruptIn tach(PIN_MOTOR_TACH_INPUT);
j11332 0:bfc0fcedcc5e 20 tach.fall(handler);
j11332 0:bfc0fcedcc5e 21
j11332 0:bfc0fcedcc5e 22 tc.reset();
j11332 0:bfc0fcedcc5e 23 tc.start();
j11332 0:bfc0fcedcc5e 24
j11332 0:bfc0fcedcc5e 25 con.baud(9600);
j11332 0:bfc0fcedcc5e 26 con.printf("init\r\n");
j11332 0:bfc0fcedcc5e 27 while(1) {
j11332 0:bfc0fcedcc5e 28 con.printf("%d [us]\r\n", tach_pulse_period);
j11332 0:bfc0fcedcc5e 29 wait_ms(100);
j11332 0:bfc0fcedcc5e 30 }
j11332 0:bfc0fcedcc5e 31 }