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");
}
Revision:
2:8d50e024637b
Parent:
1:83149916f8a9
Child:
3:9e7474866e48
--- a/PulseCounter.cpp	Sat Dec 15 14:29:08 2012 +0000
+++ b/PulseCounter.cpp	Sun Dec 16 16:04:46 2012 +0000
@@ -40,7 +40,7 @@
     LPC_TIM2->PR = 0x0;                 //                  0 = no prescaling
 
     // Count Control Register
-    LPC_TIM2->CTCR = 0x7;               // Bits 1/0:      1/1 = timer is incremented on rising & falling edges on clock sample capture pin  
+    LPC_TIM2->CTCR = 0x5;               // Bits 1/0:      0/1 = timer is incremented on rising edge on clock sample capture pin  
                                         // Bits 3/2:      0/1 = clock sample capture pin: CAP2.1 (p29), (p29 signal is counter clock)
      
     // Capture Control Register