Search Code
About PwmTest

First published 01 Dec 2009, with 2 revisions since.
Last update: 01 Dec 2009.
View history

Last change message: N/A

Import this program

PwmTest

Published 01 Dec 2009, by   user Simon Ford   tag No tags
Embed: (wiki syntax)

« Back to documentation index

You are viewing an out of date revision of PwmTest! View latest revision

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Testing PWM channel 0 vs channel 1 behaviour, sford
00002 
00003 #include "mbed.h"
00004 
00005 PwmOut pwm1(p26);
00006 PwmOut pwm2(p25);
00007 
00008 int main() {
00009 
00010     uint32_t t = 10000;
00011 
00012     // set period
00013     LPC_PWM1->MR0 = t;
00014     LPC_PWM1->LER |= 1 << 0;
00015 
00016     while (1) {
00017 
00018         // set pulsewidth to 100%
00019         LPC_PWM1->MR1 = t;
00020         LPC_PWM1->MR2 = t;
00021         LPC_PWM1->LER |= 0x6;
00022 
00023         // wait for update
00024         while (LPC_PWM1->LER);
00025 
00026         // set pulsewidth less than 100%
00027         LPC_PWM1->MR1 = t - 500;
00028         LPC_PWM1->MR2 = t - 500;
00029         LPC_PWM1->LER |= 0x6;
00030 
00031         // wait for update
00032         while (LPC_PWM1->LER);
00033     }
00034 }