Measurement of low frequencys based on timing between pulses
Dependents: Energy_Meter_S0_Example
Revision 3:36dd0d59fdc8, committed 2012-11-08
- Comitter:
- jocis
- Date:
- Thu Nov 08 14:40:51 2012 +0000
- Parent:
- 2:fc21262db17a
- Commit message:
- rework of documentation, minor bug fixes
Changed in this revision
Pulses.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r fc21262db17a -r 36dd0d59fdc8 Pulses.h --- a/Pulses.h Thu Nov 08 12:01:02 2012 +0000 +++ b/Pulses.h Thu Nov 08 14:40:51 2012 +0000 @@ -28,7 +28,7 @@ * - Motor rotations (rpm) * - Energy meter with SO interface * - * +* */ #ifndef MBED_PULSES_H @@ -54,8 +54,7 @@ pulses.setFactor(3600.0f/2000.0f); // kWh; energy meter with SO interface - 2000 pulses per kWh while(1) { - pc.printf ( "Pulses: counter=%d act=%.3f average=%.3f\r\n", - , + pc.printf ( "Pulses: act=%.3f average=%.3f counter=%d \r\n", pulses.getAct(), pulses.getAverage(), pulses.getCounter() ); @@ -63,60 +62,60 @@ wait(3.14); } } - * @endcode - */ +* @endcode +*/ class Pulses { public: /** Pulses type format */ enum PulseType { - RISE=1, - FALL=2, - CHANGE=3 + RISE=1, //< Trigger on rising edge + FALL=2, //< Trigger on falling edge + CHANGE=3 //< Trigger on both edges. On symmetrical pulses you can improve precision by 2 }; /** constructor of Pulses object - * - * @param inPin Pin number of input pin. All port pins are possible except p19 and p20 - * @param type Type of edge detection. - * @param timeout Timeout in seconds to handle an offline pulse-generator (standing motor). Max 15 minutes. - * @param counter Start value of the internal pulses counter to offset pSum (in get()) e.g. after reboot - */ - explicit Pulses(PinName inPin, PulseType type = RISE, unsigned int timeout=600, unsigned int counter=0); + * + * @param inPin Pin number of input pin. All port pins are possible except p19 and p20 + * @param type Type of edge detection. RISE, FALL, CHANGE + * @param timeout Timeout in seconds to handle a stopped pulse-generator (standing motor). Max 15 minutes. + * @param counter Start value of the internal pulses counter to offset pSum (in get()) e.g. after reboot + */ + explicit Pulses(PinName inPin, PulseType type=FALL, unsigned int timeout=600, unsigned int counter=0); /** Gets the frequency based on the last 2 pulses. It's only a snapshot and its not representative. - * - * @return Actual frequencey - */ + * + * @return Actual frequency + */ float getAct(); /** 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 - */ + * + * @return Average frequency. -1 if no new pulses occurred 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. - */ + /** Gets the average, min, max and sum 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 occurred since last call. + * @param pMin Pointer to float value to return min. frequency. Use NULL to skip param. -1 if no new pulses occurred since last call. + * @param pMax Pointer to float value to return max. frequency. Use NULL to skip param. -1 if no new pulses occurred 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 from the input pin since start - * - * @return Number of pulses - */ + * + * @return Number of pulses + */ unsigned int getCounter(); - + /** Sets the factor for the getter-functions to convert in another unit (1.0=Hz, 60.0=rpm, ...) - * - * @param factor Factor to scale from Hz to user unit - */ + * + * @param factor Factor to scale from Hz to user unit + */ void setFactor(float factor); - + protected: // ISR @@ -126,9 +125,9 @@ InterruptIn _in; Timer _timer; Ticker _timeout; - + PulseType _type; - + unsigned int _lastTimer; unsigned int _ActTime; unsigned int _MinTime; @@ -140,7 +139,7 @@ bool _bFirst; unsigned int _Timeout; unsigned int _TimeoutCount; - + }; #endif