LPC11U35 ADC Tick & USBSerial
Dependents: SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00
mbed/Timer.h@1:b1a3be5f48ab, 2018-02-19 (annotated)
- Committer:
- H_Tsunemoto
- Date:
- Mon Feb 19 09:09:52 2018 +0000
- Revision:
- 1:b1a3be5f48ab
- Parent:
- 0:871ab6846b18
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
H_Tsunemoto | 0:871ab6846b18 | 1 | /* mbed Microcontroller Library |
H_Tsunemoto | 0:871ab6846b18 | 2 | * Copyright (c) 2006-2013 ARM Limited |
H_Tsunemoto | 0:871ab6846b18 | 3 | * |
H_Tsunemoto | 0:871ab6846b18 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
H_Tsunemoto | 0:871ab6846b18 | 5 | * you may not use this file except in compliance with the License. |
H_Tsunemoto | 0:871ab6846b18 | 6 | * You may obtain a copy of the License at |
H_Tsunemoto | 0:871ab6846b18 | 7 | * |
H_Tsunemoto | 0:871ab6846b18 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
H_Tsunemoto | 0:871ab6846b18 | 9 | * |
H_Tsunemoto | 0:871ab6846b18 | 10 | * Unless required by applicable law or agreed to in writing, software |
H_Tsunemoto | 0:871ab6846b18 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
H_Tsunemoto | 0:871ab6846b18 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
H_Tsunemoto | 0:871ab6846b18 | 13 | * See the License for the specific language governing permissions and |
H_Tsunemoto | 0:871ab6846b18 | 14 | * limitations under the License. |
H_Tsunemoto | 0:871ab6846b18 | 15 | */ |
H_Tsunemoto | 0:871ab6846b18 | 16 | #ifndef MBED_TIMER_H |
H_Tsunemoto | 0:871ab6846b18 | 17 | #define MBED_TIMER_H |
H_Tsunemoto | 0:871ab6846b18 | 18 | |
H_Tsunemoto | 0:871ab6846b18 | 19 | #include "platform.h" |
H_Tsunemoto | 0:871ab6846b18 | 20 | |
H_Tsunemoto | 0:871ab6846b18 | 21 | namespace mbed { |
H_Tsunemoto | 0:871ab6846b18 | 22 | |
H_Tsunemoto | 0:871ab6846b18 | 23 | /** A general purpose timer |
H_Tsunemoto | 0:871ab6846b18 | 24 | * |
H_Tsunemoto | 0:871ab6846b18 | 25 | * Example: |
H_Tsunemoto | 0:871ab6846b18 | 26 | * @code |
H_Tsunemoto | 0:871ab6846b18 | 27 | * // Count the time to toggle a LED |
H_Tsunemoto | 0:871ab6846b18 | 28 | * |
H_Tsunemoto | 0:871ab6846b18 | 29 | * #include "mbed.h" |
H_Tsunemoto | 0:871ab6846b18 | 30 | * |
H_Tsunemoto | 0:871ab6846b18 | 31 | * Timer timer; |
H_Tsunemoto | 0:871ab6846b18 | 32 | * DigitalOut led(LED1); |
H_Tsunemoto | 0:871ab6846b18 | 33 | * int begin, end; |
H_Tsunemoto | 0:871ab6846b18 | 34 | * |
H_Tsunemoto | 0:871ab6846b18 | 35 | * int main() { |
H_Tsunemoto | 0:871ab6846b18 | 36 | * timer.start(); |
H_Tsunemoto | 0:871ab6846b18 | 37 | * begin = timer.read_us(); |
H_Tsunemoto | 0:871ab6846b18 | 38 | * led = !led; |
H_Tsunemoto | 0:871ab6846b18 | 39 | * end = timer.read_us(); |
H_Tsunemoto | 0:871ab6846b18 | 40 | * printf("Toggle the led takes %d us", end - begin); |
H_Tsunemoto | 0:871ab6846b18 | 41 | * } |
H_Tsunemoto | 0:871ab6846b18 | 42 | * @endcode |
H_Tsunemoto | 0:871ab6846b18 | 43 | */ |
H_Tsunemoto | 0:871ab6846b18 | 44 | class Timer { |
H_Tsunemoto | 0:871ab6846b18 | 45 | |
H_Tsunemoto | 0:871ab6846b18 | 46 | public: |
H_Tsunemoto | 0:871ab6846b18 | 47 | Timer(); |
H_Tsunemoto | 0:871ab6846b18 | 48 | |
H_Tsunemoto | 0:871ab6846b18 | 49 | /** Start the timer |
H_Tsunemoto | 0:871ab6846b18 | 50 | */ |
H_Tsunemoto | 0:871ab6846b18 | 51 | void start(); |
H_Tsunemoto | 0:871ab6846b18 | 52 | |
H_Tsunemoto | 0:871ab6846b18 | 53 | /** Stop the timer |
H_Tsunemoto | 0:871ab6846b18 | 54 | */ |
H_Tsunemoto | 0:871ab6846b18 | 55 | void stop(); |
H_Tsunemoto | 0:871ab6846b18 | 56 | |
H_Tsunemoto | 0:871ab6846b18 | 57 | /** Reset the timer to 0. |
H_Tsunemoto | 0:871ab6846b18 | 58 | * |
H_Tsunemoto | 0:871ab6846b18 | 59 | * If it was already counting, it will continue |
H_Tsunemoto | 0:871ab6846b18 | 60 | */ |
H_Tsunemoto | 0:871ab6846b18 | 61 | void reset(); |
H_Tsunemoto | 0:871ab6846b18 | 62 | |
H_Tsunemoto | 0:871ab6846b18 | 63 | /** Get the time passed in seconds |
H_Tsunemoto | 0:871ab6846b18 | 64 | */ |
H_Tsunemoto | 0:871ab6846b18 | 65 | float read(); |
H_Tsunemoto | 0:871ab6846b18 | 66 | |
H_Tsunemoto | 0:871ab6846b18 | 67 | /** Get the time passed in mili-seconds |
H_Tsunemoto | 0:871ab6846b18 | 68 | */ |
H_Tsunemoto | 0:871ab6846b18 | 69 | int read_ms(); |
H_Tsunemoto | 0:871ab6846b18 | 70 | |
H_Tsunemoto | 0:871ab6846b18 | 71 | /** Get the time passed in micro-seconds |
H_Tsunemoto | 0:871ab6846b18 | 72 | */ |
H_Tsunemoto | 0:871ab6846b18 | 73 | int read_us(); |
H_Tsunemoto | 0:871ab6846b18 | 74 | |
H_Tsunemoto | 0:871ab6846b18 | 75 | #ifdef MBED_OPERATORS |
H_Tsunemoto | 0:871ab6846b18 | 76 | operator float(); |
H_Tsunemoto | 0:871ab6846b18 | 77 | #endif |
H_Tsunemoto | 0:871ab6846b18 | 78 | |
H_Tsunemoto | 0:871ab6846b18 | 79 | protected: |
H_Tsunemoto | 0:871ab6846b18 | 80 | int slicetime(); |
H_Tsunemoto | 0:871ab6846b18 | 81 | int _running; // whether the timer is running |
H_Tsunemoto | 0:871ab6846b18 | 82 | unsigned int _start; // the start time of the latest slice |
H_Tsunemoto | 0:871ab6846b18 | 83 | int _time; // any accumulated time from previous slices |
H_Tsunemoto | 0:871ab6846b18 | 84 | }; |
H_Tsunemoto | 0:871ab6846b18 | 85 | |
H_Tsunemoto | 0:871ab6846b18 | 86 | } // namespace mbed |
H_Tsunemoto | 0:871ab6846b18 | 87 | |
H_Tsunemoto | 0:871ab6846b18 | 88 | #endif |