Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PwmOut Class Reference
A pulse-width modulation digital output. More...
#include <PwmOut.h>
Public Member Functions | |
PwmOut (PinName pin) | |
Create a PwmOut connected to the specified pin. | |
void | write (float value) |
Set the ouput duty-cycle, specified as a percentage (float) | |
float | read () |
Return the current output duty-cycle setting, measured as a percentage (float) | |
void | period (float seconds) |
Set the PWM period, specified in seconds (float), keeping the duty cycle the same. | |
void | period_ms (int ms) |
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. | |
void | period_us (int us) |
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. | |
void | pulsewidth (float seconds) |
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. | |
void | pulsewidth_ms (int ms) |
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. | |
void | pulsewidth_us (int us) |
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. | |
PwmOut & | operator= (float value) |
A operator shorthand for write() | |
operator float () | |
An operator shorthand for read() | |
PwmOut (PinName pin) | |
Create a PwmOut connected to the specified pin. | |
void | write (float value) |
Set the ouput duty-cycle, specified as a percentage (float) | |
float | read () |
Return the current output duty-cycle setting, measured as a percentage (float) | |
void | period (float seconds) |
Set the PWM period, specified in seconds (float), keeping the duty cycle the same. | |
void | period_ms (int ms) |
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. | |
void | period_us (int us) |
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. | |
void | pulsewidth (float seconds) |
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. | |
void | pulsewidth_ms (int ms) |
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. | |
void | pulsewidth_us (int us) |
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. | |
PwmOut & | operator= (float value) |
A operator shorthand for write() | |
operator float () | |
An operator shorthand for read() |
Detailed Description
A pulse-width modulation digital output.
Synchronization level: Interrupt safe
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.
Definition at line 56 of file mbed-dev/api/PwmOut.h.
Constructor & Destructor Documentation
PwmOut | ( | PinName | pin ) |
Create a PwmOut connected to the specified pin.
- Parameters:
-
pin PwmOut pin to connect to
Definition at line 64 of file mbed-dev/api/PwmOut.h.
PwmOut | ( | PinName | pin ) |
Create a PwmOut connected to the specified pin.
- Parameters:
-
pin PwmOut pin to connect to
Definition at line 64 of file usb_cdc/mbed-dev/api/PwmOut.h.
Member Function Documentation
operator float | ( | ) |
An operator shorthand for read()
Definition at line 168 of file mbed-dev/api/PwmOut.h.
operator float | ( | ) |
An operator shorthand for read()
Definition at line 168 of file usb_cdc/mbed-dev/api/PwmOut.h.
PwmOut& operator= | ( | float | value ) |
A operator shorthand for write()
Definition at line 154 of file mbed-dev/api/PwmOut.h.
PwmOut& operator= | ( | float | value ) |
A operator shorthand for write()
Definition at line 154 of file usb_cdc/mbed-dev/api/PwmOut.h.
void period | ( | float | seconds ) |
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.
Definition at line 106 of file mbed-dev/api/PwmOut.h.
void period | ( | float | seconds ) |
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.
Definition at line 106 of file usb_cdc/mbed-dev/api/PwmOut.h.
void period_ms | ( | int | ms ) |
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
Definition at line 114 of file mbed-dev/api/PwmOut.h.
void period_ms | ( | int | ms ) |
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
Definition at line 114 of file usb_cdc/mbed-dev/api/PwmOut.h.
void period_us | ( | int | us ) |
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
Definition at line 122 of file usb_cdc/mbed-dev/api/PwmOut.h.
void period_us | ( | int | us ) |
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
Definition at line 122 of file mbed-dev/api/PwmOut.h.
void pulsewidth | ( | float | seconds ) |
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
Definition at line 130 of file usb_cdc/mbed-dev/api/PwmOut.h.
void pulsewidth | ( | float | seconds ) |
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
Definition at line 130 of file mbed-dev/api/PwmOut.h.
void pulsewidth_ms | ( | int | ms ) |
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
Definition at line 138 of file usb_cdc/mbed-dev/api/PwmOut.h.
void pulsewidth_ms | ( | int | ms ) |
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
Definition at line 138 of file mbed-dev/api/PwmOut.h.
void pulsewidth_us | ( | int | us ) |
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
Definition at line 146 of file mbed-dev/api/PwmOut.h.
void pulsewidth_us | ( | int | us ) |
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
Definition at line 146 of file usb_cdc/mbed-dev/api/PwmOut.h.
float read | ( | void | ) |
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>.
Definition at line 93 of file usb_cdc/mbed-dev/api/PwmOut.h.
float read | ( | void | ) |
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>.
Definition at line 93 of file mbed-dev/api/PwmOut.h.
void write | ( | float | value ) |
Set the ouput duty-cycle, specified as a percentage (float)
- Parameters:
-
value A 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.
Definition at line 77 of file usb_cdc/mbed-dev/api/PwmOut.h.
void write | ( | float | value ) |
Set the ouput duty-cycle, specified as a percentage (float)
- Parameters:
-
value A 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.
Definition at line 77 of file mbed-dev/api/PwmOut.h.
Generated on Tue Jul 12 2022 22:19:22 by
