GOPA KUMAR K C
/
trqrod_pwm
PWN gen code
Fork of trqrod_pwm by
main.cpp@0:85b285794bd5, 2015-02-13 (annotated)
- Committer:
- gkumar
- Date:
- Fri Feb 13 15:48:34 2015 +0000
- Revision:
- 0:85b285794bd5
- Child:
- 1:c872ad833d2a
torquerod_pwm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gkumar | 0:85b285794bd5 | 1 | void FUNC_ACS_GENPWM(float M[3]) |
gkumar | 0:85b285794bd5 | 2 | { |
gkumar | 0:85b285794bd5 | 3 | PwmOut PWM1(A0); //Functions used to generate PWM signal |
gkumar | 0:85b285794bd5 | 4 | PwmOut PWM2(A1); |
gkumar | 0:85b285794bd5 | 5 | PwmOut PWM3(A2); //PWM output comes from pins p6 |
gkumar | 0:85b285794bd5 | 6 | Serial pc1(USBTX, USBRX); |
gkumar | 0:85b285794bd5 | 7 | printf("\nEnterd PWMGEN function\n"); |
gkumar | 0:85b285794bd5 | 8 | float DCx = 0; //Duty cycle of Moment in x, y, z directions |
gkumar | 0:85b285794bd5 | 9 | float ix = 0; //Current sent in x, y, z TR's |
gkumar | 0:85b285794bd5 | 10 | float timep = 0.02 ; |
gkumar | 0:85b285794bd5 | 11 | float Mx=M[0]; //Time period is set to 0.02s |
gkumar | 0:85b285794bd5 | 12 | //Moment in x, y, z directions |
gkumar | 0:85b285794bd5 | 13 | |
gkumar | 0:85b285794bd5 | 14 | |
gkumar | 0:85b285794bd5 | 15 | ix = Mx * 0.3 ; //Moment and Current always have the linear relationship |
gkumar | 0:85b285794bd5 | 16 | |
gkumar | 0:85b285794bd5 | 17 | if( ix>0&& ix < 0.006 ) //Current and Duty cycle have the linear relationship between 1% and 100% |
gkumar | 0:85b285794bd5 | 18 | { |
gkumar | 0:85b285794bd5 | 19 | DCx = 6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008; |
gkumar | 0:85b285794bd5 | 20 | PWM1.period(timep); |
gkumar | 0:85b285794bd5 | 21 | PWM1 = DCx/100 ; |
gkumar | 0:85b285794bd5 | 22 | } |
gkumar | 0:85b285794bd5 | 23 | else if( ix >= 0.006&& ix < 0.0116) |
gkumar | 0:85b285794bd5 | 24 | { |
gkumar | 0:85b285794bd5 | 25 | DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648; |
gkumar | 0:85b285794bd5 | 26 | PWM1.period(timep); |
gkumar | 0:85b285794bd5 | 27 | PWM1 = DCx/100 ; |
gkumar | 0:85b285794bd5 | 28 | } |
gkumar | 0:85b285794bd5 | 29 | else if (ix >= 0.0116&& ix < 0.0624) |
gkumar | 0:85b285794bd5 | 30 | { |
gkumar | 0:85b285794bd5 | 31 | |
gkumar | 0:85b285794bd5 | 32 | DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878; |
gkumar | 0:85b285794bd5 | 33 | PWM1.period(timep); |
gkumar | 0:85b285794bd5 | 34 | PWM1 = DCx/100 ; |
gkumar | 0:85b285794bd5 | 35 | } |
gkumar | 0:85b285794bd5 | 36 | else if(ix >= 0.0624&& ix < 0.555) |
gkumar | 0:85b285794bd5 | 37 | { |
gkumar | 0:85b285794bd5 | 38 | printf("\nACS entered if\n"); |
gkumar | 0:85b285794bd5 | 39 | DCx = 331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338; |
gkumar | 0:85b285794bd5 | 40 | PWM1.period(timep); |
gkumar | 0:85b285794bd5 | 41 | PWM1 = DCx/100 ; |
gkumar | 0:85b285794bd5 | 42 | } |
gkumar | 0:85b285794bd5 | 43 | else if(ix==0) |
gkumar | 0:85b285794bd5 | 44 | { |
gkumar | 0:85b285794bd5 | 45 | DCx = 0; |
gkumar | 0:85b285794bd5 | 46 | PWM1.period(timep); |
gkumar | 0:85b285794bd5 | 47 | PWM1 = DCx/100 ; |
gkumar | 0:85b285794bd5 | 48 | } |
gkumar | 0:85b285794bd5 | 49 | else |
gkumar | 0:85b285794bd5 | 50 | { |
gkumar | 0:85b285794bd5 | 51 | // printf("!!!!!!!!!!Error!!!!!!!!!"); |
gkumar | 0:85b285794bd5 | 52 | } |