syouichi imamori
/
MulticopterQuadX
Quad X Type Multicopter
PulseWidthCounter/PulseWidthCounter.cpp@8:1db19b529b22, 2021-02-21 (annotated)
- Committer:
- komaida424
- Date:
- Sun Feb 21 05:14:57 2021 +0000
- Revision:
- 8:1db19b529b22
- Parent:
- 2:59ac9df97701
rev 020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komaida424 | 2:59ac9df97701 | 1 | #include "mbed.h" |
komaida424 | 2:59ac9df97701 | 2 | #include "InterruptIn.h" |
komaida424 | 2:59ac9df97701 | 3 | #include "PulseWidthCounter.h" |
komaida424 | 2:59ac9df97701 | 4 | |
komaida424 | 8:1db19b529b22 | 5 | PulseWidthCounter::PulseWidthCounter(PinName inpin,bool positive) : pulsein(inpin) //constructa |
komaida424 | 2:59ac9df97701 | 6 | { |
komaida424 | 2:59ac9df97701 | 7 | if ( positive ) |
komaida424 | 8:1db19b529b22 | 8 | { pulsein.rise(callback(this,&PulseWidthCounter::start)); |
komaida424 | 8:1db19b529b22 | 9 | pulsein.fall(callback(this,&PulseWidthCounter::stop)); |
komaida424 | 2:59ac9df97701 | 10 | } |
komaida424 | 2:59ac9df97701 | 11 | else |
komaida424 | 8:1db19b529b22 | 12 | { pulsein.fall(callback(this,&PulseWidthCounter::start)); |
komaida424 | 8:1db19b529b22 | 13 | pulsein.rise(callback(this,&PulseWidthCounter::stop)); |
komaida424 | 2:59ac9df97701 | 14 | } |
komaida424 | 2:59ac9df97701 | 15 | } |
komaida424 | 2:59ac9df97701 | 16 | |
komaida424 | 2:59ac9df97701 | 17 | void PulseWidthCounter::start() |
komaida424 | 2:59ac9df97701 | 18 | { |
komaida424 | 2:59ac9df97701 | 19 | _time.reset(); |
komaida424 | 2:59ac9df97701 | 20 | _time.start(); |
komaida424 | 2:59ac9df97701 | 21 | } |
komaida424 | 2:59ac9df97701 | 22 | |
komaida424 | 2:59ac9df97701 | 23 | void PulseWidthCounter::stop() |
komaida424 | 2:59ac9df97701 | 24 | { |
komaida424 | 2:59ac9df97701 | 25 | _time.stop(); |
komaida424 | 2:59ac9df97701 | 26 | count = _time.read_us(); |
komaida424 | 2:59ac9df97701 | 27 | } |
komaida424 | 2:59ac9df97701 | 28 |