エンコーダー

Dependencies:   mbed QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "QEI.h"
00003 QEI rori(PA_6,PA_8,NC,600);
00004 Serial pc(USBTX,USBRX);
00005 Ticker get_rpm;
00006 
00007 /*
00008 使用エンコーダー:LPD3806-600BM-G5-24C
00009 分解能:600(QEIのデフォルトで2倍の1200を読んでいる)
00010 1ms毎にパルスを読む
00011 1ms*1000=1s
00012 rps*60=rpm
00013 表示する値:1msあたりのパルス,これまでの合計パルス、rpm
00014 */
00015 
00016 int rpm=0;
00017 int pulse=0;
00018 int sum_pulse=0;
00019 
00020 void change_rpm();
00021 
00022 int main(){
00023     pc.baud(9600);
00024     get_rpm.attach_us(&change_rpm,1000);
00025     while(true){
00026         pc.printf("pulse:%d sum_pulse:%d rpm:%d\n",pulse,sum_pulse,rpm);
00027     }
00028 }
00029 
00030 void change_rpm(){
00031     pulse=rori.getPulses();
00032     sum_pulse=sum_pulse+pulse;
00033     rori.reset();
00034     rpm=60*1000*pulse/1200;
00035 }