Dean Fraj / CurrentRegulation_

Dependents:   CurrentMeasurement

Fork of CurrentRegulation by Dean Fraj

Files at this revision

API Documentation at this revision

Comitter:
dfraj
Date:
Tue Aug 25 19:14:01 2015 +0000
Parent:
1:9406a55d8a12
Commit message:
v0.2

Changed in this revision

CurrentRegulation.cpp Show annotated file Show diff for this revision Revisions of this file
CurrentRegulation.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/CurrentRegulation.h	Mon Aug 24 11:13:04 2015 +0000
+++ b/CurrentRegulation.h	Tue Aug 25 19:14:01 2015 +0000
@@ -7,7 +7,8 @@
 
 class CurrentRegulation{
     public:
-        CurrentRegulation(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL, PinName GH_A, PinName GL_A, PinName GH_B, PinName GL_B, PinName GH_C, PinName GL_C, PinName h1, PinName h2, PinName h3, PinName Fault);
+        CurrentRegulation(PinName I_A, PinName I_B, PinName I_C, PinName I_TOTAL, PinName GH_A, PinName GL_A, PinName GH_B, PinName GL_B,
+        PinName GH_C, PinName GL_C, PinName h1, PinName h2, PinName h3, PinName Fault);
         void setValues(double R_sh, double R_1, double R_fs, double R_ft, double V_ref);
         double calculateCurrentA();
         double calculateCurrentB();
@@ -16,10 +17,13 @@
         double calculateKr();     
         double phaseCurrent(int currentSector);
         void measuring();
-        void input(double in);   
+        void getValue();
+        //void input(double in); 
+        void setOutput(double in);  
     private:
         AnalogIn I_A, I_B, I_C, I_TOTAL;
-        double R_sh, R_1, R_fs, R_ft, V_ref, I_A_, I_B_, I_C_, I_TOTAL_, zeta, T_suma, T_ch, T_pv, T_I, K_ch, K_R, K_pv, K_a, K_oR, T_d, setPoint, procesValue, I_Ar, u;
+        double R_sh, R_1, R_fs, R_ft, V_ref, I_A_, I_B_, I_C_, I_TOTAL_, zeta, T_suma, T_ch, T_pv, T_I, K_ch, K_R, K_pv, K_a, K_oR, T_d, 
+        setPoint, procesValue, I_Ar, u, output;
         int sector;
         Ticker measure;
         PI reg;