SEARCH
TOOLBOX
LANGUAGES
modified on 18 September 2014 at 14:48 ••• 22,062 views

05-03 PWMFrequency

From Manuals

(Difference between revisions)
Jump to: navigation, search
Support (Talk | contribs)
(Created page with 'This example program uses an analog input to control the period of a PWM. /*Program Example 5.3: Uses analog input to control PWM period …')
Newer edit →

Revision as of 15:28, 14 August 2014

This example program uses an analog input to control the period of a PWM.

/*Program Example 5.3: Uses analog input to control PWM period
                                                                     */
#include "mbed.h"
PwmOut pwm(PWM1);
AnalogIn Ain(A0);

int main() {
    while(1){
      pwm.period(Ain/10+0.001);            // set PWM period
      pwm=0.5;                             // set duty cycle
      wait(0.5);
    }
}


BAM210
Schematic for example 05-03