NuMaker PWM1 drive +5V DC servo motor

Committer:
ccli8
Date:
Wed Apr 18 17:08:51 2018 +0800
Revision:
9:64a0098bb8df
Parent:
8:03564884cf96
Child:
12:c7ca6b6c7fbc
Unify using UNO D3 for PWM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rkuo2000 0:68283046ceea 1 // NuMaker-PFM-NUC472 : PWM1 output to drive DC servo motor
rkuo2000 0:68283046ceea 2 #include "mbed.h"
rkuo2000 0:68283046ceea 3
ccli8 9:64a0098bb8df 4 /* NOTE: Most targets has UNO D3 for PWM. Check it for supporting new targets */
ccli8 9:64a0098bb8df 5 PwmOut pwm1(D3);
rkuo2000 0:68283046ceea 6
rkuo2000 0:68283046ceea 7 int main() {
rkuo2000 0:68283046ceea 8
rkuo2000 0:68283046ceea 9 int i=0;
rkuo2000 0:68283046ceea 10 printf("...DCserv Start...\n\r");
rkuo2000 0:68283046ceea 11 pwm1.period_us(20000); // set PWM period to 20ms (50Hz)
rkuo2000 0:68283046ceea 12
rkuo2000 0:68283046ceea 13 for (i=500; i<=2500; i=i+200) { // from 0.5ms to 2.5ms
rkuo2000 0:68283046ceea 14 pwm1.pulsewidth_us(i); // set PWM pulse width to rotate motor
rkuo2000 0:68283046ceea 15 Thread::wait(1000); // delay
rkuo2000 0:68283046ceea 16 printf("DCservo pulse width = %d\n\r", i);
rkuo2000 0:68283046ceea 17 }
rkuo2000 0:68283046ceea 18 printf("...DCserv End.....\n\r");
rkuo2000 0:68283046ceea 19 }