mbed-drivers
Public Member Functions | Protected Attributes | List of all members
mbed::PwmOut Class Reference

#include <PwmOut.h>

Public Member Functions

 PwmOut (PinName pin)
 
void write (float value)
 
float read ()
 
void period (float seconds)
 
void period_ms (int ms)
 
void period_us (int us)
 
void pulsewidth (float seconds)
 
void pulsewidth_ms (int ms)
 
void pulsewidth_us (int us)
 
PwmOutoperator= (float value)
 
PwmOutoperator= (PwmOut &rhs)
 
 operator float ()
 

Protected Attributes

pwmout_t _pwm
 

Detailed Description

A pulse-width modulation digital output

Example

// Fade a led on.
#include "mbed.h"
PwmOut led(LED1);
int main() {
while(1) {
led = led + 0.01;
wait(0.2);
if(led == 1.0) {
led = 0;
}
}
}
Note
On the LPC1768 and LPC2368, the PWMs all share the same period - if you change the period for one, you change it for all. Although routines that change the period maintain the duty cycle for its PWM, all other PWMs will require their duty cycle to be refreshed.

Constructor & Destructor Documentation

mbed::PwmOut::PwmOut ( PinName  pin)
inline

Create a PwmOut connected to the specified pin

Parameters
pinPwmOut pin to connect to

Member Function Documentation

mbed::PwmOut::operator float ( )
inline

An operator shorthand for read()

PwmOut& mbed::PwmOut::operator= ( float  value)
inline

A operator shorthand for write()

void mbed::PwmOut::period ( float  seconds)
inline

Set the PWM period, specified in seconds (float), keeping the duty cycle the same.

Note
The resolution is currently in microseconds; periods smaller than this will be set to zero.
void mbed::PwmOut::period_ms ( int  ms)
inline

Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.

void mbed::PwmOut::period_us ( int  us)
inline

Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.

void mbed::PwmOut::pulsewidth ( float  seconds)
inline

Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.

void mbed::PwmOut::pulsewidth_ms ( int  ms)
inline

Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.

void mbed::PwmOut::pulsewidth_us ( int  us)
inline

Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.

float mbed::PwmOut::read ( )
inline

Return the current output duty-cycle setting, measured as a percentage (float)

Returns
A floating-point value representing the current duty-cycle being output on the pin, measured as a percentage. The returned value will lie between 0.0f (representing on 0%) and 1.0f (representing on 100%).
Note
This value may not match exactly the value set by a previous <write>.
void mbed::PwmOut::write ( float  value)
inline

Set the ouput duty-cycle, specified as a percentage (float)

Parameters
valueA floating-point value representing the output duty-cycle, specified as a percentage. The value should lie between 0.0f (representing on 0%) and 1.0f (representing on 100%). Values outside this range will be saturated to 0.0f or 1.0f.

The documentation for this class was generated from the following file: