Interface to a standard tarco sensor. Measure the periode and the cal the speed

Committer:
gert_lauritsen
Date:
Thu Nov 07 12:02:47 2013 +0000
Revision:
3:6d3f2034e5f1
Parent:
2:c50da089786a
Child:
4:35024179a736
Tarco sensor gives speed in hz and rpm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 2:c50da089786a 1 #include "Tarco.h"
gert_lauritsen 0:8421e11df32a 2
gert_lauritsen 2:c50da089786a 3 Tarco::Tarco(PinName tarcosignal) :
gert_lauritsen 2:c50da089786a 4 _tarcosensor(tarcosignal) {
gert_lauritsen 3:6d3f2034e5f1 5 t.start();
gert_lauritsen 2:c50da089786a 6 AdvPeriode=99999;
gert_lauritsen 2:c50da089786a 7 _tarcosensor.fall(this, &Tarco::click);
gert_lauritsen 0:8421e11df32a 8 }
gert_lauritsen 0:8421e11df32a 9
gert_lauritsen 2:c50da089786a 10 void Tarco::click() {
gert_lauritsen 2:c50da089786a 11 //måler pulstiden
gert_lauritsen 2:c50da089786a 12 t.stop();
gert_lauritsen 2:c50da089786a 13 AdvPeriode=t.read_us();
gert_lauritsen 2:c50da089786a 14 t.reset(); t.start();
gert_lauritsen 0:8421e11df32a 15 }
gert_lauritsen 0:8421e11df32a 16
gert_lauritsen 2:c50da089786a 17 float Tarco::Speed(){
gert_lauritsen 2:c50da089786a 18 //Giver puls/sek [hz]
gert_lauritsen 2:c50da089786a 19 float frek=1e6/AdvPeriode;
gert_lauritsen 2:c50da089786a 20 return (float) frek;
gert_lauritsen 0:8421e11df32a 21 }
gert_lauritsen 0:8421e11df32a 22
gert_lauritsen 2:c50da089786a 23 float Tarco::RPM() {
gert_lauritsen 3:6d3f2034e5f1 24 float rpm=60e6/AdvPeriode;
gert_lauritsen 2:c50da089786a 25 return (float) rpm;
gert_lauritsen 2:c50da089786a 26 }