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.
Revision 14:07d968decc76, committed 2016-04-15
- Comitter:
- gert_lauritsen
- Date:
- Fri Apr 15 12:44:00 2016 +0000
- Parent:
- 13:4b58c9730bc7
- Commit message:
- Funger som "gammel" motor styring. Kan k?rer gennem alle stadier. Der er kommet en eventlog, s? man kan se hvad der er sket.
Changed in this revision
Tarco.cpp | Show annotated file Show diff for this revision Revisions of this file |
Tarco.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4b58c9730bc7 -r 07d968decc76 Tarco.cpp --- a/Tarco.cpp Wed Mar 09 13:24:26 2016 +0000 +++ b/Tarco.cpp Fri Apr 15 12:44:00 2016 +0000 @@ -1,41 +1,25 @@ #include "Tarco.h" #include "mbed.h" -#define NPulsPrRotation 25 - -DigitalOut debug(LED2); - -Tarco::Tarco(PinName tarcosignal, char mode) : +Tarco::Tarco(PinName tarcosignal) : _tarcosensor(tarcosignal) { - tarcomode=mode; lastfrekvens=0; AdvPeriode[0]=0; -// AdvPeriode=0; - if (mode==RunMeanSwitchAuto) - _tarcosensor.fall(this, &Tarco::RunMeanMeasure); - if (mode==SwitchAuto) - _tarcosensor.fall(this, &Tarco::Rotationtimer); - if (mode==HirthMode) - _tarcosensor.fall(this, &Tarco::Hird); + lastfrekvens=0; AdvPeriode=0; + _tarcosensor.fall(this, &Tarco::Rotationtimer); + TimeOut.attach(this,&Tarco::TarcoTimeout, 0.5); } -void Tarco::Hird() -{ -//Hird er en totakt, der kommer med - t.stop(); - AdvPeriode[0]=t.read_us(); - t.reset(); - t.start(); -} void Tarco::Rotationtimer() { //Da switchAuto motoren kommer ud med 24 pulser/rotation laver vi en prescale på 24 // static int pulscounter; - if (pulscounter++>=PulsPrRotation-1) { //Vi tæller til 24, således at det er tiden/omgang + GettingPuls=1; + if (pulscounter++>=PulsPrRotation) { //Vi tæller til 24, således at det er tiden/omgang t.stop(); - AdvPeriode[0]=t.read_us(); - // callback(AdvPeriode[0]); + AdvPeriode=t.read_us(); + if (AdvPeriode>0) lastfrekvens=(1e6/AdvPeriode); else lastfrekvens=0; t.reset(); t.start(); pulscounter=0; @@ -44,66 +28,13 @@ void Tarco::TarcoTimeout() { //Timeout på tarco puls, så vi får resat tarcoen, når den staopper - -} -void Tarco::RunMeanMeasure() -{ - static unsigned int TarcoHead; -//Måler tarco ved at lave en runing mean på periodetiderne, hvis der en variation -//på over 20% bliver den pågældende periode skippet -//Hvilket btyder at man skipper den lange Syncpuls, og kun tællere på de korte - - static bool MistedPeriod; //dette var en lang periode - int thisperiode; - float periodechange=0; - t.stop(); - if (TarcoHead>=TarcoRunMean) TarcoHead=0; - 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(); -} - -float Tarco::Speed() -{ -//returns puls/sek [hz] - unsigned int periodetid; - static int tarcotimeout; - + if (GettingPuls==0) { //Hvis vi ikke har haft en puld indenfor 0.5 sek, så er den stoppet + t.stop(); t.reset(); lastfrekvens=0; - switch (tarcomode) { - case RunMeanSwitchAuto: { - periodetid=0; - for (int i=0; i<TarcoRunMean; i++) periodetid+=AdvPeriode[i]; - lastperiode=periodetid/TarcoRunMean; - lastfrekvens=(1e6/periodetid)*(TarcoRunMean/NPulsPrRotation); - } break; - case SwitchAuto: { - 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 - } break; - - default: break; - } - return (float) lastfrekvens*60;//Giver hastighed tilbage i RPM -} + } + GettingPuls=false; +} + float Tarco::RPM() {
diff -r 4b58c9730bc7 -r 07d968decc76 Tarco.h --- a/Tarco.h Wed Mar 09 13:24:26 2016 +0000 +++ b/Tarco.h Fri Apr 15 12:44:00 2016 +0000 @@ -3,11 +3,8 @@ #include "mbed.h" #define TarcoRunMean 50 -#define PulsPrRotation 23 -#define HirthMode 2 -#define SwitchAuto 1 -#define RunMeanSwitchAuto 0 -//typedef void (*callback_type)(int); +#define PulsPrRotation 24 +#define PulsTimeOut 200 //200ms /************************************************************************************* * Tarco sensor on the SwitchAuto * Have 2 mode to measure the rotation @@ -18,16 +15,11 @@ class Tarco { private: InterruptIn _tarcosensor; - // callback_type callback; - int AdvPeriode[TarcoRunMean]; //running mean for tarco + int AdvPeriode; //running mean for tarco Timer t; //time for one rotation - - char tarcomode; + Ticker TimeOut; + bool GettingPuls; float lastfrekvens; - float advfrekvens; - int lastperiode; - void Hird(); - void RunMeanMeasure(); //Measure the tarco from a one puls /rotation source void Rotationtimer(); //measure tarco by dividing input frekvens with 24 void TarcoTimeout(); public: @@ -39,14 +31,9 @@ * 0: Standard Prescale to one measure pr rotation * 1: Running mean ********************************************************************************/ - Tarco(PinName tarcosignal,char mode); + Tarco(PinName tarcosignal); /******************************************************************************** - * gives the tarco value in hz - ********************************************************************************/ - - float Speed(); - /******************************************************************************** * gives the tarco value in rotation pr min ********************************************************************************/