1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include "pwmout_api.h"
26 /** A pulse-width modulation digital output
47 * On the LPC1768 and LPC2368, the PWMs all share the same
48 * period - if you change the period for one, you change it for all.
49 * Although routines that change the period maintain the duty cycle
50 * for its PWM, all other PWMs will require their duty cycle to be
57 /** Create a PwmOut connected to the specified pin
59 * @param pin PwmOut pin to connect to
62 pwmout_init(&_pwm, pin);
65 /** Set the ouput duty-cycle, specified as a percentage (float)
67 * @param value A floating-point value representing the output duty-cycle,
68 * specified as a percentage. The value should lie between
69 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
70 * Values outside this range will be saturated to 0.0f or 1.0f.
72 void write(float value) {
73 pwmout_write(&_pwm, value);
76 /** Return the current output duty-cycle setting, measured as a percentage (float)
79 * A floating-point value representing the current duty-cycle being output on the pin,
80 * measured as a percentage. The returned value will lie between
81 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
84 * This value may not match exactly the value set by a previous <write>.
87 return pwmout_read(&_pwm);
90 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
93 * The resolution is currently in microseconds; periods smaller than this
94 * will be set to zero.
96 void period(float seconds) {
97 pwmout_period(&_pwm, seconds);
100 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
102 void period_ms(int ms) {
103 pwmout_period_ms(&_pwm, ms);
106 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
108 void period_us(int us) {
109 pwmout_period_us(&_pwm, us);
112 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
114 void pulsewidth(float seconds) {
115 pwmout_pulsewidth(&_pwm, seconds);
118 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
120 void pulsewidth_ms(int ms) {
121 pwmout_pulsewidth_ms(&_pwm, ms);
124 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
126 void pulsewidth_us(int us) {
127 pwmout_pulsewidth_us(&_pwm, us);
130 #ifdef MBED_OPERATORS
131 /** A operator shorthand for write()
133 PwmOut& operator= (float value) {
138 PwmOut& operator= (PwmOut& rhs) {
143 /** An operator shorthand for read()