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