Program for current regulation of BLDC motor.

Dependents:   CurrentMeasurement

Fork of CurrentRegulation by Dean Fraj

Revision:
2:f71d1fb67922
Parent:
1:9406a55d8a12
diff -r 9406a55d8a12 -r f71d1fb67922 CurrentRegulation.cpp
--- a/CurrentRegulation.cpp	Mon Aug 24 11:13:04 2015 +0000
+++ b/CurrentRegulation.cpp	Tue Aug 25 19:14:01 2015 +0000
@@ -5,7 +5,7 @@
 CurrentRegulation::CurrentRegulation(PinName pI_A, PinName pI_B, PinName pI_C, PinName pI_TOTAL, PinName pGH_A, PinName pGH_B, PinName pGH_C, PinName pGL_A, PinName pGL_B, PinName pGL_C,
                     PinName pH1, PinName pH2, PinName pH3, PinName pFault):I_A(pI_A), I_B(pI_B), I_C(pI_C), I_TOTAL(pI_TOTAL), m(pGH_A, pGH_B, pGH_C, pGL_A, pGL_B, pGL_C, pH1, pH2, pH3, LED1){
     setValues(1e-3, 1e3, 40e3, 20e3, 3.3);
-    measure.attach_us(this, &CurrentRegulation::measuring, 500);
+    //measure.attach_us(this, &CurrentRegulation::measuring, 500);
 }
 
 void CurrentRegulation::setValues(double R_sh, double R_1, double R_fs, double R_ft, double V_ref){
@@ -66,6 +66,15 @@
     return I_Ar;
 }
 
+void CurrentRegulation::getValue(){
+    sector = m.getSector();
+    procesValue = phaseCurrent(sector);
+}
+
+void CurrentRegulation::measuring(){
+    measure.attach_us(this, &CurrentRegulation::getValue, 500);
+}
+
 double CurrentRegulation::calculateKr(){
     T_pv = 1e-4;
     T_ch = 25e-6;
@@ -79,17 +88,18 @@
     return K_R = (K_oR * T_I)/(K_a * K_ch * K_pv);
 }
 
-void CurrentRegulation::input(double in){
-    setPoint = in;
+/*void CurrentRegulation::input(double in){
+    setPoint = 41.25 * in;
 }
+*/
 
-void CurrentRegulation::measuring(){
-    sector = m.getSector();
-    procesValue = phaseCurrent(sector);
+void CurrentRegulation::setOutput(double in){
     K_R = calculateKr();
     T_d = 500e-6;
     PI reg(K_R, T_I, T_d);
+    setPoint = 41.25 * in;
     u = setPoint - procesValue;
     reg.in(u); 
-    reg.out();
+    output = reg.out();
+    m.setDutyCycle(output);
 }
\ No newline at end of file