Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Tarco.cpp
- Revision:
- 6:2ad5029f7b1a
- Parent:
- 5:451dd1189b0f
- Child:
- 7:752b8065ce2d
diff -r 451dd1189b0f -r 2ad5029f7b1a Tarco.cpp
--- a/Tarco.cpp Tue Nov 19 12:44:26 2013 +0000
+++ b/Tarco.cpp Wed Nov 20 13:29:29 2013 +0000
@@ -42,9 +42,20 @@
{
static unsigned int TarcoHead;
//measure pulstime
+ static bool MistedPeriod; //dette var en lang periode
+ int thisperiode;
+ float periodechange;
t.stop();
if (TarcoHead>=TarcoRunMean) TarcoHead=0;
- AdvPeriode[TarcoHead++]=t.read_us();
+ thisperiode=t.read_us();
+ if (lastperiode!=0)
+ periodechange=(float) thisperiode/lastperiode;
+ if((periodechange<1.2) || (lastperiode==0) || MistedPeriod) {
+ AdvPeriode[TarcoHead++]=thisperiode;
+ MistedPeriod=false;
+ }
+ else
+ MistedPeriod=true;
t.reset();
t.start();
}
@@ -55,7 +66,8 @@
unsigned int periodetid;
periodetid=0;
for (int i=0; i<TarcoRunMean; i++) periodetid+=AdvPeriode[i];
- lastfrekvens=(1e6/periodetid)*(TarcoRunMean/24.3);
+ lastperiode=periodetid/TarcoRunMean;
+ lastfrekvens=(1e6/periodetid)*(TarcoRunMean/25);
return (float) lastfrekvens;
}