A test program for the PWMAverage library. This program will print the average duty cycle of a signal (1Hz-100kHz) after a button is pressed for a few seconds.

Dependencies:   PWMAverage mbed

Files at this revision

API Documentation at this revision

Comitter:
p07gbar
Date:
Wed Aug 29 11:51:28 2012 +0000
Commit message:
Initial commit - Working

Changed in this revision

PWMAverage.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWMAverage.lib	Wed Aug 29 11:51:28 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/p07gbar/code/PWMAverage/#449ea283d634
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 29 11:51:28 2012 +0000
@@ -0,0 +1,33 @@
+// 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());
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 29 11:51:28 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file