fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
aria19970520
Date:
Fri Mar 06 06:52:14 2020 +0000
Revision:
3:6f7e05dd8d15
Parent:
0:3e46577dc273
fft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:3e46577dc273 1 /* mbed Microcontroller Library
MikamiUitOpen 0:3e46577dc273 2 * Copyright (c) 2006-2013 ARM Limited
MikamiUitOpen 0:3e46577dc273 3 *
MikamiUitOpen 0:3e46577dc273 4 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 0:3e46577dc273 5 * you may not use this file except in compliance with the License.
MikamiUitOpen 0:3e46577dc273 6 * You may obtain a copy of the License at
MikamiUitOpen 0:3e46577dc273 7 *
MikamiUitOpen 0:3e46577dc273 8 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 0:3e46577dc273 9 *
MikamiUitOpen 0:3e46577dc273 10 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 0:3e46577dc273 11 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 0:3e46577dc273 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 0:3e46577dc273 13 * See the License for the specific language governing permissions and
MikamiUitOpen 0:3e46577dc273 14 * limitations under the License.
MikamiUitOpen 0:3e46577dc273 15 */
MikamiUitOpen 0:3e46577dc273 16 #ifndef MBED_PWMOUT_H
MikamiUitOpen 0:3e46577dc273 17 #define MBED_PWMOUT_H
MikamiUitOpen 0:3e46577dc273 18
MikamiUitOpen 0:3e46577dc273 19 #include "platform.h"
MikamiUitOpen 0:3e46577dc273 20
MikamiUitOpen 0:3e46577dc273 21 #if DEVICE_PWMOUT
MikamiUitOpen 0:3e46577dc273 22 #include "pwmout_api.h"
MikamiUitOpen 0:3e46577dc273 23
MikamiUitOpen 0:3e46577dc273 24 namespace mbed {
MikamiUitOpen 0:3e46577dc273 25
MikamiUitOpen 0:3e46577dc273 26 /** A pulse-width modulation digital output
MikamiUitOpen 0:3e46577dc273 27 *
MikamiUitOpen 0:3e46577dc273 28 * Example
MikamiUitOpen 0:3e46577dc273 29 * @code
MikamiUitOpen 0:3e46577dc273 30 * // Fade a led on.
MikamiUitOpen 0:3e46577dc273 31 * #include "mbed.h"
MikamiUitOpen 0:3e46577dc273 32 *
MikamiUitOpen 0:3e46577dc273 33 * PwmOut led(LED1);
MikamiUitOpen 0:3e46577dc273 34 *
MikamiUitOpen 0:3e46577dc273 35 * int main() {
MikamiUitOpen 0:3e46577dc273 36 * while(1) {
MikamiUitOpen 0:3e46577dc273 37 * led = led + 0.01;
MikamiUitOpen 0:3e46577dc273 38 * wait(0.2);
MikamiUitOpen 0:3e46577dc273 39 * if(led == 1.0) {
MikamiUitOpen 0:3e46577dc273 40 * led = 0;
MikamiUitOpen 0:3e46577dc273 41 * }
MikamiUitOpen 0:3e46577dc273 42 * }
MikamiUitOpen 0:3e46577dc273 43 * }
MikamiUitOpen 0:3e46577dc273 44 * @endcode
MikamiUitOpen 0:3e46577dc273 45 *
MikamiUitOpen 0:3e46577dc273 46 * @note
MikamiUitOpen 0:3e46577dc273 47 * On the LPC1768 and LPC2368, the PWMs all share the same
MikamiUitOpen 0:3e46577dc273 48 * period - if you change the period for one, you change it for all.
MikamiUitOpen 0:3e46577dc273 49 * Although routines that change the period maintain the duty cycle
MikamiUitOpen 0:3e46577dc273 50 * for its PWM, all other PWMs will require their duty cycle to be
MikamiUitOpen 0:3e46577dc273 51 * refreshed.
MikamiUitOpen 0:3e46577dc273 52 */
MikamiUitOpen 0:3e46577dc273 53 class PwmOut {
MikamiUitOpen 0:3e46577dc273 54
MikamiUitOpen 0:3e46577dc273 55 public:
MikamiUitOpen 0:3e46577dc273 56
MikamiUitOpen 0:3e46577dc273 57 /** Create a PwmOut connected to the specified pin
MikamiUitOpen 0:3e46577dc273 58 *
MikamiUitOpen 0:3e46577dc273 59 * @param pin PwmOut pin to connect to
MikamiUitOpen 0:3e46577dc273 60 */
MikamiUitOpen 0:3e46577dc273 61 PwmOut(PinName pin) {
MikamiUitOpen 0:3e46577dc273 62 pwmout_init(&_pwm, pin);
MikamiUitOpen 0:3e46577dc273 63 }
MikamiUitOpen 0:3e46577dc273 64
MikamiUitOpen 0:3e46577dc273 65 /** Set the ouput duty-cycle, specified as a percentage (float)
MikamiUitOpen 0:3e46577dc273 66 *
MikamiUitOpen 0:3e46577dc273 67 * @param value A floating-point value representing the output duty-cycle,
MikamiUitOpen 0:3e46577dc273 68 * specified as a percentage. The value should lie between
MikamiUitOpen 0:3e46577dc273 69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
MikamiUitOpen 0:3e46577dc273 70 * Values outside this range will be saturated to 0.0f or 1.0f.
MikamiUitOpen 0:3e46577dc273 71 */
MikamiUitOpen 0:3e46577dc273 72 void write(float value) {
MikamiUitOpen 0:3e46577dc273 73 pwmout_write(&_pwm, value);
MikamiUitOpen 0:3e46577dc273 74 }
MikamiUitOpen 0:3e46577dc273 75
MikamiUitOpen 0:3e46577dc273 76 /** Return the current output duty-cycle setting, measured as a percentage (float)
MikamiUitOpen 0:3e46577dc273 77 *
MikamiUitOpen 0:3e46577dc273 78 * @returns
MikamiUitOpen 0:3e46577dc273 79 * A floating-point value representing the current duty-cycle being output on the pin,
MikamiUitOpen 0:3e46577dc273 80 * measured as a percentage. The returned value will lie between
MikamiUitOpen 0:3e46577dc273 81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
MikamiUitOpen 0:3e46577dc273 82 *
MikamiUitOpen 0:3e46577dc273 83 * @note
MikamiUitOpen 0:3e46577dc273 84 * This value may not match exactly the value set by a previous <write>.
MikamiUitOpen 0:3e46577dc273 85 */
MikamiUitOpen 0:3e46577dc273 86 float read() {
MikamiUitOpen 0:3e46577dc273 87 return pwmout_read(&_pwm);
MikamiUitOpen 0:3e46577dc273 88 }
MikamiUitOpen 0:3e46577dc273 89
MikamiUitOpen 0:3e46577dc273 90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
MikamiUitOpen 0:3e46577dc273 91 *
MikamiUitOpen 0:3e46577dc273 92 * @note
MikamiUitOpen 0:3e46577dc273 93 * The resolution is currently in microseconds; periods smaller than this
MikamiUitOpen 0:3e46577dc273 94 * will be set to zero.
MikamiUitOpen 0:3e46577dc273 95 */
MikamiUitOpen 0:3e46577dc273 96 void period(float seconds) {
MikamiUitOpen 0:3e46577dc273 97 pwmout_period(&_pwm, seconds);
MikamiUitOpen 0:3e46577dc273 98 }
MikamiUitOpen 0:3e46577dc273 99
MikamiUitOpen 0:3e46577dc273 100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
MikamiUitOpen 0:3e46577dc273 101 */
MikamiUitOpen 0:3e46577dc273 102 void period_ms(int ms) {
MikamiUitOpen 0:3e46577dc273 103 pwmout_period_ms(&_pwm, ms);
MikamiUitOpen 0:3e46577dc273 104 }
MikamiUitOpen 0:3e46577dc273 105
MikamiUitOpen 0:3e46577dc273 106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
MikamiUitOpen 0:3e46577dc273 107 */
MikamiUitOpen 0:3e46577dc273 108 void period_us(int us) {
MikamiUitOpen 0:3e46577dc273 109 pwmout_period_us(&_pwm, us);
MikamiUitOpen 0:3e46577dc273 110 }
MikamiUitOpen 0:3e46577dc273 111
MikamiUitOpen 0:3e46577dc273 112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
MikamiUitOpen 0:3e46577dc273 113 */
MikamiUitOpen 0:3e46577dc273 114 void pulsewidth(float seconds) {
MikamiUitOpen 0:3e46577dc273 115 pwmout_pulsewidth(&_pwm, seconds);
MikamiUitOpen 0:3e46577dc273 116 }
MikamiUitOpen 0:3e46577dc273 117
MikamiUitOpen 0:3e46577dc273 118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
MikamiUitOpen 0:3e46577dc273 119 */
MikamiUitOpen 0:3e46577dc273 120 void pulsewidth_ms(int ms) {
MikamiUitOpen 0:3e46577dc273 121 pwmout_pulsewidth_ms(&_pwm, ms);
MikamiUitOpen 0:3e46577dc273 122 }
MikamiUitOpen 0:3e46577dc273 123
MikamiUitOpen 0:3e46577dc273 124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
MikamiUitOpen 0:3e46577dc273 125 */
MikamiUitOpen 0:3e46577dc273 126 void pulsewidth_us(int us) {
MikamiUitOpen 0:3e46577dc273 127 pwmout_pulsewidth_us(&_pwm, us);
MikamiUitOpen 0:3e46577dc273 128 }
MikamiUitOpen 0:3e46577dc273 129
MikamiUitOpen 0:3e46577dc273 130 #ifdef MBED_OPERATORS
MikamiUitOpen 0:3e46577dc273 131 /** A operator shorthand for write()
MikamiUitOpen 0:3e46577dc273 132 */
MikamiUitOpen 0:3e46577dc273 133 PwmOut& operator= (float value) {
MikamiUitOpen 0:3e46577dc273 134 write(value);
MikamiUitOpen 0:3e46577dc273 135 return *this;
MikamiUitOpen 0:3e46577dc273 136 }
MikamiUitOpen 0:3e46577dc273 137
MikamiUitOpen 0:3e46577dc273 138 PwmOut& operator= (PwmOut& rhs) {
MikamiUitOpen 0:3e46577dc273 139 write(rhs.read());
MikamiUitOpen 0:3e46577dc273 140 return *this;
MikamiUitOpen 0:3e46577dc273 141 }
MikamiUitOpen 0:3e46577dc273 142
MikamiUitOpen 0:3e46577dc273 143 /** An operator shorthand for read()
MikamiUitOpen 0:3e46577dc273 144 */
MikamiUitOpen 0:3e46577dc273 145 operator float() {
MikamiUitOpen 0:3e46577dc273 146 return read();
MikamiUitOpen 0:3e46577dc273 147 }
MikamiUitOpen 0:3e46577dc273 148 #endif
MikamiUitOpen 0:3e46577dc273 149
MikamiUitOpen 0:3e46577dc273 150 protected:
MikamiUitOpen 0:3e46577dc273 151 pwmout_t _pwm;
MikamiUitOpen 0:3e46577dc273 152 };
MikamiUitOpen 0:3e46577dc273 153
MikamiUitOpen 0:3e46577dc273 154 } // namespace mbed
MikamiUitOpen 0:3e46577dc273 155
MikamiUitOpen 0:3e46577dc273 156 #endif
MikamiUitOpen 0:3e46577dc273 157
MikamiUitOpen 0:3e46577dc273 158 #endif