ec
Fork of EC by
Diff: EC.cpp
- Revision:
- 5:4abba4f54406
- Parent:
- 0:20fc96400ca3
- Child:
- 6:bd366dd2fd30
- Child:
- 7:87c135463de7
--- a/EC.cpp Wed Nov 02 02:43:15 2016 +0000 +++ b/EC.cpp Sat Nov 12 06:50:56 2016 +0000 @@ -39,18 +39,47 @@ } } +void Ec::upZ(){ + if(first==false){ + rev++; + first=true; + now_time=timer.read(); + RPM=60/(now_time-old_time); + if((RPM_old-RPM)>300){ + printf("\r\n CAUTION : speed downed drastically\r\n"); + NVIC_SystemReset(); + } + RPM_old=RPM; + old_time=timer.read(); + } +} + +void Ec::downZ(){ + first=false; +} + + //コンストラクタの定義 //main関数の前に必ず一度宣言する //第一・第二引数はエンコーダのA・B相のピン名 //第三院数はエンコーダの分解能 -Ec::Ec(PinName signalA,PinName signalB,int s=defsolution,double t=deftime) : signalA_(signalA),signalB_(signalB) +Ec::Ec(PinName signalA , PinName signalB , PinName signalZ , int s=defsolution , double t=deftime) : signalA_(signalA),signalB_(signalB),signalZ_(signalZ) { - S=0;stateA=0;stateB=0;count=0;pre_count=0.0; - signalA_.rise(this,&Ec::upA); - signalA_.fall(this,&Ec::downA); - signalB_.rise(this,&Ec::upB); - signalB_.fall(this,&Ec::downB); + + if((signalA!=NC)&&(signalB!=NC)){ + S=0;stateA=0;stateB=0;count=0;pre_count=0.0; + signalA_.rise(this,&Ec::upA); + signalA_.fall(this,&Ec::downA); + signalB_.rise(this,&Ec::upB); + signalB_.fall(this,&Ec::downB); + } + if(signalZ!=NC){ + first=false; rev=0; old_time=0; RPM=0; RPM_old=0; + timer.start(); + signalZ_.rise(this,&Ec::upZ); + signalZ_.fall(this,&Ec::downZ); + } dt=t; solution=s; defsolution=s; @@ -84,3 +113,11 @@ dt=t; } +double Ec::getRPM(){ + return RPM; +} + +int Ec::getrev(){ + return rev; +} +