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

Dependencies:   AutomationElements CurrentRegulation_ mbed

CurrentMeasurement.cpp

Committer:
dfraj
Date:
2015-07-18
Revision:
0:c499ebd23db0

File content as of revision 0:c499ebd23db0:

#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);       
}