Betterfrost / Mbed 2 deprecated timer_based_1kHz_ramp

Dependencies:   mbed

Fork of BoxBrovoEcho_OCt3 by Betterfrost

Revision:
4:2c5dbea00157
Parent:
3:d56766563719
Child:
5:0d28bca5dd26
--- a/main.cpp	Tue Sep 11 17:18:10 2018 +0000
+++ b/main.cpp	Wed Sep 12 16:37:35 2018 +0000
@@ -30,11 +30,11 @@
 float V_batt = 160.0;
 float I_out = 10.0;
 float V_out = 0.0;
-float freq = 50;     //switching frequency in Hz
+float freq = 30;     //switching frequency in Hz
 
 // -------------------- Current Sensor Parameters  --------------------------- //
 float HSens_gain = 31;
-float I_LIMIT = 9.0;
+float I_LIMIT = 15.0;
 float i_offset = 0.58;
 float i_load = 0;
 float i_load_sum = 0;
@@ -72,9 +72,8 @@
 {
     task_1_pin = !task_1_pin;    
     i_load = HSens_gain *3.3*(v_in/3)*( (1.0-current.read())- (1-(v_in*0.5/3)));
-
-    
-    //if((i_load > I_LIMIT)||(abs(i_load_avg-i_loadpre)>1)&&(i_loadpre != 0)) //Overcurrrent + resistance checking + first real value of i_loadpre
+   
+   
     if(i_load_avg > I_LIMIT) //Overcurrrent
     {
         c_i++;
@@ -97,10 +96,10 @@
     
     avg_c++;
     i_load_sum = i_load_sum + i_load;   //integration
-    if(avg_c == 200)
+    if(avg_c == (int)(1/freq/0.0001))
     {
         avg_c = 0;
-        i_load_avg = (i_load_sum/200);
+        i_load_avg = (i_load_sum/(1/freq/0.0001));
         i_load_sum = 0;
     }