Library to simplify using capture pins on hardware.
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!
Diff: TimerCapture.cpp
- Revision:
- 2:7c4ca945bfe1
- Parent:
- 0:94cfc6ceec2f
- Child:
- 4:3ae9f68bae6a
--- a/TimerCapture.cpp Thu May 21 08:11:06 2015 +0000 +++ b/TimerCapture.cpp Thu May 21 08:30:25 2015 +0000 @@ -32,10 +32,16 @@ mCapturePin = pCapturePin; // error out if the pin is already configured. - if (LPC_PINCON->PINSEL0 & bitmask_pinselect == bitmask_pinselect) { + if ((LPC_PINCON->PINSEL0 & bitmask_pinselect) == bitmask_pinselect) { error("TimerCapture: Pin is already configured!"); } + + //check if peripheral has power, else this operation will hang! + if ((LPC_SC->PCONP & (1 << 22)) == 0) { + error("TimerCapture: Attempted to write to timer registers with power off!"); + } + #if DEBUG printf("OK to configure registers\r\n"); #endif