Counts signal transitions on p30(CAP2.0) or p29(CAP2.1) for LPC1768 target. Can detecte rising, falling or both signal edge. Return the signal edge count during a period in seconds. In theory (Shannon's theorem) input signal frequency can up to 48 MHz with 96 MHz CCLK. But only tested with frequencys up to 20 MHz and it work.
Diff: lib_ClockCounter.h
- Revision:
- 5:b5e68cd91f09
- Parent:
- 3:20dd01b1a1fd
--- a/lib_ClockCounter.h Tue Jan 07 15:00:14 2020 +0000 +++ b/lib_ClockCounter.h Wed Dec 02 15:48:45 2020 +0000 @@ -51,11 +51,38 @@ */ ClockCounter(PinName PIN_CAP2 = p30, edgeDetection EDGE = RISING); + /** Select an ClockCounter instance + * + * Configure LPC1768 TIMER2 with capture input PIN_CAP2 and detecte transition EDGE. + * + * @param PIN_CAP2 can be p30(CAP2.0) or p29(CAP2.1). + * @param EDGE can be RISING, FALLING, BOTH, default is RISING. + */ + void setPin(PinName PIN_CAP2, edgeDetection EDGE = RISING); + + /** Start the signal transition count + * + */ + void startCount(void); + + /** Stop and Get the signal transition count + * + */ + int stopCount(void); + /** Get the signal transition count during period * * @param period default is 1000000 microsecond. */ int getCount(int period = 1000000); + + /** Get the selected input PIN_CAP2 on started signal transition count + * + */ + PinName getPin(void); +private: + int _count; + PinName _selectPin; }; #endif #endif \ No newline at end of file