LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

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?

UserRevisionLine numberNew 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_PWMOUT_H
H_Tsunemoto 0:871ab6846b18 17 #define MBED_PWMOUT_H
H_Tsunemoto 0:871ab6846b18 18
H_Tsunemoto 0:871ab6846b18 19 #include "platform.h"
H_Tsunemoto 0:871ab6846b18 20
H_Tsunemoto 0:871ab6846b18 21 #if DEVICE_PWMOUT
H_Tsunemoto 0:871ab6846b18 22 #include "pwmout_api.h"
H_Tsunemoto 0:871ab6846b18 23
H_Tsunemoto 0:871ab6846b18 24 namespace mbed {
H_Tsunemoto 0:871ab6846b18 25
H_Tsunemoto 0:871ab6846b18 26 /** A pulse-width modulation digital output
H_Tsunemoto 0:871ab6846b18 27 *
H_Tsunemoto 0:871ab6846b18 28 * Example
H_Tsunemoto 0:871ab6846b18 29 * @code
H_Tsunemoto 0:871ab6846b18 30 * // Fade a led on.
H_Tsunemoto 0:871ab6846b18 31 * #include "mbed.h"
H_Tsunemoto 0:871ab6846b18 32 *
H_Tsunemoto 0:871ab6846b18 33 * PwmOut led(LED1);
H_Tsunemoto 0:871ab6846b18 34 *
H_Tsunemoto 0:871ab6846b18 35 * int main() {
H_Tsunemoto 0:871ab6846b18 36 * while(1) {
H_Tsunemoto 0:871ab6846b18 37 * led = led + 0.01;
H_Tsunemoto 0:871ab6846b18 38 * wait(0.2);
H_Tsunemoto 0:871ab6846b18 39 * if(led == 1.0) {
H_Tsunemoto 0:871ab6846b18 40 * led = 0;
H_Tsunemoto 0:871ab6846b18 41 * }
H_Tsunemoto 0:871ab6846b18 42 * }
H_Tsunemoto 0:871ab6846b18 43 * }
H_Tsunemoto 0:871ab6846b18 44 * @endcode
H_Tsunemoto 0:871ab6846b18 45 *
H_Tsunemoto 0:871ab6846b18 46 * @note
H_Tsunemoto 0:871ab6846b18 47 * On the LPC1768 and LPC2368, the PWMs all share the same
H_Tsunemoto 0:871ab6846b18 48 * period - if you change the period for one, you change it for all.
H_Tsunemoto 0:871ab6846b18 49 * Although routines that change the period maintain the duty cycle
H_Tsunemoto 0:871ab6846b18 50 * for its PWM, all other PWMs will require their duty cycle to be
H_Tsunemoto 0:871ab6846b18 51 * refreshed.
H_Tsunemoto 0:871ab6846b18 52 */
H_Tsunemoto 0:871ab6846b18 53 class PwmOut {
H_Tsunemoto 0:871ab6846b18 54
H_Tsunemoto 0:871ab6846b18 55 public:
H_Tsunemoto 0:871ab6846b18 56
H_Tsunemoto 0:871ab6846b18 57 /** Create a PwmOut connected to the specified pin
H_Tsunemoto 0:871ab6846b18 58 *
H_Tsunemoto 0:871ab6846b18 59 * @param pin PwmOut pin to connect to
H_Tsunemoto 0:871ab6846b18 60 */
H_Tsunemoto 0:871ab6846b18 61 PwmOut(PinName pin) {
H_Tsunemoto 0:871ab6846b18 62 pwmout_init(&_pwm, pin);
H_Tsunemoto 0:871ab6846b18 63 }
H_Tsunemoto 0:871ab6846b18 64
H_Tsunemoto 0:871ab6846b18 65 /** Set the ouput duty-cycle, specified as a percentage (float)
H_Tsunemoto 0:871ab6846b18 66 *
H_Tsunemoto 0:871ab6846b18 67 * @param value A floating-point value representing the output duty-cycle,
H_Tsunemoto 0:871ab6846b18 68 * specified as a percentage. The value should lie between
H_Tsunemoto 0:871ab6846b18 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
H_Tsunemoto 0:871ab6846b18 70 * Values outside this range will be saturated to 0.0f or 1.0f.
H_Tsunemoto 0:871ab6846b18 71 */
H_Tsunemoto 0:871ab6846b18 72 void write(float value) {
H_Tsunemoto 0:871ab6846b18 73 pwmout_write(&_pwm, value);
H_Tsunemoto 0:871ab6846b18 74 }
H_Tsunemoto 0:871ab6846b18 75
H_Tsunemoto 0:871ab6846b18 76 /** Return the current output duty-cycle setting, measured as a percentage (float)
H_Tsunemoto 0:871ab6846b18 77 *
H_Tsunemoto 0:871ab6846b18 78 * @returns
H_Tsunemoto 0:871ab6846b18 79 * A floating-point value representing the current duty-cycle being output on the pin,
H_Tsunemoto 0:871ab6846b18 80 * measured as a percentage. The returned value will lie between
H_Tsunemoto 0:871ab6846b18 81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
H_Tsunemoto 0:871ab6846b18 82 *
H_Tsunemoto 0:871ab6846b18 83 * @note
H_Tsunemoto 0:871ab6846b18 84 * This value may not match exactly the value set by a previous <write>.
H_Tsunemoto 0:871ab6846b18 85 */
H_Tsunemoto 0:871ab6846b18 86 float read() {
H_Tsunemoto 0:871ab6846b18 87 return pwmout_read(&_pwm);
H_Tsunemoto 0:871ab6846b18 88 }
H_Tsunemoto 0:871ab6846b18 89
H_Tsunemoto 0:871ab6846b18 90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
H_Tsunemoto 0:871ab6846b18 91 *
H_Tsunemoto 0:871ab6846b18 92 * @note
H_Tsunemoto 0:871ab6846b18 93 * The resolution is currently in microseconds; periods smaller than this
H_Tsunemoto 0:871ab6846b18 94 * will be set to zero.
H_Tsunemoto 0:871ab6846b18 95 */
H_Tsunemoto 0:871ab6846b18 96 void period(float seconds) {
H_Tsunemoto 0:871ab6846b18 97 pwmout_period(&_pwm, seconds);
H_Tsunemoto 0:871ab6846b18 98 }
H_Tsunemoto 0:871ab6846b18 99
H_Tsunemoto 0:871ab6846b18 100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
H_Tsunemoto 0:871ab6846b18 101 */
H_Tsunemoto 0:871ab6846b18 102 void period_ms(int ms) {
H_Tsunemoto 0:871ab6846b18 103 pwmout_period_ms(&_pwm, ms);
H_Tsunemoto 0:871ab6846b18 104 }
H_Tsunemoto 0:871ab6846b18 105
H_Tsunemoto 0:871ab6846b18 106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
H_Tsunemoto 0:871ab6846b18 107 */
H_Tsunemoto 0:871ab6846b18 108 void period_us(int us) {
H_Tsunemoto 0:871ab6846b18 109 pwmout_period_us(&_pwm, us);
H_Tsunemoto 0:871ab6846b18 110 }
H_Tsunemoto 0:871ab6846b18 111
H_Tsunemoto 0:871ab6846b18 112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
H_Tsunemoto 0:871ab6846b18 113 */
H_Tsunemoto 0:871ab6846b18 114 void pulsewidth(float seconds) {
H_Tsunemoto 0:871ab6846b18 115 pwmout_pulsewidth(&_pwm, seconds);
H_Tsunemoto 0:871ab6846b18 116 }
H_Tsunemoto 0:871ab6846b18 117
H_Tsunemoto 0:871ab6846b18 118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
H_Tsunemoto 0:871ab6846b18 119 */
H_Tsunemoto 0:871ab6846b18 120 void pulsewidth_ms(int ms) {
H_Tsunemoto 0:871ab6846b18 121 pwmout_pulsewidth_ms(&_pwm, ms);
H_Tsunemoto 0:871ab6846b18 122 }
H_Tsunemoto 0:871ab6846b18 123
H_Tsunemoto 0:871ab6846b18 124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
H_Tsunemoto 0:871ab6846b18 125 */
H_Tsunemoto 0:871ab6846b18 126 void pulsewidth_us(int us) {
H_Tsunemoto 0:871ab6846b18 127 pwmout_pulsewidth_us(&_pwm, us);
H_Tsunemoto 0:871ab6846b18 128 }
H_Tsunemoto 0:871ab6846b18 129
H_Tsunemoto 0:871ab6846b18 130 #ifdef MBED_OPERATORS
H_Tsunemoto 0:871ab6846b18 131 /** A operator shorthand for write()
H_Tsunemoto 0:871ab6846b18 132 */
H_Tsunemoto 0:871ab6846b18 133 PwmOut& operator= (float value) {
H_Tsunemoto 0:871ab6846b18 134 write(value);
H_Tsunemoto 0:871ab6846b18 135 return *this;
H_Tsunemoto 0:871ab6846b18 136 }
H_Tsunemoto 0:871ab6846b18 137
H_Tsunemoto 0:871ab6846b18 138 PwmOut& operator= (PwmOut& rhs) {
H_Tsunemoto 0:871ab6846b18 139 write(rhs.read());
H_Tsunemoto 0:871ab6846b18 140 return *this;
H_Tsunemoto 0:871ab6846b18 141 }
H_Tsunemoto 0:871ab6846b18 142
H_Tsunemoto 0:871ab6846b18 143 /** An operator shorthand for read()
H_Tsunemoto 0:871ab6846b18 144 */
H_Tsunemoto 0:871ab6846b18 145 operator float() {
H_Tsunemoto 0:871ab6846b18 146 return read();
H_Tsunemoto 0:871ab6846b18 147 }
H_Tsunemoto 0:871ab6846b18 148 #endif
H_Tsunemoto 0:871ab6846b18 149
H_Tsunemoto 0:871ab6846b18 150 protected:
H_Tsunemoto 0:871ab6846b18 151 pwmout_t _pwm;
H_Tsunemoto 0:871ab6846b18 152 };
H_Tsunemoto 0:871ab6846b18 153
H_Tsunemoto 0:871ab6846b18 154 } // namespace mbed
H_Tsunemoto 0:871ab6846b18 155
H_Tsunemoto 0:871ab6846b18 156 #endif
H_Tsunemoto 0:871ab6846b18 157
H_Tsunemoto 0:871ab6846b18 158 #endif