QITH FLAGS

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of TF_conops_BAE1_3 by Team Fox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ACS.cpp Source File

ACS.cpp

00001 #include "ACS.h"
00002 #include "pin_config.h"
00003 
00004 Serial pc1(USBTX, USBRX);
00005 //.....................................flags...................................................//
00006 extern uint32_t BAE_STATUS;
00007 extern uint32_t BAE_ENABLE;
00008 
00009 //....................................pwmgen...................................................//
00010 DigitalOut phase_TR_x(PIN27); // PHASE pin for x-torquerod
00011 DigitalOut phase_TR_y(PIN28); // PHASE pin for y-torquerod
00012 DigitalOut phase_TR_z(PIN86); // PHASE pin for z-torquerod
00013 
00014 PwmOut PWM1(PIN93);                          //Functions used to generate PWM signal 
00015 PwmOut PWM2(PIN94); 
00016 PwmOut PWM3(PIN95);                          //PWM output comes from pins p6
00017 
00018 int g_err_flag_TR_x=0;       // setting x-flag to zero
00019 int g_err_flag_TR_y=0;       // setting y-flag to zero
00020 int g_err_flag_TR_z=0;       // setting z-flag to zero
00021 
00022 //....................................ATS......................................................//
00023 
00024 DigitalOut g_enb1(PIN90);//switch for sensor 1
00025 DigitalOut g_enb2(PIN70);//switch for sensor 2 
00026 Serial mnm(USBTX,USBRX); //for usb communication
00027 I2C i2c (PIN85,PIN84); //PTC2-sda,PTC1-scl
00028 
00029 Timeout g_to; //Timeout variable to
00030 int g_toflag; 
00031 int ATS_reset_count=0;
00032 char g_cmd[2];
00033 float g_gyro_error[3]= {0,0,0}, g_mag_error[3]= {0,0,0};
00034 
00035 /*------------------------------------------------------------------------------------------------------------------------------------------------------
00036 ------------------------------------------- ATS data acquisition------------------------------------------------------------------------------------------*/
00037 void FCTN_T_OUT()
00038 {
00039     g_toflag=0; //as T_OUT function gets called the while loop gets terminated
00040 }
00041 
00042 void  FCTN_ACS_INIT()
00043 {
00044     BAE_STATUS = (BAE_STATUS & 0xFFFFFF7F) +0x00000080;             //set ACS_INIT_STATUS flag to 1
00045     FCTN_ATS_SWITCH(1);
00046     char store;
00047     g_cmd[0]=RESETREQ;
00048     g_cmd[1]=BIT_RESREQ;
00049     i2c.write(SLAVE_ADDR,g_cmd,2); //When 0x01 is written in reset request register Emulates a hard power down/power up
00050     wait_ms(2000); //waiting for loading configuration file stored in EEPROM
00051     g_cmd[0]=SENTRALSTATUS;
00052     i2c.write(SLAVE_ADDR,g_cmd,1);
00053     i2c.read(SLAVE_ADDR_READ,&store,1);
00054     wait_ms(100);
00055     //to check whether EEPROM is uploaded
00056     switch((int)store) { 
00057         case(3): {
00058             break;
00059         }
00060         case(11): {
00061             break;
00062         }
00063         default: {
00064             g_cmd[0]=RESETREQ;
00065             g_cmd[1]=BIT_RESREQ;
00066             i2c.write(SLAVE_ADDR,g_cmd,2);
00067             wait_ms(2000);
00068         }
00069     }
00070     //pc.printf("Sentral Status is %x\n",(int)store);
00071     g_cmd[0]=HOST_CTRL; //0x01 is written in HOST CONTROL register to enable the sensors
00072     g_cmd[1]=BIT_RUN_ENB;
00073     i2c.write(SLAVE_ADDR,g_cmd,2);
00074     wait_ms(100);
00075     g_cmd[0]=MAGRATE; //Output data rate of 100Hz is used for magnetometer
00076     g_cmd[1]=BIT_MAGODR;
00077     i2c.write(SLAVE_ADDR,g_cmd,2);
00078     wait_ms(100);
00079     g_cmd[0]=GYRORATE; //Output data rate of 150Hz is used for gyroscope
00080     g_cmd[1]=BIT_GYROODR;
00081     i2c.write(SLAVE_ADDR,g_cmd,2);
00082     wait_ms(100);
00083     g_cmd[0]=ALGO_CTRL; //When 0x00 is written to ALGO CONTROL register we get scaled sensor values
00084     g_cmd[1]=0x00;
00085     i2c.write(SLAVE_ADDR,g_cmd,2);
00086     wait_ms(100);
00087     g_cmd[0]=ENB_EVT; //enabling the error,gyro values and magnetometer values
00088     g_cmd[1]=BIT_EVT_ENB;
00089     i2c.write(SLAVE_ADDR,g_cmd,2);
00090     wait_ms(100);
00091     PWM1 = 0;           // clear pwm pins
00092     PWM2 = 0;
00093     PWM3 = 0;
00094     BAE_STATUS &= 0xFFFFFF7F;              //clear ACS_INIT_STATUS flag
00095     printf("\n\r ACS_STATUS flag reads %x",&BAE_STATUS);
00096 }
00097 
00098 void FCTN_ACS_DATA_ACQ(float g_gyro_data[3],float g_mag_data[3])
00099 {
00100     BAE_STATUS =(BAE_STATUS & 0xFFFFFEFF)  0x00000100;     //set ACS_DATA_ACQ_STATUS flag to 1
00101     if(BAE_ENABLE & 0x00000004 == 0x00000004)       // check ACS_ATS_ENABLE = 1?
00102     {
00103         char status;
00104         g_toflag=1; //toFlag is set to 1 so that it enters while loop
00105         g_to.attach(&FCTN_T_OUT,2); //after 2 seconds the while loop gets terminated 
00106         g_cmd[0]=EVT_STATUS;
00107         i2c.write(SLAVE_ADDR,g_cmd,1);
00108         i2c.read(SLAVE_ADDR_READ,&status,1);
00109         wait_ms(100);
00110         //pc.printf("\nEvent Status is %x\n",(int)status);
00111         //if the 6th and 4th bit are 1 then it implies that gyro and magnetometer values are ready to take
00112         if(((int)status&40)==40) 
00113         {
00114             FCTN_GET_DATA(g_gyro_data,g_mag_data);
00115             printf("\n\r data received \n");
00116             for(int i=0; i<3; i++) 
00117             {
00118                 printf("%f\t",g_gyro_data[i]);
00119             }
00120             for(int i=0; i<3; i++) 
00121             {
00122                 printf("%f\t",g_mag_data[i]);
00123             }
00124         }
00125         //checking for the error
00126         else if (((int)status&2)==2) 
00127         {
00128             if(ATS_reset_count!=2) 
00129             {
00130                 FCTN_ACS_INIT(); //when there is any error then Again inilization is done to remove error
00131                 ATS_reset_count++;
00132             }
00133             else 
00134             {
00135                 FCTN_ATS_SWITCH(0);
00136             }
00137         }
00138       //  BAE_STATUS |= 0x00000000;            //set ACS_ATS_STATUS = ACS_ATS_OPERATIONAL 
00139     }
00140     else
00141     {
00142         BAE_STATUS =(BAE_STATUS & 0xFFFFFEFF)+ 0x00000200;             //set ACS_DATA_ACQ_ATS = ACS_ATS_DISABLED // ACS_DATA_ACQ_STATUS = ACS_DATA_ACQ_FAILURE
00143     }
00144        
00145     BAE_STATUS &= 0xFFFFFEFF;     //clear ACS_DATA_ACQ_STATUS flag to 1
00146 }
00147 
00148 void FCTN_GET_DATA(float g_gyro_data[3],float g_mag_data[3])
00149 {
00150     char raw_gyro[6];
00151     char raw_mag[6];
00152     int16_t bit_data;
00153     
00154     float senstivity_gyro =6.5536; //senstivity is obtained from 2^15/5000dps
00155     float senstivity_mag  =32.768; //senstivity is obtained from 2^15/1000microtesla
00156     g_cmd[0]=GYRO_XOUT_H; //0x22 gyro LSB of x 
00157     i2c.write(SLAVE_ADDR,g_cmd,1);
00158     i2c.read(SLAVE_ADDR_READ,raw_gyro,6);
00159     g_cmd[0]=MAG_XOUT_H; //LSB of x
00160     i2c.write(SLAVE_ADDR,g_cmd,1);
00161     i2c.read(SLAVE_ADDR_READ,raw_mag,6);
00162             //pc.printf("\nGyro Values:\n");
00163             for(int i=0; i<3; i++) {
00164                 //concatenating gyro LSB and MSB to get 16 bit signed data values
00165                 bit_data= ((int16_t)raw_gyro[2*i+1]<<8)|(int16_t)raw_gyro[2*i]; 
00166                 g_gyro_data[i]=(float)bit_data;
00167                 g_gyro_data[i]=g_gyro_data[i]/senstivity_gyro;
00168                 g_gyro_data[i]+=g_gyro_error[i];
00169                 //pc.printf("%f\t",gyro_data[i]);
00170             }
00171             for(int i=0; i<3; i++) {
00172                 //concatenating mag LSB and MSB to get 16 bit signed data values
00173                 bit_data= ((int16_t)raw_mag[2*i+1]<<8)|(int16_t)raw_mag[2*i];
00174                 g_mag_data[i]=(float)bit_data;
00175                 g_mag_data[i]=g_mag_data[i]/senstivity_mag;
00176                 g_mag_data[i]+=g_mag_error[i];
00177                 //pc.printf("%f\t",mag_data[i]);
00178             }
00179             
00180 }
00181 
00182 void FCTN_ATS_SWITCH(bool c)
00183 {
00184     if(c==0){
00185         g_enb1 = 1;//enabling it high switches OFF the sensor 1
00186         g_enb2 = 0;//swtiches ON the sensor 2
00187     }
00188     else{
00189         g_enb1 = 0;//enabling it low switches the sensor ON
00190         g_enb2 = 1;//switches OFF the sensor 2     
00191     }
00192 }
00193 
00194 /*------------------------------------------------------------------------------------------------------------------------------------------------------
00195 -------------------------------------------CONTROL ALGORITHM------------------------------------------------------------------------------------------*/
00196   
00197 int ctrl_count = 0;
00198 float bcopy[3];
00199 
00200 void FCTN_ACS_CNTRLALGO(float b[3],float omega[3],float moment[3])
00201 {
00202     float db[3];
00203     float bb[3]={0,0,0};
00204     float d[3]={0,0,0};
00205     float Jm[3][3]={{0.2730,0,0},{0,0.3018,0},{0,0,0.3031}};
00206     float den=0,den2;
00207     int i,j;                   //temporary variables
00208     float Mu[2],z[2],dv[2],v[2],u[2],tauc[3]={0,0,0};           //outputs
00209     float invJm[3][3];
00210     float kmu2=0.07,gamma2=1.9e4,kz2=0.4e-2,kmu=0.003,gamma=5.6e4,kz=0.1e-4;
00211     
00212     //................. calculating db values...........................
00213     if(ctrl_count!=0)
00214     {
00215         for(i=0;i<3;i++)
00216         db[i]= (b[i]-bcopy[i])/10;
00217     }
00218     else
00219     {
00220         for(i=0;i<3;i++)
00221         db[i]= 0;
00222     }
00223     ctrl_count++;
00224     //..................................................................
00225     printf("\n\r Entered cntrl algo\n\r");
00226     for(int i=0; i<3; i++) 
00227         {
00228         printf("%f\t",omega[i]);
00229         }
00230     for(int i=0; i<3; i++) 
00231         {
00232         printf("%f\t",b[i]);
00233         }
00234 
00235     //.........................algo......................................
00236     den=sqrt((b[0]*b[0])+(b[1]*b[1])+(b[2]*b[2]));
00237     den2=(b[0]*db[0])+(b[1]*db[1])+(b[2]*db[2]);
00238     for(i=0;i<3;i++)
00239     {
00240         db[i]=((db[i]*den*den)-(b[i]*(den2)))/(pow(den,3));
00241         //db[i]/=den*den*den;
00242     }
00243     for(i=0;i<3;i++)
00244     {
00245         b[i]/=den;
00246     }
00247     // select kz, kmu, gamma
00248     if(b[0]>0.9||b[0]<-0.9)
00249     {
00250         kz=kz2;
00251         kmu=kmu2;
00252         gamma=gamma2;
00253     }
00254     // calculate Mu, v, dv, z, u
00255     for(i=0;i<2;i++)
00256     {
00257         Mu[i]=b[i+1];
00258         v[i]=-kmu*Mu[i];
00259         dv[i]=-kmu*db[i+1];
00260         z[i]=db[i+1]-v[i];
00261         u[i]=-kz*z[i]+dv[i]-(Mu[i]/gamma);
00262     }
00263     inverse(Jm,invJm);
00264     for(i=0;i<3;i++)
00265     {
00266         for(j=0;j<3;j++)
00267             bb[i]+=omega[j]*(omega[(i+1)%3]*Jm[(i+2)%3][j]-omega[(i+2)%3]*Jm[(i+1)%3][j]);
00268     }
00269     for(i=0;i<3;i++)
00270     {
00271         for(j=0;j<3;j++)
00272             d[i]+=bb[j]*invJm[i][j];
00273     }
00274     bb[1]=u[0]+(d[0]*b[2])-(d[2]*b[0])-(omega[0]*db[2])+(omega[2]*db[0]);
00275     bb[2]=u[1]-(d[0]*b[1])+(d[1]*b[0])+(omega[0]*db[1])-(omega[1]*db[0]);
00276     bb[0]=0;
00277     for(i=0;i<3;i++)
00278     {
00279         d[i]=invJm[1][i];
00280         invJm[1][i]=b[2]*invJm[0][i]-b[0]*invJm[2][i];
00281         invJm[2][i]=-b[1]*invJm[0][i]+b[0]*d[i];
00282         invJm[0][i]=b[i];
00283     }
00284     inverse(invJm,Jm);
00285     printf("\n \r calculating tauc");
00286     for(i=0;i<3;i++)
00287     {
00288         for(j=0;j<3;j++)
00289             tauc[i]+=Jm[i][j]*bb[j];            // calculating torque values
00290             printf(" %f \t",tauc[i]);    
00291     }
00292     //..........................tauc to moment conversion..........................
00293     printf("\n \r calculating moment");
00294     for(i=0;i<3;i++)
00295         bcopy[i]=b[i]*den;
00296     for(i=0;i<3;i++)
00297     {
00298         moment[i]=bcopy[(i+1)%3]*tauc[(i+2)%3]-bcopy[(i+2)%3]*tauc[(i+1)%3];
00299         moment[i]/=den;
00300         printf(" %f \t",moment[i]); 
00301     }
00302     printf("\n\r exited control algo\n");
00303 }
00304 //..........................function to find inverse..................
00305 void inverse(float mat[3][3],float inv[3][3])
00306 {
00307     int i,j;
00308     float det=0;
00309     for(i=0;i<3;i++)
00310     { 
00311         for(j=0;j<3;j++)
00312             inv[j][i]=(mat[(i+1)%3][(j+1)%3]*mat[(i+2)%3][(j+2)%3])-(mat[(i+2)%3][(j+1)%3]*mat[(i+1)%3][(j+2)%3]);
00313     }
00314     det+=(mat[0][0]*inv[0][0])+(mat[0][1]*inv[1][0])+(mat[0][2]*inv[2][0]);
00315     for(i=0;i<3;i++)
00316     { 
00317         for(j=0;j<3;j++)
00318             inv[i][j]/=det;
00319     }
00320 }
00321 
00322 /*------------------------------------------------------------------------------------------------------------------------------------------------------
00323 ---------------------------------------------------PWM GENERATION-----------------------------------------------------------------------------------------*/
00324 
00325 void FCTN_ACS_GENPWM_MAIN(float Moment[3])
00326 {
00327     printf("\n\rEntered executable PWMGEN function\n"); // entering the PWMGEN executable function
00328     
00329     float l_duty_cycle_x=0;    //Duty cycle of Moment in x direction
00330     float l_current_x=0;       //Current sent in x TR's
00331     float l_duty_cycle_y=0;    //Duty cycle of Moment in y direction
00332     float l_current_y=0;       //Current sent in y TR's
00333     float l_duty_cycle_z=0;    //Duty cycle of Moment in z direction
00334     float l_current_z=0;       //Current sent in z TR's
00335  
00336     
00337     for(int i = 0 ; i<3;i++)
00338     {
00339         printf(" %f \t ",Moment[i]);  // taking the moment values from control algorithm as inputs
00340     }
00341     
00342     //-----------------------------  x-direction TR  --------------------------------------------//
00343     
00344     
00345     float l_moment_x = Moment[0];         //Moment in x direction
00346     
00347     phase_TR_x = 1;  // setting the default current direction
00348     if (l_moment_x <0)
00349     {
00350         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 
00351         l_moment_x = abs(l_moment_x);
00352     }
00353     
00354     l_current_x = l_moment_x * TR_CONSTANT ;        //Moment and Current always have the linear relationship
00355     
00356     if( l_current_x>0 && l_current_x < 0.006 ) //Current and Duty cycle have the linear relationship between 1% and 100%
00357     {
00358         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 
00359         PWM1.period(TIME_PERIOD);
00360         PWM1 = l_duty_cycle_x/100 ;
00361     }
00362     else if( l_current_x >= 0.006 && l_current_x < 0.0116)
00363     { 
00364         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
00365         PWM1.period(TIME_PERIOD);
00366         PWM1 = l_duty_cycle_x/100 ;             
00367     }
00368     else if (l_current_x >= 0.0116 && l_current_x < 0.0624)
00369     {
00370         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
00371         PWM1.period(TIME_PERIOD);
00372         PWM1 = l_duty_cycle_x/100 ;            
00373     }
00374     else if(l_current_x >= 0.0624 && l_current_x < 0.555)
00375     {
00376         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
00377         PWM1.period(TIME_PERIOD);
00378         PWM1 = l_duty_cycle_x/100 ;            
00379     }
00380     else if(l_current_x==0)
00381     {
00382         printf("\n \r l_current_x====0");
00383         l_duty_cycle_x = 0;      // default value of duty cycle
00384         PWM1.period(TIME_PERIOD);
00385         PWM1 = l_duty_cycle_x/100 ;            
00386     }
00387     else                                           //not necessary
00388     {
00389         g_err_flag_TR_x = 1;
00390     } 
00391          
00392     //------------------------------------- y-direction TR--------------------------------------//
00393     
00394      
00395     float l_moment_y = Moment[1];         //Moment in y direction
00396     
00397     phase_TR_y = 1;  // setting the default current direction
00398     if (l_moment_y <0)
00399     {
00400         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  
00401         l_moment_y = abs(l_moment_y);
00402     }
00403     
00404     
00405     l_current_y = l_moment_y * TR_CONSTANT ;        //Moment and Current always have the linear relationship
00406     
00407     if( l_current_y>0 && l_current_y < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100%
00408     {
00409         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
00410         PWM2.period(TIME_PERIOD);
00411         PWM2 = l_duty_cycle_y/100 ;
00412     }
00413     else if( l_current_y >= 0.006 && l_current_y < 0.0116)
00414     { 
00415         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
00416         PWM2.period(TIME_PERIOD);
00417         PWM2 = l_duty_cycle_y/100 ;             
00418     }
00419     else if (l_current_y >= 0.0116&& l_current_y < 0.0624)
00420     {
00421         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
00422         PWM2.period(TIME_PERIOD);
00423         PWM2 = l_duty_cycle_y/100 ;            
00424     }
00425     else if(l_current_y >= 0.0624 && l_current_y < 0.555)
00426     {
00427         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
00428         PWM2.period(TIME_PERIOD);
00429         PWM2 = l_duty_cycle_y/100 ;            
00430     }
00431     else if(l_current_y==0)
00432     {
00433         printf("\n \r l_current_y====0");
00434         l_duty_cycle_y = 0; // default value of duty cycle
00435         PWM2.period(TIME_PERIOD);
00436         PWM2 = l_duty_cycle_y/100 ;            
00437     }
00438     else                               // not necessary
00439     {
00440       g_err_flag_TR_y = 1;
00441     } 
00442              
00443     //----------------------------------------------- z-direction TR -------------------------//  
00444     
00445       
00446     float l_moment_z = Moment[2];         //Moment in z direction
00447     
00448     phase_TR_z = 1;   // setting the default current direction
00449     if (l_moment_z <0)
00450     {
00451         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 
00452         l_moment_z = abs(l_moment_z);
00453     }
00454     
00455     
00456     l_current_z = l_moment_z * TR_CONSTANT ;        //Moment and Current always have the linear relationship
00457     
00458     if( l_current_z>0 && l_current_z < 0.006 )//Current and Duty cycle have the linear relationship between 1% and 100%
00459     {
00460         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
00461         PWM3.period(TIME_PERIOD);
00462         PWM3 = l_duty_cycle_z/100 ;
00463     }
00464     else if( l_current_z >= 0.006 && l_current_z < 0.0116)
00465     { 
00466         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
00467         PWM3.period(TIME_PERIOD);
00468         PWM3 = l_duty_cycle_z/100 ;             
00469     }
00470     else if (l_current_z >= 0.0116 && l_current_z < 0.0624)
00471     {
00472         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
00473         PWM3.period(TIME_PERIOD);
00474         PWM3 = l_duty_cycle_z/100 ;            
00475     }
00476     else if(l_current_z >= 0.0624 && l_current_z < 0.555)
00477     {
00478         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
00479         PWM3.period(TIME_PERIOD);
00480         PWM3 = l_duty_cycle_z/100 ;            
00481     }
00482     else if(l_current_z==0)
00483     {
00484         printf("\n \r l_current_z====0");
00485         l_duty_cycle_z = 0; // default value of duty cycle
00486         PWM3.period(TIME_PERIOD);
00487         PWM3 = l_duty_cycle_z/100 ;            
00488     }
00489     else                               // not necessary
00490     {
00491         g_err_flag_TR_z = 1;
00492     }   
00493     
00494     //-----------------------------------------exiting the function-----------------------------------//
00495     
00496     printf("\n\rExited executable PWMGEN function\n\r"); // stating the successful exit of TR function
00497  
00498 }
00499 
00500 
00501 
00502