Interface to a standard tarco sensor. Measure the periode and the cal the speed
Diff: Tarco.cpp
- Revision:
- 3:6d3f2034e5f1
- Parent:
- 2:c50da089786a
- Child:
- 4:35024179a736
--- a/Tarco.cpp Thu Nov 07 09:23:27 2013 +0000 +++ b/Tarco.cpp Thu Nov 07 12:02:47 2013 +0000 @@ -2,7 +2,7 @@ Tarco::Tarco(PinName tarcosignal) : _tarcosensor(tarcosignal) { - Puls=0; t.start(); + t.start(); AdvPeriode=99999; _tarcosensor.fall(this, &Tarco::click); } @@ -11,20 +11,16 @@ //måler pulstiden t.stop(); AdvPeriode=t.read_us(); - NAdv++; t.reset(); t.start(); } float Tarco::Speed(){ //Giver puls/sek [hz] float frek=1e6/AdvPeriode; - AdvSpeed+=frek; - NAdvSpeed++; return (float) frek; } float Tarco::RPM() { -float rpm=(AdvSpeed/NAdvSpeed)*60; -AdvSpeed=0; NAdvSpeed=0; +float rpm=60e6/AdvPeriode; return (float) rpm; }