Interface to a standard tarco sensor. Measure the periode and the cal the speed
Diff: Tarco.cpp
- Revision:
- 2:c50da089786a
- Parent:
- 1:f5d3c37b065e
- Child:
- 3:6d3f2034e5f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tarco.cpp Thu Nov 07 09:23:27 2013 +0000 @@ -0,0 +1,30 @@ +#include "Tarco.h" + +Tarco::Tarco(PinName tarcosignal) : + _tarcosensor(tarcosignal) { + Puls=0; t.start(); + AdvPeriode=99999; + _tarcosensor.fall(this, &Tarco::click); +} + +void Tarco::click() { +//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; +return (float) rpm; +}