Library to simplify using capture pins on hardware.

Dependents:   bluesync

When I first started experimenting with the notion of capture pins, I had no idea where to begin. Rather than write to registers in every single program, I decided to create a class that'd handle that heavy lifting for me!

Import library

Public Member Functions

TimerCapture (PinName pCapturePin)
Configures registers to use the given pin as a capture pin.
uint32_t getTime ()
Get the time captured by the capture pin's register.

Static Public Member Functions

static void startTimer ()
Starts the TIMER2 timer, and configures it if it's not already configured.
static bool isRunning ()
Checks if the TIMER2 timer is running.
static void stopTimer ()
Stops the TIMER2 timer.
static void resetTimer ()
Resets the TIMER2 timer.

This code uses TIMER2 on the LPC1768. I have no idea if it will work on other hardware, but I hope it helps someone else!

Revision:
3:4c06a8b54655
Parent:
2:7c4ca945bfe1
--- a/TimerCapture.h	Thu May 21 08:30:25 2015 +0000
+++ b/TimerCapture.h	Thu May 21 08:34:46 2015 +0000
@@ -9,7 +9,8 @@
 /** A class that will start TIMER2 on the LPC1768 and configure it to use one of the two capture pins (p29 or p30). 
 * Capture pins allow the hardware to "timestamp" when a pin goes high or low, depending on the configuration. For more information, consult the 
 * <a href="http://www.nxp.com/documents/user_manual/UM10360.pdf">LPC1768 user manual</a>.
-* <h2>Example</h2>
+* <h3>Example</h3>
+* The following example will set up a capture pin, and will print out the timestamp from the capture register whenever a keypress is detected on the USB serial interface.
 * @code
 * #include "mbed.h"
 * #include "TimerCapture.h"
@@ -41,11 +42,11 @@
     * Initializes an object that will configure and read from a capture pin. 
     * If the timer is not already running, it will get configured. 
     *
-    * @attention *There are only two pins that will act as capture pins for TIMER2.* These are P0.4 (DIP p30) and P0.5(DIP p29). 
+    * @attention <b>There are only two pins that will act as capture pins for TIMER2.</b> These are P0.4 (DIP p30) and P0.5(DIP p29). 
     *
     * @warning This will cause a runtime error if: 
     *<ul>
-    * <li>The `capture_pin` is not set to an actual capture pin on the LPC1768.
+    * <li>pCapturePin is not set to an actual capture pin on the LPC1768.
     * <li>The specified capture pin is already in use (i.e. already configured). 
     * <li>The timer hasn't yet been started (i.e. peripheral is off)
     *</ul>