example for using fast pwm

Dependencies:   FastPWM mbed

Example for the use of fast pwm on an stm nucleo F302R8.

Revision:
4:f229692e352f
Parent:
3:14ba055f4bb7
Child:
5:41aafda546a3
--- a/main.cpp	Thu Mar 24 14:55:06 2016 +0000
+++ b/main.cpp	Thu Mar 31 12:24:57 2016 +0000
@@ -1,64 +1,9 @@
 #include "mbed.h"
 #include "FastPWM.h"
-//setting pwm outputs
-    FastPWM buck(D11,1);
-    FastPWM boost(D10,1);
-//seting analog input  
-    AnalogIn analog0_value(A0);
-    AnalogIn analog1_value(A1);
-//setup serial coms
-Serial pc(USBTX, USBRX);
-//setup ticker 
-    Ticker toggle_sample_ticker;
-//setup gobal variables
-    
-//setup interrupt sample function
-   
-                    
-//setup pwm function               
-    void buckpwm(int pwm){
-             if (pwm <=500) {
-                    buck.pulsewidth_ticks( pwm );
-                                } 
-                            }
-
+    FastPWM fastpwm(D11,1);    
 int main() {
-//setup pwm
-    uint32_t period_ticks=720;
-    buck.prescaler(1);
-    boost.prescaler(1);
-// define period of pwm...
-    buck.period_ticks (period_ticks);
-    boost.period_ticks (period_ticks); 
-//define duty cycle
- int duty1 = 10;
- int duty2 = 5;
-    buckpwm(duty1);   
-    boost.pulsewidth_us(duty2);
-//boostpwm(10);   
+    fastpwm.period_ticks (720);
+    fastpwm.pulsewidth_ticks( 350);
     while(1) {
-               buckpwm(duty1);   
-                boost.pulsewidth_us(duty2);
-               //wait(1);
-               float sample1= analog0_value.read()*3300;
-               float sample2= analog0_value.read()*3300;
-               float sample3= analog0_value.read()*3300;
-               float sample4= analog0_value.read()*3300;
-                float average;
-                average=(sample1+sample2+sample3+sample4)/4;
-               float sample5= analog1_value.read()*3500;
-            //pc.printf("%.0f and %.0f duty1 %d \n\r  ", average,sample5,duty1);
-                if (duty1 >= 500 ) { // setting duty cycle limits
-                                  duty1 = 500;
-                                    }
-                if (duty1 <= 1 ) { // setting duty cycle limits
-                                  duty1 = 1;
-                                    }
-                if (average > 2000 ) { // If the value is greater than 7Mv increase the duty cycle
-                                  duty1 = duty1+1;
-                                    }
-                if (average < 2000 ) { //If the value is smaller than 7Mv decrease the duty cycle
-                                  duty1 = duty1-1;
-                                    }
-    }
+             }
 }