Simon Ford
/
PWMTest
Revision 1:4115ae4cbc76, committed 2011-01-20
- Comitter:
- simon
- Date:
- Thu Jan 20 14:15:24 2011 +0000
- Parent:
- 0:c795e64e9eb0
- Commit message:
- A program displaying strange memory behavior
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Dec 01 11:01:48 2009 +0000 +++ b/main.cpp Thu Jan 20 14:15:24 2011 +0000 @@ -1,34 +1,44 @@ -// Testing PWM channel 0 vs channel 1 behaviour, sford - #include "mbed.h" -PwmOut pwm1(p26); -PwmOut pwm2(p25); +/* + +based on http://mbed.org/forum/mbed/topic/1704/ + +the Pwm part doesnt work; only led1 comes on + +if the printf in the while is removed, or the PwmOut is moved to be static/global, all works fine + +seems like a memory problem. +*/ int main() { - - uint32_t t = 10000; + DigitalOut led1(LED1); + float f=0.0; - // set period - LPC_PWM1->MR0 = t; - LPC_PWM1->LER |= 1 << 0; + PwmOut display(LED2); - while (1) { + display.period_ms(1); - // set pulsewidth to 100% - LPC_PWM1->MR1 = t; - LPC_PWM1->MR2 = t; - LPC_PWM1->LER |= 0x6; - - // wait for update - while (LPC_PWM1->LER); - - // set pulsewidth less than 100% - LPC_PWM1->MR1 = t - 500; - LPC_PWM1->MR2 = t - 500; - LPC_PWM1->LER |= 0x6; - - // wait for update - while (LPC_PWM1->LER); + display=f; + + AnalogIn light(p20); + + for (int i=0;i<100;i++) + { + f=f+0.01; + display=f; + wait (0.03); + } + printf("%f\n",display.read()); + led1=1; + + while (true) + { + double d=light; + double sq=pow(d,0.6); + display.write(sq*3); + + printf("%f / %f\n",d,sq); + wait(1); } }
--- a/mbed.bld Tue Dec 01 11:01:48 2009 +0000 +++ b/mbed.bld Thu Jan 20 14:15:24 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/32af5db564d4 +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e