1 /* mbed Microcontroller Library - PwmOut
2 * Copyright (c) 2007-2011 ARM Limited. All rights reserved.
14 #include "PeripheralNames.h"
20 * A pulse-width modulation digital output
38 * Note that on the LPC1768 and LPC2368, the PWMs all share the same
39 * period - if you change the period for one, you change it for all.
40 * Although routines that change the period maintain the duty cycle
41 * for its PWM, all other PWMs will require their duty cycle to be
44 class PwmOut
: public Base
{
48 /* Constructor: PwmOut
49 * Create a PwmOut connected to the specified pin
52 * pin - PwmOut pin to connect to
54 PwmOut(PinName pin
, const char *name
= NULL
);
57 * Set the ouput duty-cycle, specified as a percentage (float)
60 * value - A floating-point value representing the output duty-cycle,
61 * specified as a percentage. The value should lie between
62 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
63 * Values outside this range will be saturated to 0.0f or 1.0f.
65 void write(float value
);
68 * Return the current output duty-cycle setting, measured as a percentage (float)
71 * returns - A floating-point value representing the current duty-cycle being output on the pin,
72 * measured as a percentage. The returned value will lie between
73 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
76 * This value may not match exactly the value set by a previous <write>.
81 * Set the PWM period, specified in seconds (float), keeping the
82 * duty cycle the same.
85 * The resolution is currently in microseconds; periods smaller than this
86 * will be set to zero.
88 void period(float seconds
);
90 /* Function: period_ms
91 * Set the PWM period, specified in milli-seconds (int), keeping the
92 * duty cycle the same.
94 void period_ms(int ms
);
96 /* Function: period_us
97 * Set the PWM period, specified in micro-seconds (int), keeping the
98 * duty cycle the same.
100 void period_us(int us
);
102 /* Function: pulsewidth
103 * Set the PWM pulsewidth, specified in seconds (float), keeping the
106 void pulsewidth(float seconds
);
108 /* Function: pulsewidth_ms
109 * Set the PWM pulsewidth, specified in milli-seconds (int), keeping
110 * the period the same.
112 void pulsewidth_ms(int ms
);
114 /* Function: pulsewidth_us
115 * Set the PWM pulsewidth, specified in micro-seconds (int), keeping
116 * the period the same.
118 void pulsewidth_us(int us
);
120 #ifdef MBED_OPERATORS
121 /* Function: operator=
122 * A operator shorthand for <write()>
124 PwmOut
& operator= (float value
);
125 PwmOut
& operator= (PwmOut
& rhs
);
127 /* Function: operator float()
128 * An operator shorthand for <read()>
134 virtual const struct rpc_method
*get_rpc_methods();
135 static struct rpc_class
*get_rpc_class();