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:
11:0f71a96987bd
Parent:
10:54598e22a857
Child:
12:f82fbe93fab3
--- a/ACS.cpp	Wed Mar 30 13:17:52 2016 +0000
+++ b/ACS.cpp	Thu Mar 31 11:44:20 2016 +0000
@@ -482,4 +482,195 @@
 }
 
 
+/*void FCTN_ACS_GENPWM_MAIN(float Moment[3])
+{
+    printf("\n\rEntered executable PWMGEN function\n"); // entering the PWMGEN executable function
+    
+    float l_duty_cycle_x=0;    //Duty cycle of Moment in x direction
+    float l_current_x=0;       //Current sent in x TR's
+    float l_duty_cycle_y=0;    //Duty cycle of Moment in y direction
+    float l_current_y=0;       //Current sent in y TR's
+    float l_duty_cycle_z=0;    //Duty cycle of Moment in z direction
+    float l_current_z=0;       //Current sent in z TR's
+ 
+    
+    for(int i = 0 ; i<3;i++)
+    {
+       printf("pwm %f \t ",Moment[i]);  // taking the moment values from control algorithm as inputs
+    }
+    
+    //-----------------------------  x-direction TR  --------------------------------------------//
+    
+    
+    float l_moment_x = Moment[0];         //Moment in x direction
+    
+    phase_TR_x = 1;  // setting the default current direction
+    if (l_moment_x <0)
+    {
+        phase_TR_x = 0;    // if the moment value is negative, we send the abs value of corresponding current in opposite direction by setting the phase pin high 
+        l_moment_x = abs(l_moment_x);
+    }
+    
+    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%
+    {
+        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);
+        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)
+    {
+        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);
+        PWM1.period(TIME_PERIOD);
+        PWM1 = l_duty_cycle_x/100 ;            
+    }
+    else if(l_current_x >= 0.0624 && l_current_x < 0.555)
+    {
+        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);
+        PWM1.period(TIME_PERIOD);
+        PWM1 = l_duty_cycle_x/100 ;            
+    }
+    else if(l_current_x==0)
+    {
+        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);
+        PWM1.period(TIME_PERIOD);
+        PWM1 = l_duty_cycle_x/100 ;            
+    }
+    else                                           //not necessary
+    {
+        g_err_flag_TR_x = 1;
+    } 
+         
+    //------------------------------------- y-direction TR--------------------------------------//
+    
+     
+    float l_moment_y = Moment[1];         //Moment in y direction
+    
+    phase_TR_y = 1;  // setting the default current direction
+    if (l_moment_y <0)
+    {
+        phase_TR_y = 0;   //if the moment value is negative, we send the abs value of corresponding current in opposite direction by setting the phase pin high  
+        l_moment_y = abs(l_moment_y);
+    }
+    
+    
+    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%
+    {
+        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);
+        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)
+    {
+        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);
+        PWM2.period(TIME_PERIOD);
+        PWM2 = l_duty_cycle_y/100 ;            
+    }
+    else if(l_current_y >= 0.0624 && l_current_y < 0.555)
+    {
+        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);
+        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);
+        PWM2.period(TIME_PERIOD);
+        PWM2 = l_duty_cycle_y/100 ;            
+    }
+    else                               // not necessary
+    {
+      g_err_flag_TR_y = 1;
+    } 
+             
+    //----------------------------------------------- z-direction TR -------------------------//  
+    
+      
+    float l_moment_z = Moment[2];         //Moment in z direction
+    
+    phase_TR_z = 1;   // setting the default current direction
+    if (l_moment_z <0)
+    {
+        phase_TR_z = 0; //if the moment value is negative, we send the abs value of corresponding current in opposite direction by setting the phase pin high 
+        l_moment_z = abs(l_moment_z);
+    }
+    
+    
+    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%
+    {
+        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);
+        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)
+    {
+        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);
+        PWM3.period(TIME_PERIOD);
+        PWM3 = l_duty_cycle_z/100 ;            
+    }
+    else if(l_current_z >= 0.0624 && l_current_z < 0.555)
+    {
+        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);
+        PWM3.period(TIME_PERIOD);
+        PWM3 = l_duty_cycle_z/100 ;            
+    }
+    else if(l_current_z==0)
+    {
+        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);
+        PWM3.period(TIME_PERIOD);
+        PWM3 = l_duty_cycle_z/100 ;            
+    }
+    else                               // not necessary
+    {
+        g_err_flag_TR_z = 1;
+    }   
+    
+    //-----------------------------------------exiting the function-----------------------------------//
+    
+    printf("\n\rExited executable PWMGEN function\n\r"); // stating the successful exit of TR function
+ 
+}*/
+
+
     
\ No newline at end of file