i2c working with old hk

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_1_1 by green rosh

Committer:
greenroshks
Date:
Wed Sep 10 06:41:21 2014 +0000
Revision:
0:8b0d43fe6c05
Child:
13:1b37d98840d3
BAE FRDM Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
greenroshks 0:8b0d43fe6c05 1 #include "ACS.h"
greenroshks 0:8b0d43fe6c05 2
greenroshks 0:8b0d43fe6c05 3
greenroshks 0:8b0d43fe6c05 4 PwmOut PWM1(PTD4); //Functions used to generate PWM signal
greenroshks 0:8b0d43fe6c05 5 //PWM output comes from pins p6
greenroshks 0:8b0d43fe6c05 6 Serial pc1(USBTX, USBRX);
greenroshks 0:8b0d43fe6c05 7
greenroshks 0:8b0d43fe6c05 8
greenroshks 0:8b0d43fe6c05 9 void FUNC_ACS_GENPWM()
greenroshks 0:8b0d43fe6c05 10 {
greenroshks 0:8b0d43fe6c05 11 printf("\nEnterd PWMGEN function\n");
greenroshks 0:8b0d43fe6c05 12 double DCx = 0; //Duty cycle of Moment in x, y, z directions
greenroshks 0:8b0d43fe6c05 13 double ix = 0; //Current sent in x, y, z TR's
greenroshks 0:8b0d43fe6c05 14 float timep = 0.02 ;
greenroshks 0:8b0d43fe6c05 15 double Mx=1.5; //Time period is set to 0.2s
greenroshks 0:8b0d43fe6c05 16 //Moment in x, y, z directions
greenroshks 0:8b0d43fe6c05 17
greenroshks 0:8b0d43fe6c05 18
greenroshks 0:8b0d43fe6c05 19 ix = Mx * 0.3 ; //Moment and Current always have the linear relationship
greenroshks 0:8b0d43fe6c05 20
greenroshks 0:8b0d43fe6c05 21 if( ix>0&& ix < 0.006 ) //Current and Duty cycle have the linear relationship between 1% and 100%
greenroshks 0:8b0d43fe6c05 22 {
greenroshks 0:8b0d43fe6c05 23 DCx = 6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008;
greenroshks 0:8b0d43fe6c05 24 PWM1.period(timep);
greenroshks 0:8b0d43fe6c05 25 PWM1 = DCx/100 ;
greenroshks 0:8b0d43fe6c05 26 }
greenroshks 0:8b0d43fe6c05 27 else if( ix >= 0.006&& ix < 0.0116)
greenroshks 0:8b0d43fe6c05 28 {
greenroshks 0:8b0d43fe6c05 29 DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648;
greenroshks 0:8b0d43fe6c05 30 PWM1.period(timep);
greenroshks 0:8b0d43fe6c05 31 PWM1 = DCx/100 ;
greenroshks 0:8b0d43fe6c05 32 }
greenroshks 0:8b0d43fe6c05 33 else if (ix >= 0.0116&& ix < 0.0624)
greenroshks 0:8b0d43fe6c05 34 {
greenroshks 0:8b0d43fe6c05 35
greenroshks 0:8b0d43fe6c05 36 DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878;
greenroshks 0:8b0d43fe6c05 37 PWM1.period(timep);
greenroshks 0:8b0d43fe6c05 38 PWM1 = DCx/100 ;
greenroshks 0:8b0d43fe6c05 39 }
greenroshks 0:8b0d43fe6c05 40 else if(ix >= 0.0624&& ix < 0.555)
greenroshks 0:8b0d43fe6c05 41 {
greenroshks 0:8b0d43fe6c05 42 printf("\nACS entered if\n");
greenroshks 0:8b0d43fe6c05 43 DCx = 331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338;
greenroshks 0:8b0d43fe6c05 44 PWM1.period(timep);
greenroshks 0:8b0d43fe6c05 45 PWM1 = DCx/100 ;
greenroshks 0:8b0d43fe6c05 46 }
greenroshks 0:8b0d43fe6c05 47 else if(ix==0)
greenroshks 0:8b0d43fe6c05 48 {
greenroshks 0:8b0d43fe6c05 49 DCx = 0;
greenroshks 0:8b0d43fe6c05 50 PWM1.period(timep);
greenroshks 0:8b0d43fe6c05 51 PWM1 = DCx/100 ;
greenroshks 0:8b0d43fe6c05 52 }
greenroshks 0:8b0d43fe6c05 53 else
greenroshks 0:8b0d43fe6c05 54 {
greenroshks 0:8b0d43fe6c05 55 // printf("!!!!!!!!!!Error!!!!!!!!!");
greenroshks 0:8b0d43fe6c05 56 }
greenroshks 0:8b0d43fe6c05 57
greenroshks 0:8b0d43fe6c05 58
greenroshks 0:8b0d43fe6c05 59 printf("\nExited PWMGEN function\n");
greenroshks 0:8b0d43fe6c05 60 }
greenroshks 0:8b0d43fe6c05 61