Tony Jeon
/
SimplePWM
Simple PWM for motor control
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 #define FORWARD 0 00004 #define BACKWARD 1 00005 00006 00007 int main() { 00008 00009 Serial pc(USBTX, USBRX); 00010 pc.baud(115200); 00011 00012 // This program is for NXP LPC1768. If you use other platform, change pin number!! ============ 00013 PwmOut mypwm(p21);// NXP 1768 platform PWM output 00014 DigitalOut direction(p5);// NXP 1768 platform GPIO pin #5 output 00015 DigitalOut brake(p6);// NXP 1768 platform GPIO pin #6 output 00016 DigitalOut myled(LED1);//For LED blinking. 00017 //============================================================================================= 00018 00019 direction = FORWARD;// FORWARD == 0;. 00020 00021 while(1) { 00022 myled = !myled; 00023 mypwm = mypwm + 0.05;// 0.05 is 5% duty pulse width 00024 wait(3); 00025 if( mypwm >= 1) 00026 { 00027 brake = 1; //stop 00028 } 00029 } 00030 }
Generated on Tue Jul 26 2022 04:16:14 by 1.7.2