Betterfrost / Mbed 2 deprecated timer_based_1kHz_ramp

Dependencies:   mbed

Fork of BoxBrovoEcho_OCt3 by Betterfrost

Revision:
6:c905afa84d8a
Parent:
5:0d28bca5dd26
Child:
7:11433074d022
--- a/main.cpp	Fri Sep 21 17:29:36 2018 +0000
+++ b/main.cpp	Wed Oct 03 13:51:07 2018 +0000
@@ -26,17 +26,17 @@
 AnalogIn voltage(p16);
 
 // ------------------------- Main Parameters  ------------------------------- //
-float resistance = 9.6;
-float V_batt = 400.0;
-float I_out = 20.0;
+float resistance = 30.0;
+float V_batt = 300.0;
+float I_out = 5.0;
 float V_out = 0.0;
 float freq = 30;     //switching frequency in Hz
 Timer TIMER;
-float RunTime = 20;  // in seconds
+float RunTime = 60;  // in seconds
 
 // -------------------- Current Sensor Parameters  --------------------------- //
 float HSens_gain = 31;
-float I_LIMIT = 30.0;
+float I_LIMIT = 8.0;
 float i_offset = 0.58;
 float i_load = 0;
 float i_load_sum = 0;
@@ -47,6 +47,7 @@
 int NUM_SAMPLES = 5;
 int count = 0;
 int c_i = 0;
+int c_i2 = 0;
 int a = 0;
 int avg_c = 0;
 float v_in = 0;
@@ -87,9 +88,18 @@
         }
     }
     
-    if((abs(i_load_avg-i_loadpre) > 1)&&(i_loadpre != 0)) // resistance checking
+    if((abs(i_load_avg-i_loadpre) > 4)&&(i_loadpre != 0)) // resistance checking
     {
-        led2 = 1;
+        c_i2++;
+        if(c_i2 == 5) 
+        {
+            
+            led2 = 1;            
+            c_i2 = 0;
+        }
+        
+        
+        
     }
     
     
@@ -233,8 +243,7 @@
         ton = ton*1000;
         toff = toff*1000;
         
-        //if((led1 == 1)||(led2 == 1)||(led3 == 1)) //test conditions for break
-        if((led1 == 1)||(led3 == 1)||(TIMER.read()>=RunTime)) //test conditions for break
+        if((led1 == 1)||(led2 == 1)||(led3 == 1)||(TIMER.read()>=RunTime)) //test conditions for break
         {
             break;
         }