by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Fri Aug 31 16:08:03 2012 +0000
Revision:
0:3f1f67f31106
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:3f1f67f31106 1 /*Program Example 4.6: Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison.
robt 0:3f1f67f31106 2 */
robt 0:3f1f67f31106 3 #include "mbed.h"
robt 0:3f1f67f31106 4 DigitalOut motor(p6);
robt 0:3f1f67f31106 5 int i;
robt 0:3f1f67f31106 6 int main()
robt 0:3f1f67f31106 7 {
robt 0:3f1f67f31106 8 while(1) {
robt 0:3f1f67f31106 9 motor = 0; //motor switched off for 5 secs
robt 0:3f1f67f31106 10 wait (5);
robt 0:3f1f67f31106 11 for (i=0; i<5000; i=i+1) { //5000 PWM cycles, low duty cycle
robt 0:3f1f67f31106 12 motor = 1;
robt 0:3f1f67f31106 13 wait_us(400); //output high for 400us
robt 0:3f1f67f31106 14 motor = 0;
robt 0:3f1f67f31106 15 wait_us(600); //output low for 600us
robt 0:3f1f67f31106 16 }
robt 0:3f1f67f31106 17 for (i=0; i<5000; i=i+1) { //5000 PWM cycles, high duty cycle
robt 0:3f1f67f31106 18 motor = 1;
robt 0:3f1f67f31106 19 wait_us(800); //output high for 800us
robt 0:3f1f67f31106 20 motor = 0;
robt 0:3f1f67f31106 21 wait_us(200); //output low for 200us
robt 0:3f1f67f31106 22 }
robt 0:3f1f67f31106 23 motor = 1; //motor switched fully on for 5 secs
robt 0:3f1f67f31106 24 wait (5);
robt 0:3f1f67f31106 25 }
robt 0:3f1f67f31106 26 }
robt 0:3f1f67f31106 27