positive or negative pulse width counter
PulseWidthCounter.cpp@1:d37d6388c179, 2013-07-11 (annotated)
- Committer:
- komaida424
- Date:
- Thu Jul 11 19:15:42 2013 +0000
- Revision:
- 1:d37d6388c179
- Parent:
- PulseCounter.cpp@0:89bd4ad6027d
namechange from PulseCounter to PulseWidthCounter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komaida424 | 0:89bd4ad6027d | 1 | #include "mbed.h" |
komaida424 | 0:89bd4ad6027d | 2 | #include "InterruptIn.h" |
komaida424 | 1:d37d6388c179 | 3 | #include "PulseWidthCounter.h" |
komaida424 | 0:89bd4ad6027d | 4 | |
komaida424 | 1:d37d6388c179 | 5 | PulseWidthCounter::PulseWidthCounter(PinName _interrupt,bool positive=true) : interrupt(_interrupt) //constructa |
komaida424 | 0:89bd4ad6027d | 6 | { |
komaida424 | 0:89bd4ad6027d | 7 | if ( positive ) |
komaida424 | 1:d37d6388c179 | 8 | { interrupt.rise(this,&PulseWidthCounter::start); |
komaida424 | 1:d37d6388c179 | 9 | interrupt.fall(this,&PulseWidthCounter::stop); |
komaida424 | 0:89bd4ad6027d | 10 | } |
komaida424 | 0:89bd4ad6027d | 11 | else |
komaida424 | 1:d37d6388c179 | 12 | { interrupt.fall(this,&PulseWidthCounter::start); |
komaida424 | 1:d37d6388c179 | 13 | interrupt.rise(this,&PulseWidthCounter::stop); |
komaida424 | 0:89bd4ad6027d | 14 | } |
komaida424 | 0:89bd4ad6027d | 15 | } |
komaida424 | 0:89bd4ad6027d | 16 | |
komaida424 | 1:d37d6388c179 | 17 | void PulseWidthCounter::start() |
komaida424 | 0:89bd4ad6027d | 18 | { |
komaida424 | 0:89bd4ad6027d | 19 | _time.reset(); |
komaida424 | 0:89bd4ad6027d | 20 | _time.start(); |
komaida424 | 0:89bd4ad6027d | 21 | } |
komaida424 | 0:89bd4ad6027d | 22 | |
komaida424 | 1:d37d6388c179 | 23 | void PulseWidthCounter::stop() |
komaida424 | 0:89bd4ad6027d | 24 | { |
komaida424 | 0:89bd4ad6027d | 25 | _time.stop(); |
komaida424 | 0:89bd4ad6027d | 26 | count = _time.read_us(); |
komaida424 | 1:d37d6388c179 | 27 | } |