Cooper Liu
/
Eurobot2013_IR
Eurobot 2013 IR testbench
PwmIn/PwmIn.h@0:5ebe36076172, 2012-11-14 (annotated)
- Committer:
- xiaxia686
- Date:
- Wed Nov 14 16:53:28 2012 +0000
- Revision:
- 0:5ebe36076172
- Child:
- 1:818904abef3d
Eurobot2013 IR Testbench;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xiaxia686 | 0:5ebe36076172 | 1 | /* mbed PwmIn Library |
xiaxia686 | 0:5ebe36076172 | 2 | * Copyright (c) 2008-2010, sford |
xiaxia686 | 0:5ebe36076172 | 3 | * |
xiaxia686 | 0:5ebe36076172 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
xiaxia686 | 0:5ebe36076172 | 5 | * of this software and associated documentation files (the "Software"), to deal |
xiaxia686 | 0:5ebe36076172 | 6 | * in the Software without restriction, including without limitation the rights |
xiaxia686 | 0:5ebe36076172 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
xiaxia686 | 0:5ebe36076172 | 8 | * copies of the Software, and to permit persons to whom the Software is |
xiaxia686 | 0:5ebe36076172 | 9 | * furnished to do so, subject to the following conditions: |
xiaxia686 | 0:5ebe36076172 | 10 | * |
xiaxia686 | 0:5ebe36076172 | 11 | * The above copyright notice and this permission notice shall be included in |
xiaxia686 | 0:5ebe36076172 | 12 | * all copies or substantial portions of the Software. |
xiaxia686 | 0:5ebe36076172 | 13 | * |
xiaxia686 | 0:5ebe36076172 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
xiaxia686 | 0:5ebe36076172 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
xiaxia686 | 0:5ebe36076172 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
xiaxia686 | 0:5ebe36076172 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
xiaxia686 | 0:5ebe36076172 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
xiaxia686 | 0:5ebe36076172 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
xiaxia686 | 0:5ebe36076172 | 20 | * THE SOFTWARE. |
xiaxia686 | 0:5ebe36076172 | 21 | */ |
xiaxia686 | 0:5ebe36076172 | 22 | |
xiaxia686 | 0:5ebe36076172 | 23 | #ifndef MBED_PWMIN_H |
xiaxia686 | 0:5ebe36076172 | 24 | #define MBED_PWMIN_H |
xiaxia686 | 0:5ebe36076172 | 25 | |
xiaxia686 | 0:5ebe36076172 | 26 | #include "mbed.h" |
xiaxia686 | 0:5ebe36076172 | 27 | |
xiaxia686 | 0:5ebe36076172 | 28 | /** PwmIn class to read PWM inputs |
xiaxia686 | 0:5ebe36076172 | 29 | * |
xiaxia686 | 0:5ebe36076172 | 30 | * Uses InterruptIn to measure the changes on the input |
xiaxia686 | 0:5ebe36076172 | 31 | * and record the time they occur |
xiaxia686 | 0:5ebe36076172 | 32 | * |
xiaxia686 | 0:5ebe36076172 | 33 | * @note uses InterruptIn, so not available on p19/p20 |
xiaxia686 | 0:5ebe36076172 | 34 | */ |
xiaxia686 | 0:5ebe36076172 | 35 | class PwmIn { |
xiaxia686 | 0:5ebe36076172 | 36 | public: |
xiaxia686 | 0:5ebe36076172 | 37 | /** Create a PwmIn |
xiaxia686 | 0:5ebe36076172 | 38 | * |
xiaxia686 | 0:5ebe36076172 | 39 | * @param p The pwm input pin (must support InterruptIn) |
xiaxia686 | 0:5ebe36076172 | 40 | */ |
xiaxia686 | 0:5ebe36076172 | 41 | PwmIn(PinName p); |
xiaxia686 | 0:5ebe36076172 | 42 | |
xiaxia686 | 0:5ebe36076172 | 43 | /** Read the current period |
xiaxia686 | 0:5ebe36076172 | 44 | * |
xiaxia686 | 0:5ebe36076172 | 45 | * @returns the period in seconds |
xiaxia686 | 0:5ebe36076172 | 46 | */ |
xiaxia686 | 0:5ebe36076172 | 47 | float period(); |
xiaxia686 | 0:5ebe36076172 | 48 | |
xiaxia686 | 0:5ebe36076172 | 49 | /** Read the current pulsewidth |
xiaxia686 | 0:5ebe36076172 | 50 | * |
xiaxia686 | 0:5ebe36076172 | 51 | * @returns the pulsewidth in seconds |
xiaxia686 | 0:5ebe36076172 | 52 | */ |
xiaxia686 | 0:5ebe36076172 | 53 | float pulsewidth(); |
xiaxia686 | 0:5ebe36076172 | 54 | |
xiaxia686 | 0:5ebe36076172 | 55 | /** Read the current dutycycle |
xiaxia686 | 0:5ebe36076172 | 56 | * |
xiaxia686 | 0:5ebe36076172 | 57 | * @returns the dutycycle as a percentage, represented between 0.0-1.0 |
xiaxia686 | 0:5ebe36076172 | 58 | */ |
xiaxia686 | 0:5ebe36076172 | 59 | float dutycycle(); |
xiaxia686 | 0:5ebe36076172 | 60 | |
xiaxia686 | 0:5ebe36076172 | 61 | protected: |
xiaxia686 | 0:5ebe36076172 | 62 | void rise(); |
xiaxia686 | 0:5ebe36076172 | 63 | void fall(); |
xiaxia686 | 0:5ebe36076172 | 64 | |
xiaxia686 | 0:5ebe36076172 | 65 | InterruptIn _p; |
xiaxia686 | 0:5ebe36076172 | 66 | Timer _t; |
xiaxia686 | 0:5ebe36076172 | 67 | float _pulsewidth, _period; |
xiaxia686 | 0:5ebe36076172 | 68 | }; |
xiaxia686 | 0:5ebe36076172 | 69 | |
xiaxia686 | 0:5ebe36076172 | 70 | #endif |