ES305 Lab 2 Exercise 3 PWM output to OScope

Dependencies:   mbed

Committer:
brianconnett
Date:
Thu Aug 14 16:15:16 2014 +0000
Revision:
0:2da13a76baf2
ES305 Lab 2 Exercise 3; Create a PWM signal to be viewed on the OScope

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brianconnett 0:2da13a76baf2 1 //****************************************
brianconnett 0:2da13a76baf2 2 // ES305 Linear Control Systems
brianconnett 0:2da13a76baf2 3 // Lab 2 - Introduction to mbed microcontroller
brianconnett 0:2da13a76baf2 4 // Exercise 3 - Pulse Width Modulation
brianconnett 0:2da13a76baf2 5 // Adjusts Pulse Width Modulation output. From Pin22 and displays on attached Oscilloscope
brianconnett 0:2da13a76baf2 6 //
brianconnett 0:2da13a76baf2 7 // Brian Connett, LCDR, USN
brianconnett 0:2da13a76baf2 8 //****************************************
brianconnett 0:2da13a76baf2 9
brianconnett 0:2da13a76baf2 10 #include "mbed.h" //mbed header file from mbed.org includes MOST APIs required to operate LPC
brianconnett 0:2da13a76baf2 11
brianconnett 0:2da13a76baf2 12 PwmOut pwm1(p22); //Creates a pulse-width modulation digital output assigned to the variable pwm1 at Pin22
brianconnett 0:2da13a76baf2 13
brianconnett 0:2da13a76baf2 14 int main()
brianconnett 0:2da13a76baf2 15 {
brianconnett 0:2da13a76baf2 16
brianconnett 0:2da13a76baf2 17 pwm1.period(0.010); //Set PWM period to 10ms
brianconnett 0:2da13a76baf2 18 pwm1.period_ms(10); //Set PWM period to 10ms (alternative)
brianconnett 0:2da13a76baf2 19 pwm1.period_us(10000); //Set PWM period to 10ms (alternative)
brianconnett 0:2da13a76baf2 20
brianconnett 0:2da13a76baf2 21 pwm1.write(0.5); //set duty cycle to 50%
brianconnett 0:2da13a76baf2 22 pwm1=0.5; //set duty cycle to 50% (alternative)
brianconnett 0:2da13a76baf2 23
brianconnett 0:2da13a76baf2 24 }