SEARCH
TOOLBOX
LANGUAGES
modified on 18 September 2014 at 14:47 ••• 18,925 views

05-02 PWMPulse

From Manuals

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

Revision as of 15:25, 14 August 2014

This example uses an analog input to control the duty cycle of a PWM in a fixed period.

/*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period
                                                    */
#include "mbed.h"
PwmOut pwm(PWM1);
AnalogIn Ain(A0);          //defines analog input on A0

int main() {
  while(1){
    pwm.period(0.010);  // set PWM period to 10 ms
    pwm=Ain;            //Analog in value becomes PWM duty, both are type float
    wait(0.1);
  }
}


File:BAM210 05 02 SCH.png
Schematic for example 05-02