![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The one with the new HK
Fork of BAE_vr2_1_1 by
Diff: ACS.cpp
- Revision:
- 0:8b0d43fe6c05
- Child:
- 13:1b37d98840d3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ACS.cpp Wed Sep 10 06:41:21 2014 +0000 @@ -0,0 +1,61 @@ +#include "ACS.h" + + +PwmOut PWM1(PTD4); //Functions used to generate PWM signal + //PWM output comes from pins p6 +Serial pc1(USBTX, USBRX); + + +void FUNC_ACS_GENPWM() + { + printf("\nEnterd PWMGEN function\n"); + double DCx = 0; //Duty cycle of Moment in x, y, z directions + double ix = 0; //Current sent in x, y, z TR's + float timep = 0.02 ; + double Mx=1.5; //Time period is set to 0.2s + //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!!!!!!!!!"); + } + + +printf("\nExited PWMGEN function\n"); +} + \ No newline at end of file