Main code of our project.

Dependencies:   TextLCD mbed PID

Revision:
3:a1b11dfd26f3
Parent:
2:e612706e18eb
Child:
4:886ce7eefa6e
--- a/main.cpp	Fri Sep 21 07:32:33 2018 +0000
+++ b/main.cpp	Sun Oct 07 01:19:29 2018 +0000
@@ -8,7 +8,9 @@
 //PwmOut              pwm1(D9);
 DigitalOut          relaySync(D8);
 
-AnalogIn            analog_pin1(A0);
+AnalogIn            syncPin(A0);
+AnalogIn            gridPin(A1);
+AnalogIn            differentialPin(A2);
 
 const float         sqrt2 = 1.414213562;
 
@@ -44,30 +46,35 @@
 // ########## MAIN ##############################
 // #############################################################################
 int main() {
-    float Vm;
-    float freq1;
+    float syncRMS, gridRMS, syncFreq, gridFreq;
     
     relaySync = 1;//Relay off=1, on=0
     while(1){
-        if(getVolageReadedMax(analog_pin1) < 0.020){
+        /*if(getVolageReadedMax(analog_pin1) < 0.020){
             relaySync = 0;//Relay off=1, on=0
             lcd.locate(0,0);
             lcd.printf("SYNC");
-        }
+        }*/
+        syncRMS = getVolageRMS(syncPin);
+        gridRMS = getVolageRMS(gridPin);
+        syncFreq = getFrequency(syncPin);
+        gridFreq = getFrequency(gridPin);
+        
+        lcd.locate(0,0);//(col,row)
+        lcd.printf("                ");
+        lcd.locate(0,1);//(col,row)
+        lcd.printf("                ");
+        lcd.locate(0,0);//(col,row)
+        lcd.printf("G:%3.1f@%3.1f", gridRMS, gridFreq);
+        lcd.locate(0,1);//(col,row)
+        lcd.printf("S:%3.1f@%3.1f", syncRMS, syncFreq);
     }
     
     
     // specify period first
     //pwm1.period(0.1f);      // 4 second period
     //pwm1.write(0.50f);      // 50% duty cycle, relative to period
-    
-    
-    Vm = getVolageRMS(analog_pin1);
-    lcd.locate(0,0);
-    lcd.printf("Vm=%f", Vm);
-    freq1 = getFrequency(analog_pin1);
-    lcd.locate(0,1);
-    lcd.printf("freq1=%f", freq1);
+
 }
 
 
@@ -97,7 +104,7 @@
             v1Max = v1;
         }
     }
-    VRMS = (v1Max+0.685)*20.8/sqrt2;
+    VRMS = (v1Max+0.685)*9.32/sqrt2;
     pc.printf("VRMS: %f\r\n",VRMS);
     return VRMS;
 }
@@ -120,7 +127,6 @@
 
 
 // #############################################################################
-// getFrequency #######
 float getFrequency(AnalogIn ana_pin){
     float   freq; //frequency
     float   maxReadedVoltage;//maximum voltage readed by the ADC