![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
working code of bae with i2c
Fork of all_combined_week6 by
ACS.cpp@6:82153349cc9b, 2014-07-15 (annotated)
- Committer:
- greenroshks
- Date:
- Tue Jul 15 10:04:38 2014 +0000
- Revision:
- 6:82153349cc9b
- Child:
- 7:47e07755d9a4
BAE RTOS final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greenroshks | 6:82153349cc9b | 1 | #include "ACS.h" |
greenroshks | 6:82153349cc9b | 2 | |
greenroshks | 6:82153349cc9b | 3 | |
greenroshks | 6:82153349cc9b | 4 | PwmOut PWM1(p6); //Functions used to generate PWM signal |
greenroshks | 6:82153349cc9b | 5 | //PWM output comes from pins p6 |
greenroshks | 6:82153349cc9b | 6 | Serial pc1(USBTX, USBRX); |
greenroshks | 6:82153349cc9b | 7 | |
greenroshks | 6:82153349cc9b | 8 | |
greenroshks | 6:82153349cc9b | 9 | void FUNC_ACS_GENPWM() |
greenroshks | 6:82153349cc9b | 10 | { |
greenroshks | 6:82153349cc9b | 11 | printf("\nEnterd PWMGEN function\n"); |
greenroshks | 6:82153349cc9b | 12 | double DCx = 0; //Duty cycle of Moment in x, y, z directions |
greenroshks | 6:82153349cc9b | 13 | double ix = 0; //Current sent in x, y, z TR's |
greenroshks | 6:82153349cc9b | 14 | float timep = 0.02 ; |
greenroshks | 6:82153349cc9b | 15 | double Mx=1.5; //Time period is set to 0.2s |
greenroshks | 6:82153349cc9b | 16 | //Moment in x, y, z directions |
greenroshks | 6:82153349cc9b | 17 | |
greenroshks | 6:82153349cc9b | 18 | |
greenroshks | 6:82153349cc9b | 19 | ix = Mx * 0.3 ; //Moment and Current always have the linear relationship |
greenroshks | 6:82153349cc9b | 20 | |
greenroshks | 6:82153349cc9b | 21 | if( ix>0&& ix < 0.006 ) //Current and Duty cycle have the linear relationship between 1% and 100% |
greenroshks | 6:82153349cc9b | 22 | { |
greenroshks | 6:82153349cc9b | 23 | DCx = 6*1000000*pow(ix,4) - 377291*pow(ix,3) + 4689.6*pow(ix,2) + 149.19*ix - 0.0008; |
greenroshks | 6:82153349cc9b | 24 | PWM1.period(timep); |
greenroshks | 6:82153349cc9b | 25 | PWM1 = DCx/100 ; |
greenroshks | 6:82153349cc9b | 26 | } |
greenroshks | 6:82153349cc9b | 27 | else if( ix >= 0.006&& ix < 0.0116) |
greenroshks | 6:82153349cc9b | 28 | { |
greenroshks | 6:82153349cc9b | 29 | DCx = 1*100000000*pow(ix,4) - 5*1000000*pow(ix,3) + 62603*pow(ix,2) - 199.29*ix + 0.7648; |
greenroshks | 6:82153349cc9b | 30 | PWM1.period(timep); |
greenroshks | 6:82153349cc9b | 31 | PWM1 = DCx/100 ; |
greenroshks | 6:82153349cc9b | 32 | } |
greenroshks | 6:82153349cc9b | 33 | else if (ix >= 0.0116&& ix < 0.0624) |
greenroshks | 6:82153349cc9b | 34 | { |
greenroshks | 6:82153349cc9b | 35 | |
greenroshks | 6:82153349cc9b | 36 | DCx = 212444*pow(ix,4) - 33244*pow(ix,3) + 1778.4*pow(ix,2) + 120.91*ix + 0.3878; |
greenroshks | 6:82153349cc9b | 37 | PWM1.period(timep); |
greenroshks | 6:82153349cc9b | 38 | PWM1 = DCx/100 ; |
greenroshks | 6:82153349cc9b | 39 | } |
greenroshks | 6:82153349cc9b | 40 | else if(ix >= 0.0624&& ix < 0.555) |
greenroshks | 6:82153349cc9b | 41 | { |
greenroshks | 6:82153349cc9b | 42 | printf("\nACS entered if\n"); |
greenroshks | 6:82153349cc9b | 43 | DCx = 331.15*pow(ix,4) - 368.09*pow(ix,3) + 140.43*pow(ix,2) + 158.59*ix + 0.0338; |
greenroshks | 6:82153349cc9b | 44 | PWM1.period(timep); |
greenroshks | 6:82153349cc9b | 45 | PWM1 = DCx/100 ; |
greenroshks | 6:82153349cc9b | 46 | } |
greenroshks | 6:82153349cc9b | 47 | else if(ix==0) |
greenroshks | 6:82153349cc9b | 48 | { |
greenroshks | 6:82153349cc9b | 49 | DCx = 0; |
greenroshks | 6:82153349cc9b | 50 | PWM1.period(timep); |
greenroshks | 6:82153349cc9b | 51 | PWM1 = DCx/100 ; |
greenroshks | 6:82153349cc9b | 52 | } |
greenroshks | 6:82153349cc9b | 53 | else |
greenroshks | 6:82153349cc9b | 54 | { |
greenroshks | 6:82153349cc9b | 55 | // pc.printf("!!!!!!!!!!Error!!!!!!!!!"); |
greenroshks | 6:82153349cc9b | 56 | } |
greenroshks | 6:82153349cc9b | 57 | |
greenroshks | 6:82153349cc9b | 58 | |
greenroshks | 6:82153349cc9b | 59 | printf("\nExited PWMGEN function\n"); |
greenroshks | 6:82153349cc9b | 60 | } |
greenroshks | 6:82153349cc9b | 61 |