A PWM/duty cycle measurement library using Timer2

Dependents:   PWMAverage_test pwm_duty_measurement

Revision:
0:5da51898a166
Child:
1:34a9269390d9
diff -r 000000000000 -r 5da51898a166 PWMAverage.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWMAverage.h	Wed Aug 29 11:25:55 2012 +0000
@@ -0,0 +1,109 @@
+/**
+* @author Giles Barton-Owen
+*
+* @section LICENSE
+*
+* Copyright (c) 2011 mbed
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+* THE SOFTWARE.
+*
+* @section DESCRIPTION
+*    PWM/Duty cycle measurement library using Timer2: library h file for NXP LPC1768
+*
+*/ 
+
+#ifndef PWMAVERAGE_H
+#define PWMAVERAGE_H
+#include "mbed.h"
+
+
+/** A class for measuring PWM/Duty cycle of a signal connected to pins 30 and 29
+ *
+ */
+class PWMAverage
+{
+    public:
+    /** Create a PWMAverage object
+     * 
+     *
+     * @param cap0 Pin connected to signal (ignored in program)
+     * @param cap1 Pin connected to signal (ignored in program)
+     */
+    PWMAverage(PinName cap0, PinName cap1);
+    
+    /** Reset the counters and values
+     */
+    void reset();
+    /** Start the timer
+     */
+    void start();
+    /** Stop the timer
+     */
+    void stop();
+    /** Read the duty cycle measured
+     * @returns The Duty cycle
+     */
+    float read();
+    /** Read the average length of time the signal was high per cycle in seconds
+     * @returns The Length of time the signal was high per cycle in seconds
+     */
+    double avg_up();
+    /** Read the average length of time the signal was high per cycle in seconds
+     * @returns The Length of time the signal was high per cycle in seconds
+     */
+    float avg_UP();
+    /** Read the average length of time the signal was low per cycle in seconds
+     * @returns The Length of time the signal was low per cycle in seconds
+     */
+    double avg_down();
+    /** Read the average period in seconds
+     * @returns The Period
+     */
+    double period();
+    /** Read the number of cycles counted over
+     * @returns The number of cycles
+     */
+    int count();
+    
+    long count_;
+    long totalup;
+    long total;
+    
+    double timeMult;
+    
+    double timeDiv;
+    
+    private:
+    
+    static void _tisr();
+    static PWMAverage * instance;
+    void enable(bool yn);
+    void configure();
+    
+    
+    
+    bool running;
+    bool starting;
+    
+    uint32_t prescaler_point;
+    
+};
+
+
+#endif
\ No newline at end of file