This is my quadcopter prototype software, still in development!

Committer:
Anaesthetix
Date:
Tue Jul 23 14:01:42 2013 +0000
Revision:
1:ac68f0368a77
Parent:
0:978110f7f027
Other accelerometer added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:978110f7f027 1 /* mbed Microcontroller Library - PwmOut
Anaesthetix 0:978110f7f027 2 * Copyright (c) 2007-2011 ARM Limited. All rights reserved.
Anaesthetix 0:978110f7f027 3 */
Anaesthetix 0:978110f7f027 4
Anaesthetix 0:978110f7f027 5 #ifndef MBED_PWMOUT_H
Anaesthetix 0:978110f7f027 6 #define MBED_PWMOUT_H
Anaesthetix 0:978110f7f027 7
Anaesthetix 0:978110f7f027 8 #include "device.h"
Anaesthetix 0:978110f7f027 9
Anaesthetix 0:978110f7f027 10 #if DEVICE_PWMOUT
Anaesthetix 0:978110f7f027 11
Anaesthetix 0:978110f7f027 12 #include "platform.h"
Anaesthetix 0:978110f7f027 13 #include "PinNames.h"
Anaesthetix 0:978110f7f027 14 #include "PeripheralNames.h"
Anaesthetix 0:978110f7f027 15 #include "Base.h"
Anaesthetix 0:978110f7f027 16
Anaesthetix 0:978110f7f027 17 namespace mbed {
Anaesthetix 0:978110f7f027 18
Anaesthetix 0:978110f7f027 19 /* Class: PwmOut
Anaesthetix 0:978110f7f027 20 * A pulse-width modulation digital output
Anaesthetix 0:978110f7f027 21 *
Anaesthetix 0:978110f7f027 22 * Example
Anaesthetix 0:978110f7f027 23 * > // Fade a led on.
Anaesthetix 0:978110f7f027 24 * > #include "mbed.h"
Anaesthetix 0:978110f7f027 25 * >
Anaesthetix 0:978110f7f027 26 * > PwmOut led(LED1);
Anaesthetix 0:978110f7f027 27 * >
Anaesthetix 0:978110f7f027 28 * > int main() {
Anaesthetix 0:978110f7f027 29 * > while(1) {
Anaesthetix 0:978110f7f027 30 * > led = led + 0.01;
Anaesthetix 0:978110f7f027 31 * > wait(0.2);
Anaesthetix 0:978110f7f027 32 * > if(led == 1.0) {
Anaesthetix 0:978110f7f027 33 * > led = 0;
Anaesthetix 0:978110f7f027 34 * > }
Anaesthetix 0:978110f7f027 35 * > }
Anaesthetix 0:978110f7f027 36 * > }
Anaesthetix 0:978110f7f027 37 *
Anaesthetix 0:978110f7f027 38 * Note that on the LPC1768 and LPC2368, the PWMs all share the same
Anaesthetix 0:978110f7f027 39 * period - if you change the period for one, you change it for all.
Anaesthetix 0:978110f7f027 40 * Although routines that change the period maintain the duty cycle
Anaesthetix 0:978110f7f027 41 * for its PWM, all other PWMs will require their duty cycle to be
Anaesthetix 0:978110f7f027 42 * refreshed.
Anaesthetix 0:978110f7f027 43 */
Anaesthetix 0:978110f7f027 44 class PwmOut : public Base {
Anaesthetix 0:978110f7f027 45
Anaesthetix 0:978110f7f027 46 public:
Anaesthetix 0:978110f7f027 47
Anaesthetix 0:978110f7f027 48 /* Constructor: PwmOut
Anaesthetix 0:978110f7f027 49 * Create a PwmOut connected to the specified pin
Anaesthetix 0:978110f7f027 50 *
Anaesthetix 0:978110f7f027 51 * Variables:
Anaesthetix 0:978110f7f027 52 * pin - PwmOut pin to connect to
Anaesthetix 0:978110f7f027 53 */
Anaesthetix 0:978110f7f027 54 PwmOut(PinName pin, const char *name = NULL);
Anaesthetix 0:978110f7f027 55
Anaesthetix 0:978110f7f027 56 /* Function: write
Anaesthetix 0:978110f7f027 57 * Set the ouput duty-cycle, specified as a percentage (float)
Anaesthetix 0:978110f7f027 58 *
Anaesthetix 0:978110f7f027 59 * Variables:
Anaesthetix 0:978110f7f027 60 * value - A floating-point value representing the output duty-cycle,
Anaesthetix 0:978110f7f027 61 * specified as a percentage. The value should lie between
Anaesthetix 0:978110f7f027 62 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
Anaesthetix 0:978110f7f027 63 * Values outside this range will be saturated to 0.0f or 1.0f.
Anaesthetix 0:978110f7f027 64 */
Anaesthetix 0:978110f7f027 65 void write(float value);
Anaesthetix 0:978110f7f027 66
Anaesthetix 0:978110f7f027 67 /* Function: read
Anaesthetix 0:978110f7f027 68 * Return the current output duty-cycle setting, measured as a percentage (float)
Anaesthetix 0:978110f7f027 69 *
Anaesthetix 0:978110f7f027 70 * Variables:
Anaesthetix 0:978110f7f027 71 * returns - A floating-point value representing the current duty-cycle being output on the pin,
Anaesthetix 0:978110f7f027 72 * measured as a percentage. The returned value will lie between
Anaesthetix 0:978110f7f027 73 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
Anaesthetix 0:978110f7f027 74 *
Anaesthetix 0:978110f7f027 75 * Note:
Anaesthetix 0:978110f7f027 76 * This value may not match exactly the value set by a previous <write>.
Anaesthetix 0:978110f7f027 77 */
Anaesthetix 0:978110f7f027 78 float read();
Anaesthetix 0:978110f7f027 79
Anaesthetix 0:978110f7f027 80 /* Function: period
Anaesthetix 0:978110f7f027 81 * Set the PWM period, specified in seconds (float), keeping the
Anaesthetix 0:978110f7f027 82 * duty cycle the same.
Anaesthetix 0:978110f7f027 83 *
Anaesthetix 0:978110f7f027 84 * Note:
Anaesthetix 0:978110f7f027 85 * The resolution is currently in microseconds; periods smaller than this
Anaesthetix 0:978110f7f027 86 * will be set to zero.
Anaesthetix 0:978110f7f027 87 */
Anaesthetix 0:978110f7f027 88 void period(float seconds);
Anaesthetix 0:978110f7f027 89
Anaesthetix 0:978110f7f027 90 /* Function: period_ms
Anaesthetix 0:978110f7f027 91 * Set the PWM period, specified in milli-seconds (int), keeping the
Anaesthetix 0:978110f7f027 92 * duty cycle the same.
Anaesthetix 0:978110f7f027 93 */
Anaesthetix 0:978110f7f027 94 void period_ms(int ms);
Anaesthetix 0:978110f7f027 95
Anaesthetix 0:978110f7f027 96 /* Function: period_us
Anaesthetix 0:978110f7f027 97 * Set the PWM period, specified in micro-seconds (int), keeping the
Anaesthetix 0:978110f7f027 98 * duty cycle the same.
Anaesthetix 0:978110f7f027 99 */
Anaesthetix 0:978110f7f027 100 void period_us(int us);
Anaesthetix 0:978110f7f027 101
Anaesthetix 0:978110f7f027 102 /* Function: pulsewidth
Anaesthetix 0:978110f7f027 103 * Set the PWM pulsewidth, specified in seconds (float), keeping the
Anaesthetix 0:978110f7f027 104 * period the same.
Anaesthetix 0:978110f7f027 105 */
Anaesthetix 0:978110f7f027 106 void pulsewidth(float seconds);
Anaesthetix 0:978110f7f027 107
Anaesthetix 0:978110f7f027 108 /* Function: pulsewidth_ms
Anaesthetix 0:978110f7f027 109 * Set the PWM pulsewidth, specified in milli-seconds (int), keeping
Anaesthetix 0:978110f7f027 110 * the period the same.
Anaesthetix 0:978110f7f027 111 */
Anaesthetix 0:978110f7f027 112 void pulsewidth_ms(int ms);
Anaesthetix 0:978110f7f027 113
Anaesthetix 0:978110f7f027 114 /* Function: pulsewidth_us
Anaesthetix 0:978110f7f027 115 * Set the PWM pulsewidth, specified in micro-seconds (int), keeping
Anaesthetix 0:978110f7f027 116 * the period the same.
Anaesthetix 0:978110f7f027 117 */
Anaesthetix 0:978110f7f027 118 void pulsewidth_us(int us);
Anaesthetix 0:978110f7f027 119
Anaesthetix 0:978110f7f027 120 #ifdef MBED_OPERATORS
Anaesthetix 0:978110f7f027 121 /* Function: operator=
Anaesthetix 0:978110f7f027 122 * A operator shorthand for <write()>
Anaesthetix 0:978110f7f027 123 */
Anaesthetix 0:978110f7f027 124 PwmOut& operator= (float value);
Anaesthetix 0:978110f7f027 125 PwmOut& operator= (PwmOut& rhs);
Anaesthetix 0:978110f7f027 126
Anaesthetix 0:978110f7f027 127 /* Function: operator float()
Anaesthetix 0:978110f7f027 128 * An operator shorthand for <read()>
Anaesthetix 0:978110f7f027 129 */
Anaesthetix 0:978110f7f027 130 operator float();
Anaesthetix 0:978110f7f027 131 #endif
Anaesthetix 0:978110f7f027 132
Anaesthetix 0:978110f7f027 133 #ifdef MBED_RPC
Anaesthetix 0:978110f7f027 134 virtual const struct rpc_method *get_rpc_methods();
Anaesthetix 0:978110f7f027 135 static struct rpc_class *get_rpc_class();
Anaesthetix 0:978110f7f027 136 #endif
Anaesthetix 0:978110f7f027 137
Anaesthetix 0:978110f7f027 138 protected:
Anaesthetix 0:978110f7f027 139
Anaesthetix 0:978110f7f027 140 PWMName _pwm;
Anaesthetix 0:978110f7f027 141
Anaesthetix 0:978110f7f027 142 };
Anaesthetix 0:978110f7f027 143
Anaesthetix 0:978110f7f027 144 } // namespace mbed
Anaesthetix 0:978110f7f027 145
Anaesthetix 0:978110f7f027 146 #endif
Anaesthetix 0:978110f7f027 147
Anaesthetix 0:978110f7f027 148 #endif