Counts pulses on pin p29. Pulse frequency can be up to 48 MHz.
Example, counting 48MHz-pulses on pin p29 generated by pin p22 with PwmOscillator (https://mbed.org/users/geotec/code/PwmOscillator/). Pins p22 & p29 must be connected. Count is triggered when pin p30 = high (I connected oscillator with 9kHz that triggered periodically).
#include "mbed.h" #include "PwmOscillator.h" #include "PulseCounter.h" Serial usbPC(USBTX, USBRX); // sends log messages via USB to PC terminal PwmOscillator pulseGenerator; // generates pulses to be count (48 MHz) on pin p22. Connect this pin to p29 (counter input). PulseCounter pulseCounter; // counts the pulses on pin p29 between trigger events (= rising edges) on pin p30. int main() { usbPC.printf("---> start <---\n"); pulseGenerator.initWithFrequency(48000000); pulseCounter.init(); pulseGenerator.start(); pulseCounter.start(); wait(1); // waiting 1 second for trigger events (pin30: rising edge). Count pulses between trigger events. pulseCounter.stop(); pulseGenerator.stop(); // read & print pulseCounter results uint32_t pulseCounterResults[20]; pulseCounter.counterArray(&pulseCounterResults[0],sizeof pulseCounterResults / sizeof (uint32_t)); for(int i = 0; i < (sizeof pulseCounterResults / sizeof (uint32_t)); i++) { usbPC.printf("counter of trigger event %i = %u\n",i,pulseCounterResults[i]); } // usbPC.printf(" finished.\n"); }
History
bugfix: capture interrupt enabled before start()
2013-01-09, by geotec [Wed, 09 Jan 2013 09:57:21 +0000] rev 4
bugfix: capture interrupt enabled before start()
changed datatype of counterArray (int -> uint32_t)
2013-01-08, by geotec [Tue, 08 Jan 2013 14:25:02 +0000] rev 3
changed datatype of counterArray (int -> uint32_t)
Changed clock sample rate (sample on both edges -> sample on rising edge on p29)
2012-12-16, by geotec [Sun, 16 Dec 2012 16:04:46 +0000] rev 2
Changed clock sample rate (sample on both edges -> sample on rising edge on p29)
MIT license added
2012-12-15, by geotec [Sat, 15 Dec 2012 14:29:08 +0000] rev 1
MIT license added
Initial commit
2012-12-15, by geotec [Sat, 15 Dec 2012 14:26:47 +0000] rev 0
Initial commit