TVZ Mechatronics Team / Mbed 2 deprecated CurrentMeasurement

Dependencies:   AutomationElements CurrentRegulation_ mbed

Files at this revision

API Documentation at this revision

Comitter:
dfraj
Date:
Sat Jul 18 20:01:58 2015 +0000
Child:
1:feb19abb96b5
Commit message:
First version of program for measuring current of three phase BLDC motor.

Changed in this revision

CurrentMeasurement.cpp Show annotated file Show diff for this revision Revisions of this file
CurrentMeasurement.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CurrentMeasurement.h	Sat Jul 18 20:01:58 2015 +0000
@@ -0,0 +1,22 @@
+#ifndef CURRENTMEASUREMENT_H
+#define CURRENTMEASUREMENT_H
+
+#include "mbed.h"
+
+class CurrentMeasurement{
+    public:
+        CurrentMeasurement(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL);
+        CurrentMeasurement(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL, float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref);
+        void setValues(float R_sh, float R_1s, float R_1t, float R_fs, float R_ft, float V_ref);
+        float calculateCurrentA();
+        float calculateCurrentB();
+        float calculateCurrentC();
+        float calculateCurrentTotal();
+        
+    private:
+        AnalogIn I_A, I_B, I_C, I_TOTAL;
+        float R_sh, R_1s, R_1t, R_fs, R_ft, V_ref, I_A_, I_B_, I_C_, I_TOTAL_; 
+    };
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 18 20:01:58 2015 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "CurrentMeasurement.h"
+
+Serial pc(USBTX, USBRX);
+
+int main(){
+    CurrentMeasurement c(p17, p18, p19, p20);
+    while(true){
+        pc.printf("Current phase A: %f\n\r", c.calculateCurrentA());
+        pc.printf("Current phase B: %f\n\r", c.calculateCurrentB()); 
+        pc.printf("Current phase C: %f\n\r", c.calculateCurrentC()); 
+        pc.printf("Total Current: %f\n\r", c.calculateCurrentTotal()); 
+        wait_ms(1);       
+    }
+}
+
+/*#include "mbed.h"
+
+AnalogIn gas(p16);
+AnalogIn I_A(p17);
+AnalogIn I_B(p18);
+AnalogIn I_C(p19);
+AnalogIn I_TOTAL(p20);
+
+Serial pc(USBTX, USBRX);
+
+int main() {
+    float R_sh = 1e-3;
+    float R_1s = 1e3;
+    float R_1t = 1e3;
+    float R_fs = 40e3;
+    float R_ft = 20e3;
+    float V_ref = 3.3;
+    float I_A_, I_B_, I_C_, I_TOTAL_;
+    while(1) {
+        I_A_ = (R_sh * R_1s * (V_ref * I_A.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
+        I_B_ = (R_sh * R_1s * (V_ref * I_B.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
+        I_C_ = (R_sh * R_1s * (V_ref * I_C.read()))/R_fs - (R_sh * R_1s * (V_ref/2))/R_fs;
+        I_TOTAL_ = (R_1t * (V_ref * I_TOTAL.read()))/(R_ft * R_sh) - (R_1t * (V_ref/2))/(R_ft * R_sh);
+        pc.printf("Current phase A: %f\n\r", I_A_);
+        pc.printf("Current phase B: %f\n\r", I_B_);
+        pc.printf("Current phase C: %f\n\r", I_C_);
+        pc.printf("Total Current: %f\n\r", I_TOTAL_);
+        wait_ms(1);
+    }
+}
+*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jul 18 20:01:58 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file