Dependents:   Motorteststand

Files at this revision

API Documentation at this revision

Comitter:
HMFK03LST1
Date:
Tue Mar 28 10:00:31 2017 +0000
Parent:
1:356385f2d5c9
Commit message:
test

Changed in this revision

counter.cpp Show annotated file Show diff for this revision Revisions of this file
counter.h Show annotated file Show diff for this revision Revisions of this file
diff -r 356385f2d5c9 -r a1fd290abd1a counter.cpp
--- a/counter.cpp	Wed Dec 16 20:08:08 2015 +0000
+++ b/counter.cpp	Tue Mar 28 10:00:31 2017 +0000
@@ -1,44 +1,41 @@
 #include "counter.h"
 
+
     /** Create an Counter with period read for low counts
      * 
      * @param pin is the MC pin for the Interrupt Input 
      */ 
-Counter::Counter(PinName pin) : _interrupt(pin), _count(0) {        // create the InterruptIn on the pin specified to Counter
+Counter::Counter(PinName pin, int count_per_round) : _interrupt(pin), _count(0), _period (100000000) {        // create the InterruptIn on the pin specified to Counter
+        _count_per_round = count_per_round;
         _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance
-        _base.attach(this,&Counter::do_calc,1);
+        _base.attach(this, &Counter::do_calc,0.01);
         _time.start();
+        
     }
 
     /** Counter up on Riese Interrupt 
      *  Read periode time
      */ 
+
 void Counter::increment() {
+        if (_count < _count_per_round)
+         {_period = ((_period * _count         ) + _time.read_us()) / (_count + 1);}
+         else
+         {_period = ((_period * _count_per_round) + _time.read_us()) / (_count_per_round + 1);}
         _count++;
-        _period = (_period + (_time.read_us() / 1000)) / 2;
         _time.reset(); 
     }
 
-
-    /** Calc Counts per Secound and Counts per Minute 
-     *  if interrupt count higher 55 only interrupt is in calc
-     *  if interrupt count between 15 and 55 interrupt and periode time is in calc
-     *  if interrupt count lower 15 only periode time is in calc
-     */     
-void Counter::do_calc() {
-        if (_count  >  90)
-                          {
-                            cps = _count;
-                          }
-        else              {
-         if (_count <  65)   
-                           {
-                            if (_period ==  0) _period = 100000;
-                            cps = (1000/_period);
-                           }
-         else              {
-                            cps =((1000/_period) + _count) / 2;
-                           }               
-                          }
-        _count = 0;
-    }   
\ No newline at end of file
+void Counter::do_calc() {   
+        if (_count > 0)
+         {
+          rps = (1000000/(_period * _count_per_round));                             
+          _count = 0;
+          no_count = 0;
+         }
+        else
+         {
+          no_count++;
+         }
+        if (_time.read_ms() > 2000) _period = 100000000;
+    }
\ No newline at end of file
diff -r 356385f2d5c9 -r a1fd290abd1a counter.h
--- a/counter.h	Wed Dec 16 20:08:08 2015 +0000
+++ b/counter.h	Tue Mar 28 10:00:31 2017 +0000
@@ -7,11 +7,12 @@
      * @param pin is the MC pin for the Interrupt Input 
      */
     
-    Counter(PinName pin);
+    Counter(PinName pin, int count_per_round);
  
     /** Stores Counts per Second for last counting interval
      */
-    float cps;
+    float rps;
+    int no_count;
 
 
 private:
@@ -25,7 +26,7 @@
     Timer       _time;
     
     volatile int _count;
-    
+    volatile int _count_per_round;
     float _period;
     
 };
\ No newline at end of file