Betterfrost / Mbed 2 deprecated timer_based_1kHz_ramp

Dependencies:   mbed

Fork of BoxBrovoEcho_OCt3 by Betterfrost

Revision:
5:0d28bca5dd26
Parent:
4:2c5dbea00157
Child:
6:c905afa84d8a
--- a/main.cpp	Wed Sep 12 16:37:35 2018 +0000
+++ b/main.cpp	Fri Sep 21 17:29:36 2018 +0000
@@ -26,15 +26,17 @@
 AnalogIn voltage(p16);
 
 // ------------------------- Main Parameters  ------------------------------- //
-float resistance = 10.0;
-float V_batt = 160.0;
-float I_out = 10.0;
+float resistance = 9.6;
+float V_batt = 400.0;
+float I_out = 20.0;
 float V_out = 0.0;
 float freq = 30;     //switching frequency in Hz
+Timer TIMER;
+float RunTime = 20;  // in seconds
 
 // -------------------- Current Sensor Parameters  --------------------------- //
 float HSens_gain = 31;
-float I_LIMIT = 15.0;
+float I_LIMIT = 30.0;
 float i_offset = 0.58;
 float i_load = 0;
 float i_load_sum = 0;
@@ -52,7 +54,7 @@
 
 // ------------------------- Ramp up parameters  ----------------------------- //
 float N = 20;        // number of steps
-float tramp = 5000;  // ramp time in ms
+float tramp = 10000;  // ramp time in ms
 float tstep = 0;     // step time
 float toff = 1;    // cycle off time
 float ton_sat = 0;   // ON time saturation value
@@ -188,7 +190,7 @@
 
 
 //--------Ramp up Start ----------//
-
+    TIMER.start();
     d_sat = resistance*I_out/V_batt;
 
     if (d_sat > 0.99) {
@@ -231,7 +233,8 @@
         ton = ton*1000;
         toff = toff*1000;
         
-        if((led1 == 1)||(led2 == 1)||(led3 == 1)) //test conditions for break
+        //if((led1 == 1)||(led2 == 1)||(led3 == 1)) //test conditions for break
+        if((led1 == 1)||(led3 == 1)||(TIMER.read()>=RunTime)) //test conditions for break
         {
             break;
         }          
@@ -252,6 +255,7 @@
         }  
     }
     
+    TIMER.reset();
     NVIC_SystemReset(); 
       
 }
\ No newline at end of file