First version of program for measuring current of three phase BLDC motor.

Dependencies:   AutomationElements CurrentRegulation_ mbed

Committer:
dfraj
Date:
Thu Aug 20 15:08:50 2015 +0000
Revision:
1:feb19abb96b5
Parent:
0:c499ebd23db0
Current regulation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dfraj 1:feb19abb96b5 1 #include "mbed.h"
dfraj 1:feb19abb96b5 2 #include "CurrentRegulation.h"
dfraj 1:feb19abb96b5 3 #include "PI.h"
dfraj 1:feb19abb96b5 4
dfraj 1:feb19abb96b5 5 Serial pc(USBTX, USBRX);
dfraj 1:feb19abb96b5 6 CurrentRegulation cr(p17, p18, p19, p20);
dfraj 1:feb19abb96b5 7
dfraj 1:feb19abb96b5 8 int main() {
dfraj 1:feb19abb96b5 9 double K_R;
dfraj 1:feb19abb96b5 10 double T_I = 1.428e-3;
dfraj 1:feb19abb96b5 11 double T_d = 500e-6;
dfraj 1:feb19abb96b5 12 while(true) {
dfraj 1:feb19abb96b5 13 double I_Ar = cr.showResult();
dfraj 1:feb19abb96b5 14 pc.printf("Current phase A: %f\n\r", I_Ar);
dfraj 1:feb19abb96b5 15 K_R = cr.calculateKr();
dfraj 1:feb19abb96b5 16 PI reg(K_R, T_I, T_d);
dfraj 1:feb19abb96b5 17 double in = pc.getc();
dfraj 1:feb19abb96b5 18 double u = in - I_Ar;
dfraj 1:feb19abb96b5 19 reg.in(u);
dfraj 1:feb19abb96b5 20 }
dfraj 1:feb19abb96b5 21 }
dfraj 1:feb19abb96b5 22
dfraj 1:feb19abb96b5 23
dfraj 1:feb19abb96b5 24
dfraj 1:feb19abb96b5 25
dfraj 1:feb19abb96b5 26
dfraj 1:feb19abb96b5 27 /*
dfraj 0:c499ebd23db0 28 #include "mbed.h"
dfraj 0:c499ebd23db0 29 #include "CurrentMeasurement.h"
dfraj 0:c499ebd23db0 30
dfraj 0:c499ebd23db0 31 Serial pc(USBTX, USBRX);
dfraj 0:c499ebd23db0 32
dfraj 0:c499ebd23db0 33 int main(){
dfraj 0:c499ebd23db0 34 CurrentMeasurement c(p17, p18, p19, p20);
dfraj 0:c499ebd23db0 35 while(true){
dfraj 0:c499ebd23db0 36 pc.printf("Current phase A: %f\n\r", c.calculateCurrentA());
dfraj 0:c499ebd23db0 37 pc.printf("Current phase B: %f\n\r", c.calculateCurrentB());
dfraj 0:c499ebd23db0 38 pc.printf("Current phase C: %f\n\r", c.calculateCurrentC());
dfraj 0:c499ebd23db0 39 pc.printf("Total Current: %f\n\r", c.calculateCurrentTotal());
dfraj 0:c499ebd23db0 40 wait_ms(1);
dfraj 0:c499ebd23db0 41 }
dfraj 0:c499ebd23db0 42 }
dfraj 1:feb19abb96b5 43 */
dfraj 0:c499ebd23db0 44
dfraj 1:feb19abb96b5 45 /*
dfraj 1:feb19abb96b5 46 #include "mbed.h"
dfraj 0:c499ebd23db0 47
dfraj 0:c499ebd23db0 48 AnalogIn gas(p16);
dfraj 0:c499ebd23db0 49 AnalogIn I_A(p17);
dfraj 0:c499ebd23db0 50 AnalogIn I_B(p18);
dfraj 0:c499ebd23db0 51 AnalogIn I_C(p19);
dfraj 0:c499ebd23db0 52 AnalogIn I_TOTAL(p20);
dfraj 0:c499ebd23db0 53
dfraj 0:c499ebd23db0 54 Serial pc(USBTX, USBRX);
dfraj 0:c499ebd23db0 55
dfraj 0:c499ebd23db0 56 int main() {
dfraj 0:c499ebd23db0 57 float R_sh = 1e-3;
dfraj 0:c499ebd23db0 58 float R_1s = 1e3;
dfraj 0:c499ebd23db0 59 float R_1t = 1e3;
dfraj 0:c499ebd23db0 60 float R_fs = 40e3;
dfraj 0:c499ebd23db0 61 float R_ft = 20e3;
dfraj 0:c499ebd23db0 62 float V_ref = 3.3;
dfraj 0:c499ebd23db0 63 float I_A_, I_B_, I_C_, I_TOTAL_;
dfraj 0:c499ebd23db0 64 while(1) {
dfraj 0:c499ebd23db0 65 I_A_ = (R_sh * R_1s * (V_ref * I_A.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
dfraj 0:c499ebd23db0 66 I_B_ = (R_sh * R_1s * (V_ref * I_B.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
dfraj 0:c499ebd23db0 67 I_C_ = (R_sh * R_1s * (V_ref * I_C.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
dfraj 0:c499ebd23db0 68 I_TOTAL_ = (R_1t * (V_ref * I_TOTAL.read()))/(R_ft * R_sh) - (R_1t * (V_ref/2))/(R_ft * R_sh);
dfraj 0:c499ebd23db0 69 pc.printf("Current phase A: %f\n\r", I_A_);
dfraj 0:c499ebd23db0 70 pc.printf("Current phase B: %f\n\r", I_B_);
dfraj 0:c499ebd23db0 71 pc.printf("Current phase C: %f\n\r", I_C_);
dfraj 0:c499ebd23db0 72 pc.printf("Total Current: %f\n\r", I_TOTAL_);
dfraj 0:c499ebd23db0 73 wait_ms(1);
dfraj 0:c499ebd23db0 74 }
dfraj 0:c499ebd23db0 75 }
dfraj 0:c499ebd23db0 76 */