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

Dependencies:   AutomationElements CurrentRegulation_ mbed

Revision:
0:c499ebd23db0
diff -r 000000000000 -r c499ebd23db0 CurrentMeasurement.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CurrentMeasurement.cpp	Sat Jul 18 20:01:58 2015 +0000
@@ -0,0 +1,42 @@
+#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