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