Rob Toulson / Mbed 2 deprecated PE_04-06_SoftwarePWM

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.
00002                                                                               */
00003 #include "mbed.h"
00004 DigitalOut motor(p6);
00005 int i;
00006 int main()
00007 {
00008     while(1) {
00009         motor = 0;                    //motor switched off for 5 secs
00010         wait (5);
00011         for (i=0; i<5000; i=i+1) {    //5000 PWM cycles, low duty cycle
00012             motor = 1;
00013             wait_us(400);               //output high for 400us
00014             motor = 0;
00015             wait_us(600);               //output low for 600us
00016         }
00017         for (i=0; i<5000; i=i+1) {    //5000 PWM cycles, high duty cycle
00018             motor = 1;
00019             wait_us(800);               //output high for 800us
00020             motor = 0;
00021             wait_us(200);               //output low for 200us
00022         }
00023         motor = 1;                    //motor switched fully on for 5 secs
00024         wait (5);
00025     }
00026 }
00027