Ray Liu
/
NuMaker-mbed-PWM1_DCservo
Modify the file main.cpp for M487
main.cpp@0:6e96e6e154d1, 2017-09-29 (annotated)
- Committer:
- shliu1
- Date:
- Fri Sep 29 05:45:11 2017 +0000
- Revision:
- 0:6e96e6e154d1
main.cpp adds the setting of TARGET_NUMAKER_PFM_M487 for M487
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shliu1 | 0:6e96e6e154d1 | 1 | // NuMaker-PFM-NUC472 : PWM1 output to drive DC servo motor |
shliu1 | 0:6e96e6e154d1 | 2 | #include "mbed.h" |
shliu1 | 0:6e96e6e154d1 | 3 | |
shliu1 | 0:6e96e6e154d1 | 4 | #if defined(TARGET_NUMAKER_PFM_NUC472) |
shliu1 | 0:6e96e6e154d1 | 5 | PwmOut pwm1(PF_10); // PWM1 pinname |
shliu1 | 0:6e96e6e154d1 | 6 | #elif defined(TARGET_NUMAKER_PFM_M453) |
shliu1 | 0:6e96e6e154d1 | 7 | PwmOut pwm1(PC_7); |
shliu1 | 0:6e96e6e154d1 | 8 | #elif defined(TARGET_NUMAKER_PFM_M487) |
shliu1 | 0:6e96e6e154d1 | 9 | PwmOut pwm1(PA_4); // PWM1 pinname |
shliu1 | 0:6e96e6e154d1 | 10 | #endif |
shliu1 | 0:6e96e6e154d1 | 11 | |
shliu1 | 0:6e96e6e154d1 | 12 | int main() { |
shliu1 | 0:6e96e6e154d1 | 13 | |
shliu1 | 0:6e96e6e154d1 | 14 | int i=0; |
shliu1 | 0:6e96e6e154d1 | 15 | printf("...DCserv Start...\n\r"); |
shliu1 | 0:6e96e6e154d1 | 16 | pwm1.period_us(20000); // set PWM period to 20ms (50Hz) |
shliu1 | 0:6e96e6e154d1 | 17 | |
shliu1 | 0:6e96e6e154d1 | 18 | for (i=500; i<=2500; i=i+200) { // from 0.5ms to 2.5ms |
shliu1 | 0:6e96e6e154d1 | 19 | pwm1.pulsewidth_us(i); // set PWM pulse width to rotate motor |
shliu1 | 0:6e96e6e154d1 | 20 | Thread::wait(1000); // delay |
shliu1 | 0:6e96e6e154d1 | 21 | printf("DCservo pulse width = %d\n\r", i); |
shliu1 | 0:6e96e6e154d1 | 22 | } |
shliu1 | 0:6e96e6e154d1 | 23 | printf("...DCserv End.....\n\r"); |
shliu1 | 0:6e96e6e154d1 | 24 | } |