First version of program for measuring current of three phase BLDC motor.
Dependencies: AutomationElements CurrentRegulation_ mbed
Revision 1:feb19abb96b5, committed 2015-08-20
- Comitter:
- dfraj
- Date:
- Thu Aug 20 15:08:50 2015 +0000
- Parent:
- 0:c499ebd23db0
- Commit message:
- Current regulation
Changed in this revision
diff -r c499ebd23db0 -r feb19abb96b5 AutomationElements.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AutomationElements.lib Thu Aug 20 15:08:50 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/TVZ-Mechatronics-Team/code/AutomationElements/#b9e11da0f2eb
diff -r c499ebd23db0 -r feb19abb96b5 CurrentMeasurement.cpp --- a/CurrentMeasurement.cpp Sat Jul 18 20:01:58 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#include "CurrentMeasurement.h" - -CurrentMeasurement::CurrentMeasurement(PinName pI_A, PinName pI_B, PinName pI_C, PinName pI_TOTAL):I_A(pI_A), I_B(pI_B), I_C(pI_C), I_TOTAL(pI_TOTAL){ - setValues(1e-3, 1e3, 1e3, 40e3, 20e3, 3.3); - calculateCurrentA(); - calculateCurrentB(); - calculateCurrentC(); - calculateCurrentTotal(); -} - -CurrentMeasurement::CurrentMeasurement(PinName pI_A, PinName pI_B, PinName pI_C, PinName pI_TOTAL, float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref):I_A(pI_A), I_B(pI_B), I_C(pI_C), I_TOTAL(pI_TOTAL){ - setValues(R_sh, R_1s, R_1t, R_fs, R_ft, V_ref); - calculateCurrentA(); - calculateCurrentB(); - calculateCurrentC(); - calculateCurrentTotal(); -} - -void CurrentMeasurement::setValues(float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref){ - this->R_sh = R_sh; - this->R_1s = R_1s; - this->R_1t = R_1t; - this->R_fs = R_fs; - this->R_ft = R_ft; - this->V_ref = V_ref; -} - -float CurrentMeasurement::calculateCurrentA(){ - return I_A_ = (R_sh * R_1s * (V_ref * I_A.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs; -} - -float CurrentMeasurement::calculateCurrentB(){ - return I_B_ = (R_sh * R_1s * (V_ref * I_B.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs; -} - -float CurrentMeasurement::calculateCurrentC(){ - return I_C_ = (R_sh * R_1s * (V_ref * I_C.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs; -} - -float CurrentMeasurement::calculateCurrentTotal(){ - return I_TOTAL_ = (R_1t * (V_ref * I_TOTAL.read()))/(R_ft * R_sh) - (R_1t * (V_ref/2))/(R_ft * R_sh); -} \ No newline at end of file
diff -r c499ebd23db0 -r feb19abb96b5 CurrentMeasurement.h --- a/CurrentMeasurement.h Sat Jul 18 20:01:58 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#ifndef CURRENTMEASUREMENT_H -#define CURRENTMEASUREMENT_H - -#include "mbed.h" - -class CurrentMeasurement{ - public: - CurrentMeasurement(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL); - CurrentMeasurement(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL, float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref); - void setValues(float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref); - float calculateCurrentA(); - float calculateCurrentB(); - float calculateCurrentC(); - float calculateCurrentTotal(); - - private: - AnalogIn I_A, I_B, I_C, I_TOTAL; - float R_sh, R_1s, R_1t, R_fs, R_ft, V_ref, I_A_, I_B_, I_C_, I_TOTAL_; - }; - -#endif -
diff -r c499ebd23db0 -r feb19abb96b5 CurrentRegulation.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CurrentRegulation.lib Thu Aug 20 15:08:50 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/dfraj/code/CurrentRegulation_/#d8dab3dae6f2
diff -r c499ebd23db0 -r feb19abb96b5 main.cpp --- a/main.cpp Sat Jul 18 20:01:58 2015 +0000 +++ b/main.cpp Thu Aug 20 15:08:50 2015 +0000 @@ -1,3 +1,30 @@ +#include "mbed.h" +#include "CurrentRegulation.h" +#include "PI.h" + +Serial pc(USBTX, USBRX); +CurrentRegulation cr(p17, p18, p19, p20); + +int main() { + double K_R; + double T_I = 1.428e-3; + double T_d = 500e-6; + while(true) { + double I_Ar = cr.showResult(); + pc.printf("Current phase A: %f\n\r", I_Ar); + K_R = cr.calculateKr(); + PI reg(K_R, T_I, T_d); + double in = pc.getc(); + double u = in - I_Ar; + reg.in(u); + } +} + + + + + +/* #include "mbed.h" #include "CurrentMeasurement.h" @@ -13,8 +40,10 @@ wait_ms(1); } } +*/ -/*#include "mbed.h" +/* +#include "mbed.h" AnalogIn gas(p16); AnalogIn I_A(p17);