control de velocidad progresivo de un motor de CC en ambas direcciones

Dependencies:   mbed

Fork of pwm_example by Baser Kandehir

Files at this revision

API Documentation at this revision

Comitter:
javierjsp
Date:
Wed Mar 22 17:08:53 2017 +0000
Parent:
3:1174132d5190
Commit message:
version 1

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
diff -r 1174132d5190 -r 84669d69a2d4 main.cpp
--- a/main.cpp	Tue Jul 21 08:22:09 2015 +0000
+++ b/main.cpp	Wed Mar 22 17:08:53 2017 +0000
@@ -47,26 +47,39 @@
 
 #include "mbed.h"
 
-PwmOut PWM1(p21);     // pwm outputs
-PwmOut PWM2(p22);
+PwmOut PWM1(PF_8);     // pwm outputs
+PwmOut PWM2(PF_7);
+DigitalOut led1(LED1);
 
 /* Function prototype */
 void motorControl(bool dir, float pwmVal);
 
 int main()
 {
+    
+    led1 = 1;
+    wait(1);
+    led1 = 0;
+    PWM1.write(0);       // Duty cycles are initially zero   
+    PWM2.write(0);   
+    PWM1.period(0.02f);   // 1 kHz pwm frequency
+    PWM2.period(0.02f);
+    
     while(1)
     {
-        for(float i=0;i<1;i=i+0.01)  // increase speed from 0 to 1 in 5 seconds (50ms*100). 
+        for(float i=0;i<1;i=i+0.01f)  // increase speed from 0 to 1 in 5 seconds (50ms*100). 
         {
             motorControl(1,i);
-            wait_ms(50);    
-        }
-        for(float i=1;i>0;i=i-0.01)  // decrease speed from 1 to 0 in 5 seconds (50ms*100).
+            wait(0.05f);    
+        }  
+        for(float i=1;i>0;i=i-0.01f)  // decrease speed from 1 to 0 in 5 seconds (50ms*100).
         {
             motorControl(0,i);
-            wait_ms(50);    
+            wait(0.05f);    
         }   
+        led1 = 1;
+        wait(0.5);
+        led1 = 0;
     }    
 }
 
@@ -74,19 +87,14 @@
 // a motor. Motor drivers like L293D can be used.
 void motorControl(bool dir, float pwmVal)
 {
-    PWM1.write(0);       // Duty cycles are initially zero   
-    PWM2.write(0);   
-    PWM1.period_ms(1);   // 1 kHz pwm frequency
-    PWM2.period_ms(1);
-    
     if(dir==1)               // forward direction
     {
+        PWM2.write(0);   
         PWM1.write(pwmVal);        
-        PWM2.write(0);   
     }
     else if(dir==0)         // reverse direction
-    {
-        PWM2.write(pwmVal);        
+    {     
         PWM1.write(0);       
+        PWM2.write(pwmVal);   
     }    
 }
\ No newline at end of file
diff -r 1174132d5190 -r 84669d69a2d4 mbed.bld
--- a/mbed.bld	Tue Jul 21 08:22:09 2015 +0000
+++ b/mbed.bld	Wed Mar 22 17:08:53 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb
\ No newline at end of file