SEARCH
TOOLBOX
LANGUAGES
modified on 14 August 2014 at 15:25 ••• 18,909 views

05-02 PWMPulse

From Manuals

Revision as of 15:25, 14 August 2014 by Support (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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