SEARCH
TOOLBOX
LANGUAGES
modified on 17 September 2014 at 19:10 ••• 19,651 views

04-06 SoftwarePWM

From Manuals

(Difference between revisions)
Jump to: navigation, search
(Created page with ' /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison. …')
Line 1: Line 1:
 +
This example uses the same set-up as the previous example. It controls the Servo using a software PWM. The servo motor is a HiTEC HS0422.
  /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.
  /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.

Revision as of 15:13, 14 August 2014

This example uses the same set-up as the previous example. It controls the Servo using a software PWM. The servo motor is a HiTEC HS0422.

/*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.
                                                                             */
#include "mbed.h"
DigitalOut motor(p21);
int i;

int main()
{
   while(1) {
       motor = 0;                    //motor switched off for 5 secs
       wait (5);
       for (i=0; i<5000; i=i+1) {    //5000 PWM cycles, low duty cycle
           motor = 1;
           wait_us(400);               //output high for 400us
           motor = 0;
           wait_us(600);               //output low for 600us
       }
       for (i=0; i<5000; i=i+1) {    //5000 PWM cycles, high duty cycle
           motor = 1;
           wait_us(800);               //output high for 800us
           motor = 0;
           wait_us(200);               //output low for 200us
       }
       motor = 1;                    //motor switched fully on for 5 secs
       wait (5);
   }
}


BAM210
Schematic for example 04-06