PWM and ALGO updated.. PWM getting generated

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of TFR_BAE_vr1_1working_finally_PWM_CTRLALGO_update by Team Fox

Revision:
10:54598e22a857
Parent:
6:036d08b62785
Child:
11:0f71a96987bd
--- a/ACS.cpp	Sun Mar 06 12:43:32 2016 +0000
+++ b/ACS.cpp	Wed Mar 30 13:17:52 2016 +0000
@@ -342,32 +342,25 @@
     }
     
     l_current_x = l_moment_x * TR_CONSTANT ;        //Moment and Current always have the linear relationship
-    pc_acs.printf("current in trx is %f \r \n",l_current_x);
-    if( l_current_x>0 && l_current_x < 0.006 ) //Current and Duty cycle have the linear relationship between 1% and 100%
+    printf("current in trx is %f \r \n",l_current_x);
+    if( l_current_x>0 && l_current_x < 0.0016 ) //Current and Duty cycle have the linear relationship between 1% and 100%
     {
-        l_duty_cycle_x =  6*1000000*pow(l_current_x,4) - 377291*pow(l_current_x,3) + 4689.6*pow(l_current_x,2) + 149.19*l_current_x - 0.0008; // calculating upto 0.1% dutycycle by polynomial interpolation 
-        pc_acs.printf("DC for trx is %f \r \n",l_duty_cycle_x);
+        l_duty_cycle_x =  3*10000000*pow(l_current_x,3)- 90216*pow(l_current_x,2) + 697.78*l_current_x - 0.0048; // calculating upto 0.1% dutycycle by polynomial interpolation 
+        printf("DC for trx is %f \r \n",l_duty_cycle_x);
         PWM1.period(TIME_PERIOD);
         PWM1 = l_duty_cycle_x/100 ;
     }
-    else if( l_current_x >= 0.006 && l_current_x < 0.0116)
-    { 
-        l_duty_cycle_x = 1*100000000*pow(l_current_x,4) - 5*1000000*pow(l_current_x,3) + 62603*pow(l_current_x,2) - 199.29*l_current_x + 0.7648;// calculating upto 1% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trx is %f \r \n",l_duty_cycle_x);
-        PWM1.period(TIME_PERIOD);
-        PWM1 = l_duty_cycle_x/100 ;             
-    }
-    else if (l_current_x >= 0.0116 && l_current_x < 0.0624)
+    else if (l_current_x >= 0.0016 && l_current_x < 0.0171)
     {
-        l_duty_cycle_x = 212444*pow(l_current_x,4) - 33244*pow(l_current_x,3) + 1778.4*pow(l_current_x,2) + 120.91*l_current_x + 0.3878; // calculating upto 10% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trx is %f \r \n",l_duty_cycle_x);
+        l_duty_cycle_x = - 76880*pow(l_current_x,3) + 1280.8*pow(l_current_x,2) + 583.78*l_current_x + 0.0281; // calculating upto 10% dutycycle by polynomial interpolation
+        printf("DC for trx is %f \r \n",l_duty_cycle_x);
         PWM1.period(TIME_PERIOD);
         PWM1 = l_duty_cycle_x/100 ;            
     }
-    else if(l_current_x >= 0.0624 && l_current_x < 0.555)
+    else if(l_current_x >= 0.0171 && l_current_x < 0.1678)
     {
-        l_duty_cycle_x =  331.15*pow(l_current_x,4) - 368.09*pow(l_current_x,3) + 140.43*pow(l_current_x,2) + 158.59*l_current_x + 0.0338; // calculating upto 100% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trx is %f \r \n",l_duty_cycle_x);
+        l_duty_cycle_x =  275.92*pow(l_current_x,2) + 546.13*l_current_x + 0.5316; // calculating upto 100% dutycycle by polynomial interpolation
+        printf("DC for trx is %f \r \n",l_duty_cycle_x);
         PWM1.period(TIME_PERIOD);
         PWM1 = l_duty_cycle_x/100 ;            
     }
@@ -375,7 +368,7 @@
     {
         printf("\n \r l_current_x====0");
         l_duty_cycle_x = 0;      // default value of duty cycle
-        pc_acs.printf("DC for trx is %f \r \n",l_duty_cycle_x);
+        printf("DC for trx is %f \r \n",l_duty_cycle_x);
         PWM1.period(TIME_PERIOD);
         PWM1 = l_duty_cycle_x/100 ;            
     }
@@ -398,40 +391,33 @@
     
     
     l_current_y = l_moment_y * TR_CONSTANT ;        //Moment and Current always have the linear relationship
-     pc_acs.printf("current in try is %f \r \n",l_current_y);
-    if( l_current_y>0 && l_current_y < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100%
+    printf("current in try is %f \r \n",l_current_y);
+    if( l_current_y>0 && l_current_y < 0.0016 ) //Current and Duty cycle have the linear relationship between 1% and 100%
     {
-        l_duty_cycle_y =  6*1000000*pow(l_current_y,4) - 377291*pow(l_current_y,3) + 4689.6*pow(l_current_y,2) + 149.19*l_current_y - 0.0008; // calculating upto 0.1% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for try is %f \r \n",l_duty_cycle_y);
+        l_duty_cycle_y =  3*10000000*pow(l_current_y,3)- 90216*pow(l_current_y,2) + 697.78*l_current_y - 0.0048; // calculating upto 0.1% dutycycle by polynomial interpolation 
+        printf("DC for try is %f \r \n",l_duty_cycle_y);
         PWM2.period(TIME_PERIOD);
         PWM2 = l_duty_cycle_y/100 ;
     }
-    else if( l_current_y >= 0.006 && l_current_y < 0.0116)
-    { 
-        l_duty_cycle_y = 1*100000000*pow(l_current_y,4) - 5*1000000*pow(l_current_y,3) + 62603*pow(l_current_y,2) - 199.29*l_current_y + 0.7648;// calculating upto 1% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for try is %f \r \n",l_duty_cycle_y);
-        PWM2.period(TIME_PERIOD);
-        PWM2 = l_duty_cycle_y/100 ;             
-    }
-    else if (l_current_y >= 0.0116&& l_current_y < 0.0624)
+    else if (l_current_y >= 0.0016 && l_current_y < 0.0171)
     {
-        l_duty_cycle_y = 212444*pow(l_current_y,4) - 33244*pow(l_current_y,3) + 1778.4*pow(l_current_y,2) + 120.91*l_current_y + 0.3878;// calculating upto 10% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for try is %f \r \n",l_duty_cycle_y);
+        l_duty_cycle_y = - 76880*pow(l_current_y,3) + 1280.8*pow(l_current_y,2) + 583.78*l_current_y + 0.0281; // calculating upto 10% dutycycle by polynomial interpolation
+        printf("DC for try is %f \r \n",l_duty_cycle_y);
         PWM2.period(TIME_PERIOD);
         PWM2 = l_duty_cycle_y/100 ;            
     }
-    else if(l_current_y >= 0.0624 && l_current_y < 0.555)
+    else if(l_current_y >= 0.0171 && l_current_y < 0.1678)
     {
-        l_duty_cycle_y =  331.15*pow(l_current_y,4) - 368.09*pow(l_current_y,3) + 140.43*pow(l_current_y,2) + 158.59*l_current_y + 0.0338;// calculating upto 100% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for try is %f \r \n",l_duty_cycle_y);
+        l_duty_cycle_y =  275.92*pow(l_current_y,2) + 546.13*l_current_y + 0.5316; // calculating upto 100% dutycycle by polynomial interpolation
+        printf("DC for try is %f \r \n",l_duty_cycle_y);
         PWM2.period(TIME_PERIOD);
         PWM2 = l_duty_cycle_y/100 ;            
-    }
+    }        
     else if(l_current_y==0)
     {
         printf("\n \r l_current_y====0");
         l_duty_cycle_y = 0; // default value of duty cycle
-        pc_acs.printf("DC for try is %f \r \n",l_duty_cycle_y);
+        printf("DC for try is %f \r \n",l_duty_cycle_y);
         PWM2.period(TIME_PERIOD);
         PWM2 = l_duty_cycle_y/100 ;            
     }
@@ -454,32 +440,25 @@
     
     
     l_current_z = l_moment_z * TR_CONSTANT ;        //Moment and Current always have the linear relationship
-     pc_acs.printf("current in trz is %f \r \n",l_current_z);
-    if( l_current_z>0 && l_current_z < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100%
+     printf("current in trz is %f \r \n",l_current_z);
+        if( l_current_z>0 && l_current_z < 0.0016 ) //Current and Duty cycle have the linear relationship between 1% and 100%
     {
-        l_duty_cycle_z =  6*1000000*pow(l_current_z,4) - 377291*pow(l_current_z,3) + 4689.6*pow(l_current_z,2) + 149.19*l_current_z - 0.0008;// calculating upto 0.1% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trz is %f \r \n",l_duty_cycle_z);
+        l_duty_cycle_z =  3*10000000*pow(l_current_z,3)- 90216*pow(l_current_z,2) + 697.78*l_current_z - 0.0048; // calculating upto 0.1% dutycycle by polynomial interpolation 
+        printf("DC for trz is %f \r \n",l_duty_cycle_z);
         PWM3.period(TIME_PERIOD);
         PWM3 = l_duty_cycle_z/100 ;
     }
-    else if( l_current_z >= 0.006 && l_current_z < 0.0116)
-    { 
-        l_duty_cycle_z = 1*100000000*pow(l_current_z,4) - 5*1000000*pow(l_current_z,3) + 62603*pow(l_current_z,2) - 199.29*l_current_z + 0.7648;// calculating upto 1% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trz is %f \r \n",l_duty_cycle_z);
-        PWM3.period(TIME_PERIOD);
-        PWM3 = l_duty_cycle_z/100 ;             
-    }
-    else if (l_current_z >= 0.0116 && l_current_z < 0.0624)
+    else if (l_current_z >= 0.0016 && l_current_z < 0.0171)
     {
-        l_duty_cycle_z = 212444*pow(l_current_z,4) - 33244*pow(l_current_z,3) + 1778.4*pow(l_current_z,2) + 120.91*l_current_z + 0.3878;// calculating upto 10% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trz is %f \r \n",l_duty_cycle_z);
+        l_duty_cycle_z = - 76880*pow(l_current_z,3) + 1280.8*pow(l_current_z,2) + 583.78*l_current_z + 0.0281; // calculating upto 10% dutycycle by polynomial interpolation
+        printf("DC for trz is %f \r \n",l_duty_cycle_z);
         PWM3.period(TIME_PERIOD);
         PWM3 = l_duty_cycle_z/100 ;            
     }
-    else if(l_current_z >= 0.0624 && l_current_z < 0.555)
+    else if(l_current_z >= 0.0171 && l_current_z < 0.1678)
     {
-        l_duty_cycle_z =  331.15*pow(l_current_z,4) - 368.09*pow(l_current_z,3) + 140.43*pow(l_current_z,2) + 158.59*l_current_z + 0.0338;// calculating upto 100% dutycycle by polynomial interpolation
-        pc_acs.printf("DC for trz is %f \r \n",l_duty_cycle_z);
+        l_duty_cycle_z =  275.92*pow(l_current_z,2) + 546.13*l_current_z + 0.5316; // calculating upto 100% dutycycle by polynomial interpolation
+        printf("DC for trz is %f \r \n",l_duty_cycle_z);
         PWM3.period(TIME_PERIOD);
         PWM3 = l_duty_cycle_z/100 ;            
     }
@@ -487,7 +466,7 @@
     {
         printf("\n \r l_current_z====0");
         l_duty_cycle_z = 0; // default value of duty cycle
-        pc_acs.printf("DC for trz is %f \r \n",l_duty_cycle_z);
+        printf("DC for trz is %f \r \n",l_duty_cycle_z);
         PWM3.period(TIME_PERIOD);
         PWM3 = l_duty_cycle_z/100 ;            
     }