mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
2:e9a661555b58
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

Who changed what in which revision?

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