Measurement of low frequencys based on timing between pulses

Dependents:   Energy_Meter_S0_Example

Revision:
1:6eb686d7d16a
Parent:
0:ef402fb370c5
Child:
2:fc21262db17a
--- a/Pulses.h	Wed Nov 07 18:38:59 2012 +0000
+++ b/Pulses.h	Thu Nov 08 07:25:41 2012 +0000
@@ -21,7 +21,7 @@
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * @section DESCRIPTION
-* mbed Pulses Library, for calculate low frequencys based on timing between pulses
+* mbed Pulses Library, for measurement of low frequencys based on timing between pulses
 *
 * Use cases:
 * - Motor rotations (rpm)
@@ -108,20 +108,29 @@
      * @param type     Type of edge detection.
      * @param timeout  Timeout in seconds to handle an offline pulse-generator (standing motor). Max 15 minutes.
      */
-    explicit Pulses(PinName inPin, PulseType type = RISE, unsigned int timeout=600);
+    explicit Pulses(PinName inPin, PulseType type = RISE, unsigned int timeout=600, unsigned int counter=0);
 
     /** Gets the frequency based on the last 2 pulses
      *
-     * @return        Actual frequence
+     * @return        Actual frequencey
      */
     float getAct();
 
-    /** Gets the average frequency based on all pulses since last call of this function
+    /** Gets the average of frequency based on all pulses since last call of this function
      *
      * @return        Average frequency. -1 if no new pulses occoured since last call
      */
     float getAverage();
 
+    /** Gets the average, min, max and summ of frequency based on all pulses since last call of this function
+     *
+     * @param pAverage    Pointer to float value to return average frequency. Use NULL to skip param. -1 if no new pulses occoured since last call.
+     * @param pMin        Pointer to float value to return min. frequency. Use NULL to skip param. -1 if no new pulses occoured since last call.
+     * @param pMax        Pointer to float value to return max. frequency. Use NULL to skip param. -1 if no new pulses occoured since last call.
+     * @param pSum        Pointer to float value to return the accumulated average values. Use NULL to skip param.
+     */
+    void get(float *pAverage, float *pMin, float *pMax, float *pSum=NULL);
+
     /** Gets the number of pulses since start
      *
      * @return        Number of pulses
@@ -147,8 +156,10 @@
     PulseType _type;
     
     unsigned int _ActTime;
-    unsigned int _SumTime;
-    unsigned int _SumCount;
+    unsigned int _MinTime;
+    unsigned int _MaxTime;
+    unsigned int _AvrTimeSum;
+    unsigned int _AvrTimeCount;
     unsigned int _Counter;
     float _Factor;
     bool _bFirst;