Dean Fraj / CurrentRegulation
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CurrentRegulation.cpp Source File

CurrentRegulation.cpp

00001 #include "CurrentRegulation.h"
00002 
00003 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){
00004     setValues(1e-3, 1e3, 40e3, 20e3, 3.3);
00005     measure1.attach_us(this, &CurrentRegulation::calculateCurrentA, 500);
00006     measure2.attach_us(this, &CurrentRegulation::calculateTotalCurrent, 500);
00007 }
00008 
00009 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){
00010     setValues(R_sh, R_1, R_fs, R_ft, V_ref);
00011     measure1.attach_us(this, &CurrentRegulation::calculateCurrentA, 500);
00012     measure2.attach_us(this, &CurrentRegulation::calculateTotalCurrent, 500);
00013 }
00014 
00015 void CurrentRegulation::setValues(double R_sh, double R_1, double R_fs, double R_ft, double V_ref){
00016     this->R_sh = R_sh;
00017     this->R_1 = R_1;
00018     this->R_fs = R_fs;
00019     this->R_ft = R_ft;
00020     this->V_ref = V_ref;    
00021 }
00022 
00023 void CurrentRegulation::calculateCurrentA(){
00024     double V_outa = (V_ref - (V_ref/2))/(1 - 0) * I_A.read() + (V_ref/2);
00025     this->I_A_ = (R_1 * V_outa)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs);
00026 }
00027 
00028 void CurrentRegulation::calculateCurrentB(){
00029     double V_outb = (V_ref - (V_ref/2))/(1 - 0) * I_B.read() + (V_ref/2);
00030     this->I_B_ = (R_1 * V_outb)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs);
00031 }
00032 
00033 void CurrentRegulation::calculateCurrentC(){
00034     double V_outc = (V_ref - (V_ref/2))/(1 - 0) * I_C.read() + (V_ref/2);
00035     this->I_C_ = (R_1 * V_outc)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs);
00036 }
00037 
00038 void CurrentRegulation::calculateTotalCurrent(){
00039     double V_outt = (V_ref - (V_ref/2))/(1 - 0)*I_TOTAL.read()+(V_ref/2);
00040     this->I_TOTAL_ = (R_1 * V_outt)/(R_sh * R_fs) - (R_1 * (V_ref/2))/(R_sh * R_fs);
00041 }
00042 
00043 double showResult(){
00044     double I_Ar = this->I_A_;
00045     return I_Ar;
00046 }
00047 
00048 double CurrentRegulation::calculateKr(){
00049     T_pv = 1e-4;
00050     T_ch = 25e-6;
00051     zeta = 1.2;
00052     K_ch = 50.0;
00053     K_pv = 1.0;
00054     T_I = 1.428e-3;
00055     K_a = 4.76;
00056     T_suma = (T_pv + T_ch);
00057     K_oR = 1/(4 * (zeta * zeta) * T_suma);
00058     return K_R = (K_oR * T_I)/(K_a * K_ch * K_pv);
00059 }
00060 
00061 /*
00062 void CurrentMeasurement::phaseCurrent(int currentSector){
00063     switch(currentSector){  
00064            case 0:                
00065                 measureCurrentC();
00066                 break;
00067            case 1:            
00068                 measureCurrentC(); 
00069                 break;
00070            case 2:   
00071                 measureCurrentA();   
00072                 break;
00073             case 3:             
00074                 measureCurrentA(); 
00075                 break;
00076             case 4:              
00077                 measureCurrentB();  
00078                 break;    
00079             case 5:              
00080                 measureCurrentB();  
00081                 break;
00082         }
00083 }
00084 */