PWN gen code

Dependencies:   mbed

Fork of trqrod_pwm by GOPA KUMAR K C

Revision:
0:85b285794bd5
Child:
1:c872ad833d2a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 13 15:48:34 2015 +0000
@@ -0,0 +1,52 @@
+void FUNC_ACS_GENPWM(float M[3])
+ {
+     PwmOut PWM1(A0);        //Functions used to generate PWM signal 
+       PwmOut PWM2(A1); 
+        PwmOut PWM3(A2);                   //PWM output comes from pins p6
+Serial pc1(USBTX, USBRX); 
+     printf("\nEnterd PWMGEN function\n");
+     float DCx = 0;         //Duty cycle of Moment in x, y, z directions
+     float ix = 0;          //Current sent in x, y, z TR's
+     float timep = 0.02 ;  
+     float Mx=M[0];            //Time period is set to 0.02s  
+                             //Moment in x, y, z directions
+      
+     
+        ix = Mx * 0.3 ;      //Moment and Current always have the linear relationship
+     
+        if( ix>0&& ix < 0.006 )                     //Current and Duty cycle have the linear relationship between 1% and 100%
+         {
+             DCx =  6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008;
+             PWM1.period(timep);
+             PWM1 = DCx/100 ;
+         }
+        else if( ix >= 0.006&& ix < 0.0116)
+         { 
+            DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648;
+            PWM1.period(timep);
+            PWM1 = DCx/100 ;             
+         }
+        else if (ix >= 0.0116&& ix < 0.0624)
+         {
+              
+            DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878;
+            PWM1.period(timep);
+            PWM1 = DCx/100 ;            
+         }
+        else if(ix >= 0.0624&& ix < 0.555)
+         {
+            printf("\nACS entered if\n");
+            DCx =  331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338;
+            PWM1.period(timep);
+            PWM1 = DCx/100 ;            
+         }
+         else if(ix==0)
+         {
+             DCx = 0;
+            PWM1.period(timep);
+            PWM1 = DCx/100 ;            
+         }
+         else
+         {
+            // printf("!!!!!!!!!!Error!!!!!!!!!");
+         }