Program for current regulation of BLDC motor.
Dependents: CurrentMeasurement
Fork of CurrentRegulation by
CurrentRegulation.cpp@0:d8dab3dae6f2, 2015-08-20 (annotated)
- Committer:
- dfraj
- Date:
- Thu Aug 20 14:58:23 2015 +0000
- Revision:
- 0:d8dab3dae6f2
- Child:
- 1:9406a55d8a12
Library for current regulation of BLDC motor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dfraj | 0:d8dab3dae6f2 | 1 | #include "CurrentRegulation.h" |
dfraj | 0:d8dab3dae6f2 | 2 | |
dfraj | 0:d8dab3dae6f2 | 3 | CurrentRegulation::CurrentRegulation(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){ |
dfraj | 0:d8dab3dae6f2 | 4 | setValues(1e-3, 1e3, 40e3, 20e3, 3.3); |
dfraj | 0:d8dab3dae6f2 | 5 | measure1.attach_us(this, &CurrentRegulation::calculateCurrentA, 500); |
dfraj | 0:d8dab3dae6f2 | 6 | measure2.attach_us(this, &CurrentRegulation::calculateTotalCurrent, 500); |
dfraj | 0:d8dab3dae6f2 | 7 | } |
dfraj | 0:d8dab3dae6f2 | 8 | |
dfraj | 0:d8dab3dae6f2 | 9 | CurrentRegulation::CurrentRegulation(PinName pI_A, PinName pI_B, PinName pI_C, PinName pI_TOTAL, double R_sh, double R_1, double R_fs, double R_ft, double V_ref):I_A(pI_A), I_B(pI_B), I_C(pI_C), I_TOTAL(pI_TOTAL){ |
dfraj | 0:d8dab3dae6f2 | 10 | setValues(R_sh, R_1, R_fs, R_ft, V_ref); |
dfraj | 0:d8dab3dae6f2 | 11 | measure1.attach_us(this, &CurrentRegulation::calculateCurrentA, 500); |
dfraj | 0:d8dab3dae6f2 | 12 | measure2.attach_us(this, &CurrentRegulation::calculateTotalCurrent, 500); |
dfraj | 0:d8dab3dae6f2 | 13 | } |
dfraj | 0:d8dab3dae6f2 | 14 | |
dfraj | 0:d8dab3dae6f2 | 15 | void CurrentRegulation::setValues(double R_sh, double R_1, double R_fs, double R_ft, double V_ref){ |
dfraj | 0:d8dab3dae6f2 | 16 | this->R_sh = R_sh; |
dfraj | 0:d8dab3dae6f2 | 17 | this->R_1 = R_1; |
dfraj | 0:d8dab3dae6f2 | 18 | this->R_fs = R_fs; |
dfraj | 0:d8dab3dae6f2 | 19 | this->R_ft = R_ft; |
dfraj | 0:d8dab3dae6f2 | 20 | this->V_ref = V_ref; |
dfraj | 0:d8dab3dae6f2 | 21 | } |
dfraj | 0:d8dab3dae6f2 | 22 | |
dfraj | 0:d8dab3dae6f2 | 23 | void CurrentRegulation::calculateCurrentA(){ |
dfraj | 0:d8dab3dae6f2 | 24 | double V_outa = (V_ref - (V_ref/2))/(1 - 0) * I_A.read() + (V_ref/2); |
dfraj | 0:d8dab3dae6f2 | 25 | this->I_A_ = (R_1 * V_outa)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs); |
dfraj | 0:d8dab3dae6f2 | 26 | } |
dfraj | 0:d8dab3dae6f2 | 27 | |
dfraj | 0:d8dab3dae6f2 | 28 | void CurrentRegulation::calculateCurrentB(){ |
dfraj | 0:d8dab3dae6f2 | 29 | double V_outb = (V_ref - (V_ref/2))/(1 - 0) * I_B.read() + (V_ref/2); |
dfraj | 0:d8dab3dae6f2 | 30 | this->I_B_ = (R_1 * V_outb)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs); |
dfraj | 0:d8dab3dae6f2 | 31 | } |
dfraj | 0:d8dab3dae6f2 | 32 | |
dfraj | 0:d8dab3dae6f2 | 33 | void CurrentRegulation::calculateCurrentC(){ |
dfraj | 0:d8dab3dae6f2 | 34 | double V_outc = (V_ref - (V_ref/2))/(1 - 0) * I_C.read() + (V_ref/2); |
dfraj | 0:d8dab3dae6f2 | 35 | this->I_C_ = (R_1 * V_outc)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs); |
dfraj | 0:d8dab3dae6f2 | 36 | } |
dfraj | 0:d8dab3dae6f2 | 37 | |
dfraj | 0:d8dab3dae6f2 | 38 | void CurrentRegulation::calculateTotalCurrent(){ |
dfraj | 0:d8dab3dae6f2 | 39 | double V_outt = (V_ref - (V_ref/2))/(1 - 0)*I_TOTAL.read()+(V_ref/2); |
dfraj | 0:d8dab3dae6f2 | 40 | this->I_TOTAL_ = (R_1 * V_outt)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs); |
dfraj | 0:d8dab3dae6f2 | 41 | } |
dfraj | 0:d8dab3dae6f2 | 42 | |
dfraj | 0:d8dab3dae6f2 | 43 | double showResult(){ |
dfraj | 0:d8dab3dae6f2 | 44 | double I_Ar = this->I_A_; |
dfraj | 0:d8dab3dae6f2 | 45 | return I_Ar; |
dfraj | 0:d8dab3dae6f2 | 46 | } |
dfraj | 0:d8dab3dae6f2 | 47 | |
dfraj | 0:d8dab3dae6f2 | 48 | double CurrentRegulation::calculateKr(){ |
dfraj | 0:d8dab3dae6f2 | 49 | T_pv = 1e-4; |
dfraj | 0:d8dab3dae6f2 | 50 | T_ch = 25e-6; |
dfraj | 0:d8dab3dae6f2 | 51 | zeta = 1.2; |
dfraj | 0:d8dab3dae6f2 | 52 | K_ch = 50.0; |
dfraj | 0:d8dab3dae6f2 | 53 | K_pv = 1.0; |
dfraj | 0:d8dab3dae6f2 | 54 | T_I = 1.428e-3; |
dfraj | 0:d8dab3dae6f2 | 55 | K_a = 4.76; |
dfraj | 0:d8dab3dae6f2 | 56 | T_suma = (T_pv + T_ch); |
dfraj | 0:d8dab3dae6f2 | 57 | K_oR = 1/(4 * (zeta * zeta) * T_suma); |
dfraj | 0:d8dab3dae6f2 | 58 | return K_R = (K_oR * T_I)/(K_a * K_ch * K_pv); |
dfraj | 0:d8dab3dae6f2 | 59 | } |
dfraj | 0:d8dab3dae6f2 | 60 | |
dfraj | 0:d8dab3dae6f2 | 61 | /* |
dfraj | 0:d8dab3dae6f2 | 62 | void CurrentMeasurement::phaseCurrent(int currentSector){ |
dfraj | 0:d8dab3dae6f2 | 63 | switch(currentSector){ |
dfraj | 0:d8dab3dae6f2 | 64 | case 0: |
dfraj | 0:d8dab3dae6f2 | 65 | measureCurrentC(); |
dfraj | 0:d8dab3dae6f2 | 66 | break; |
dfraj | 0:d8dab3dae6f2 | 67 | case 1: |
dfraj | 0:d8dab3dae6f2 | 68 | measureCurrentC(); |
dfraj | 0:d8dab3dae6f2 | 69 | break; |
dfraj | 0:d8dab3dae6f2 | 70 | case 2: |
dfraj | 0:d8dab3dae6f2 | 71 | measureCurrentA(); |
dfraj | 0:d8dab3dae6f2 | 72 | break; |
dfraj | 0:d8dab3dae6f2 | 73 | case 3: |
dfraj | 0:d8dab3dae6f2 | 74 | measureCurrentA(); |
dfraj | 0:d8dab3dae6f2 | 75 | break; |
dfraj | 0:d8dab3dae6f2 | 76 | case 4: |
dfraj | 0:d8dab3dae6f2 | 77 | measureCurrentB(); |
dfraj | 0:d8dab3dae6f2 | 78 | break; |
dfraj | 0:d8dab3dae6f2 | 79 | case 5: |
dfraj | 0:d8dab3dae6f2 | 80 | measureCurrentB(); |
dfraj | 0:d8dab3dae6f2 | 81 | break; |
dfraj | 0:d8dab3dae6f2 | 82 | } |
dfraj | 0:d8dab3dae6f2 | 83 | } |
dfraj | 0:d8dab3dae6f2 | 84 | */ |