A PWM/duty cycle measurement library using Timer2
Dependents: PWMAverage_test pwm_duty_measurement
Diff: PWMAverage.h
- Revision:
- 1:34a9269390d9
- Parent:
- 0:5da51898a166
- Child:
- 2:449ea283d634
--- a/PWMAverage.h Wed Aug 29 11:25:55 2012 +0000 +++ b/PWMAverage.h Wed Aug 29 11:44:01 2012 +0000 @@ -35,6 +35,44 @@ /** A class for measuring PWM/Duty cycle of a signal connected to pins 30 and 29 * + * + * @code + * // Measure and print the average duty cycle of a signal connected to p29 and p30 (together) while the button (p16) is pulled high + * + * #include "mbed.h" + * #include "PWMAverage.h" + * + * DigitalOut myled(LED1); + * + * PWMAverage pa(p29,p30); + * + * DigitalIn button (p16); + * + * Timer tmr; + * + * int main() + * { + * button.mode(PullDown); + * while(1) + * { + * pa.reset(); + * + * while (!button) {} + * pa.start(); + * tmr.start(); + * myled=1; + * + * while (button) {} + * pa.stop(); + * tmr.stop(); + * myled=0; + * + * printf("Average dudy cycle over %d us was %.4f\n\r",tmr.read_us(),pa.read()); + * } + * } + * @endcode + * + * */ class PWMAverage { @@ -81,6 +119,13 @@ */ int count(); + private: + + static void _tisr(); + static PWMAverage * instance; + void enable(bool yn); + void configure(); + long count_; long totalup; long total; @@ -89,15 +134,6 @@ double timeDiv; - private: - - static void _tisr(); - static PWMAverage * instance; - void enable(bool yn); - void configure(); - - - bool running; bool starting;