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

Committer:
p07gbar
Date:
Wed Aug 29 11:51:28 2012 +0000
Revision:
0:a84599c324fb
Initial commit - Working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p07gbar 0:a84599c324fb 1 // Measure and print the average duty cycle of a signal connected to p29 and p30 (together) while the button (p16) is pulled high
p07gbar 0:a84599c324fb 2
p07gbar 0:a84599c324fb 3 #include "mbed.h"
p07gbar 0:a84599c324fb 4 #include "PWMAverage.h"
p07gbar 0:a84599c324fb 5
p07gbar 0:a84599c324fb 6 DigitalOut myled(LED1);
p07gbar 0:a84599c324fb 7
p07gbar 0:a84599c324fb 8 PWMAverage pa(p29,p30);
p07gbar 0:a84599c324fb 9
p07gbar 0:a84599c324fb 10 DigitalIn button (p16);
p07gbar 0:a84599c324fb 11
p07gbar 0:a84599c324fb 12 Timer tmr;
p07gbar 0:a84599c324fb 13
p07gbar 0:a84599c324fb 14 int main()
p07gbar 0:a84599c324fb 15 {
p07gbar 0:a84599c324fb 16 button.mode(PullDown);
p07gbar 0:a84599c324fb 17 while(1)
p07gbar 0:a84599c324fb 18 {
p07gbar 0:a84599c324fb 19 pa.reset();
p07gbar 0:a84599c324fb 20
p07gbar 0:a84599c324fb 21 while (!button) {}
p07gbar 0:a84599c324fb 22 pa.start();
p07gbar 0:a84599c324fb 23 tmr.start();
p07gbar 0:a84599c324fb 24 myled=1;
p07gbar 0:a84599c324fb 25
p07gbar 0:a84599c324fb 26 while (button) {}
p07gbar 0:a84599c324fb 27 pa.stop();
p07gbar 0:a84599c324fb 28 tmr.stop();
p07gbar 0:a84599c324fb 29 myled=0;
p07gbar 0:a84599c324fb 30
p07gbar 0:a84599c324fb 31 printf("Average dudy cycle over %d us was %.4f\n\r",tmr.read_us(),pa.read());
p07gbar 0:a84599c324fb 32 }
p07gbar 0:a84599c324fb 33 }