Ray Liu
/
NuMaker-mbed-PWM1_DCservo
Modify the file main.cpp for M487
Revision 0:6e96e6e154d1, committed 2017-09-29
- Comitter:
- shliu1
- Date:
- Fri Sep 29 05:45:11 2017 +0000
- Commit message:
- main.cpp adds the setting of TARGET_NUMAKER_PFM_M487 for M487
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Fri Sep 29 05:45:11 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Sep 29 05:45:11 2017 +0000 @@ -0,0 +1,25 @@ +# Getting started PWM1 with DC servo motor on mbed OS + + +### Import NuMaker-mbed-PWM1_DCservo from on-line IDE +1. Please choose Nuvoton NuMaker-PFM-XXX as your target platform. +2. Please press the left-up icon "New", then choose "NuMaker PWM1 drive + 5V DC servo motor" from the template list. +3. Your NuMaker-mbed-PWM1_DCservo program is existed. + +#### Now compile +Please press compile icon. + +#### Burn Code & Execute +1. Connect the board NuMaker-PFM-XXX with your PC by USB cable, then there will be one "mbed" disk. +2. Copy the built binary file into "mbed" disk on you PC. +3. Press device's reset button to execute, and you could get the below log by uart console. +------------------------------------------------------------------------------- +...DCserv Start... +DCservo pulse width = 500 +DCservo pulse width = 700 + + : + : +...DCserv End..... +-------------------------------------------------------------------------- + PWM1 outputs to drive DC servo motor \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 29 05:45:11 2017 +0000 @@ -0,0 +1,24 @@ +// NuMaker-PFM-NUC472 : PWM1 output to drive DC servo motor +#include "mbed.h" + +#if defined(TARGET_NUMAKER_PFM_NUC472) +PwmOut pwm1(PF_10); // PWM1 pinname +#elif defined(TARGET_NUMAKER_PFM_M453) +PwmOut pwm1(PC_7); +#elif defined(TARGET_NUMAKER_PFM_M487) +PwmOut pwm1(PA_4); // PWM1 pinname +#endif + +int main() { + + int i=0; + printf("...DCserv Start...\n\r"); + pwm1.period_us(20000); // set PWM period to 20ms (50Hz) + + for (i=500; i<=2500; i=i+200) { // from 0.5ms to 2.5ms + pwm1.pulsewidth_us(i); // set PWM pulse width to rotate motor + Thread::wait(1000); // delay + printf("DCservo pulse width = %d\n\r", i); + } + printf("...DCserv End.....\n\r"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Sep 29 05:45:11 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#ca661f9d28526ca8f874b05432493a489c9671ea