New PWM code by Yeshwanth

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
gkumar
Date:
Sat Mar 19 07:36:08 2016 +0000
Parent:
0:4e8fb2adea64
Commit message:
New PWM Gen code by Yeshwanth

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4e8fb2adea64 -r c5f613785c7b main.cpp
--- a/main.cpp	Sat Mar 19 07:24:49 2016 +0000
+++ b/main.cpp	Sat Mar 19 07:36:08 2016 +0000
@@ -1,8 +1,25 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include<math.h>
+#include "mbed.h"
+#include "math.h"
+#include "stdlib.h"
 #include "pin_config.h"
-#include "mbed.h"
+
+//...........................................
+#define TIME_PERIOD  0.02
+#define TR_CONSTANT  0.15254
+
+DigitalOut phase_TR_x(PIN27); // PHASE pin for x-torquerod
+DigitalOut phase_TR_y(PIN28); // PHASE pin for y-torquerod
+DigitalOut phase_TR_z(PIN86); // PHASE pin for z-torquerod
+
+PwmOut PWM1(PIN93); //x                         //Functions used to generate PWM signal 
+PwmOut PWM2(PIN94); //y
+PwmOut PWM3(PIN95); //z                         //PWM output comes from pins p6
+
+
+int g_err_flag_TR_x=0;       // setting x-flag to zero
+int g_err_flag_TR_y=0;       // setting y-flag to zero
+int g_err_flag_TR_z=0;       // setting z-flag to zero
+
 void FCTN_ACS_GENPWM_MAIN(float Moment[3])
 {
     printf("\n\rEntered executable PWMGEN function\n"); // entering the PWMGEN executable function
@@ -33,25 +50,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);
+    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 =  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 
-        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 ;
     }
     else if (l_current_x >= 0.0016 && l_current_x < 0.0171)
     {
         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
-        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 ;            
     }
     else if(l_current_x >= 0.0171 && l_current_x < 0.1678)
     {
         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
-        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 ;            
     }
@@ -59,7 +76,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 ;            
     }
@@ -82,25 +99,25 @@
     
     
     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.0016 ) //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 =  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 
-        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 ;
     }
     else if (l_current_y >= 0.0016 && l_current_y < 0.0171)
     {
         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
-        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 ;            
     }
     else if(l_current_y >= 0.0171 && l_current_y < 0.1678)
     {
         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
-        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 ;            
     }        
@@ -108,7 +125,7 @@
     {
         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 ;            
     }
@@ -131,25 +148,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);
+     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 =  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 
-        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 ;
     }
     else if (l_current_z >= 0.0016 && l_current_z < 0.0171)
     {
         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
-        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 ;            
     }
     else if(l_current_z >= 0.0171 && l_current_z < 0.1678)
     {
         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
-        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 ;            
     }
@@ -157,7 +174,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 ;            
     }
@@ -170,4 +187,9 @@
     
     printf("\n\rExited executable PWMGEN function\n\r"); // stating the successful exit of TR function
  
-}
\ No newline at end of file
+}
+
+void main(){
+    float mmt[3]={1,0.5,1.1}; // Unit: Ampere*Meter^2
+    FCTN_ACS_GENPWM_MAIN(mmt);
+    }
\ No newline at end of file