Interface to a standard tarco sensor. Measure the periode and the cal the speed
Diff: Tarco.cpp
- Revision:
- 9:6b8619ccb136
- Parent:
- 8:2e6b17f1da02
- Child:
- 10:94eed3809760
--- a/Tarco.cpp Thu Sep 11 07:43:31 2014 +0000 +++ b/Tarco.cpp Wed Nov 19 07:36:50 2014 +0000 @@ -6,7 +6,7 @@ Tarco::Tarco(PinName tarcosignal, char mode,callback_type _callback) : _tarcosensor(tarcosignal) { - tarcomode=mode; + tarcomode=mode; lastfrekvens=0; AdvPeriode[0]=0; // AdvPeriode=0; if (mode==RunMeanSwitchAuto) _tarcosensor.fall(this, &Tarco::RunMeanMeasure); @@ -70,6 +70,7 @@ { //returns puls/sek [hz] unsigned int periodetid; + static int tarcotimeout; lastfrekvens=0; switch (tarcomode) { case RunMeanSwitchAuto: { @@ -79,7 +80,16 @@ lastfrekvens=(1e6/periodetid)*(TarcoRunMean/25); } break; case SwitchAuto: { - lastfrekvens=(1e6/AdvPeriode[0]); + if (AdvPeriode[0]) { + lastfrekvens=(1e6/AdvPeriode[0]); + tarcotimeout=0; AdvPeriode[0]=0; + } + else { + if (tarcotimeout>10) { + lastfrekvens=0; AdvPeriode[0]; + } + tarcotimeout++; + } } break; case HirthMode: { lastfrekvens=(500e3/AdvPeriode[0]); //vi skal kun gannge med det halve da der er 2 pulser /omgang