2017-12-21 39 views
0

Ich versuche ein 3-phasiges Systemüberwachungsgerät auf Basis von Arduino Mega zu lernen/bauen, das es dem Benutzer ermöglicht, 220V/50Hz 3-phasige Systemspannung zu überwachen und Strom mit Phasenfolgeerkennung für die richtige Verdrahtungsreihenfolge (L1, 12, 13).3-phasige Spannungsüberwachung/Phasenfolge mit Arduino + EmonLib

Ich folgte diesem Projekt von engineer experiences und erzielte gute Ergebnisse auf dem Hardwareteil (Schaltpläne und Schaltung von Link oben).
Für die Software habe ich EmonLib für Spannungs- und Strommessungen verwendet. Ich habe die korrekten Messwerte von Arduino, ich glaube, ich verstehe nicht, dass der Teil zum Hinzufügen von Timer-Schleife zum Code gehört.

Das ist mein modifizierte Code:

#include "EmonLib.h" // Include Emon Library 
EnergyMonitor emon0; // L1 Instance 
EnergyMonitor emon1; // L2 Instance 
EnergyMonitor emon2; // L3 Instance 

int s1 = analogRead(A3); 
int s2 = analogRead(A4); 
int s3 = analogRead(A5); 
unsigned int g=0; 
int i; // For for loops 
unsigned int a22; 

void setup() { 
    Serial.begin(9600); 
    Serial.println("3 phase voltage"); 
    delay(1000); 
    emon0.voltage(0, 225.5, 1.7); // Voltage: input pin, calibration, phase_shift 
    emon1.voltage(1, 225.5, 1.7); // Voltage: input pin, calibration, phase_shift 
    emon2.voltage(2, 225.5, 1.7); // Voltage: input pin, calibration, phase_shift 
    emon0.current(6, 111.1); // Current: input pin, calibration. 
    emon1.current(7, 111.1); // Current: input pin, calibration. 
    emon2.current(8, 111.1); // Current: input pin, calibration. 
} 

//Code Start 
//Function for angle calculations 
int calculations() { 
    unsigned int k=0; 
    //To complete number of counts 
    g=g+1; 
    //To convert into seconds 
    float pf=(float)g/1000000; 
    //To convert seconds into degrees 
    pf=pf*50*360;//here frequency = 50hz 
    k = pf; 
    return k; 
} 

void tloop1() { 
    while(1) { 
    if (s2 != 0) { 
     TCNT1=0; 
     TCCR1B = 0x01; // Start timer1 at Fcpu/1 
     break; 
    } else { 
     continue; 
    } 
    } 

    while(1) { 
    if (s3 != 0){ 
     TCCR1B = 0x00;//stop timer1 
     g=TCNT1;//getting number of counts 
     break; 
    } else { 
     continue; 
    } 
    } 
} 

void tloop2() { 
    while(1) { 
    if (s3 != 0){ 
     TCNT1=0; 
     TCCR1B = 0x01; // Start timer1 at Fcpu/1 
     break; 
    } else { 
     continue; 
    } 
    } 

    while(1) { 
    if (s1 != 0){ 
     TCCR1B = 0x00;//stop timer1 
     g=TCNT1;//getting number of counts 
     break; 
    } else { 
     continue; 
    } 
    } 
} 

float fmap(float x, float in_min, float in_max, float out_min, float out_max) { 
    return (x - in_min) * (out_max - out_min)/(in_max - in_min) + out_min; 
} 

void phase1() { 
    unsigned int a1=0; 
    unsigned int v1=0; 
    emon0.calcVI(20,2000); // Calculate all. No.of wavelengths, time-out 
    float L1supplyVoltage = emon0.Vrms; //extract Vrms into Variable 
    float Irms0 = emon0.Irms; //extract Irms into Variable 
    float cablibratedi0 = 0; 
    Serial.print("phase 1: V = ");Serial.println(L1supplyVoltage); // Print out all variables 
    cablibratedi0 = fmap(Irms0, 0.0, 1024.0, 0.0, 200.0); 
    Serial.print("phase 1: A = ");Serial.println(cablibratedi0); // Print out all variables 
    a1 = calculations(); 
    Serial.print("phase 1: D = ");Serial.println(a1); 
    Serial.print("Line to Next Line Voltage:");Serial.println(L1supplyVoltage * 1.732); 
} 

void phase2() { 
    tloop1(); 
    unsigned int a2=0; 
    unsigned int v2=0; 
    delay(20); 
    emon1.calcVI(20,2000); // Calculate all. No.of wavelengths, time-out 
    float L2supplyVoltage = emon1.Vrms; //extract Vrms into Variable 
    float Irms1 = emon1.Irms; //extract Irms into Variable 
    float cablibratedi1 = 0; 
    Serial.print("phase 2: V = ");Serial.println(L2supplyVoltage); // Print out all variables 
    cablibratedi1 = fmap(Irms1, 0.0, 1024.0, 0.0, 200.0); 
    Serial.print("phase 2: A = ");Serial.println(cablibratedi1); // Print out all variables 
    a2 = calculations(); 
    a22 = a2; 
    Serial.print("phase 2: D = ");Serial.println(a2); 
    Serial.print("Line to Next Line Voltage:");Serial.println(L2supplyVoltage * 1.732); 
    delay(700); 
} 

void phase3() { 
    tloop2(); 
    unsigned int a3=0; 
    unsigned int v3=0; 
    delay(20); 
    emon2.calcVI(20,2000); // Calculate all. No.of wavelengths, time-out 
    float L3supplyVoltage = emon2.Vrms; //extract Vrms into Variable 
    float Irms2 = emon2.Irms; //extract Irms into Variable 
    float cablibratedi2 = 0; 
    Serial.print("phase 3: V = ");Serial.println(L3supplyVoltage);   // Print out all variables 
    cablibratedi2 = fmap(Irms2, 0.0, 1024.0, 0.0, 200.0); 
    Serial.print("phase 3: A = ");Serial.println(cablibratedi2); // Print out all variables 
    a3 = calculations(); 
    a3 = a22 + a3; 
    Serial.print("phase 3: D = ");Serial.println(a3); 
    Serial.print("Line to Next Line Voltage:");Serial.println(L3supplyVoltage * 1.732); 
} 

void loop() { 
    phase1(); 
    phase2(); 
    phase3(); 
    delay(1000); 
} 

-Code ohne Fehler kompiliert wird, aber wenn ich seriellen Monitor von Arduino IDE öffne nur phase1(); wird einmal ausgeführt und angezeigt.

Antwort

1
int s1 = analogRead(A3); 
int s2 = analogRead(A4); 
int s3 = analogRead(A5); 

Versuchen Sie nicht, Pins außerhalb von Funktionen zu lesen. Es wird nicht funktionieren. Die Variablen werden als 0 initialisiert. Das bedeutet, dass Ihr Code in einer while-Schleife hängen bleibt.

Was Sie tun müssen, ist:

int s1; 
int s2; 
int s3; 

[...] 

void setup() { 
    s1 = analogRead(A3); 
    s2 = analogRead(A4); 
    s3 = analogRead(A5); 
+0

Es funktioniert jetzt, Dank für Klärung –

0

Der Code funktioniert jetzt, hier ist Kopie davon:

int m; float n; 
int m1; float n1; 
int m2; float n2; 

void setup() 
{ 
    pinMode(A0,INPUT); // L1 
    pinMode(A1,INPUT); // L2 
    pinMode(A2,INPUT); // L3 
    pinMode(A3,INPUT); // A 
    pinMode(A4,INPUT); // B 
    pinMode(A5,INPUT); // C 
    Serial.begin(9600); 
} 

void loop() 
{ 
    m=analogRead(A0);// read analog values from pin A0 across capacitor 
    n=(m* .304177);// converts analog value(x) into input ac supply value using this formula (explained in woeking section) 

    Serial.print("1 analaog input ") ; // specify name to the corresponding value to be printed 
    Serial.print(m) ; // print input analog value on serial monitor 
    Serial.print(" ac voltage ") ; // specify name to the corresponding value to be printed 
    Serial.print(n) ; // prints the ac value on Serial monitor 
    Serial.println(); 
    delay(1000); 

    m1=analogRead(A1);// read analog values from pin A0 across capacitor 
    n1=(m1* .304177);// converts analog value(x) into input ac supply value using this formula (explained in woeking section) 

    Serial.print("2 analaog input ") ; // specify name to the corresponding value to be printed 
    Serial.print(m1) ; // print input analog value on serial monitor 
    Serial.print(" ac voltage ") ; // specify name to the corresponding value to be printed 
    Serial.print(n1) ; // prints the ac value on Serial monitor 
    Serial.println(); 
    delay(1000); 

    m2=analogRead(A2);// read analog values from pin A0 across capacitor 
    n2=(m2* .304177);// converts analog value(x) into input ac supply value using this formula (explained in woeking section) 

    Serial.print("3 analaog input ") ; // specify name to the corresponding value to be printed 
    Serial.print(m2) ; // print input analog value on serial monitor 
    Serial.print(" ac voltage ") ; // specify name to the corresponding value to be printed 
    Serial.print(n2) ; // prints the ac value on Serial monitor 
    Serial.println(); 
    delay(1000); 
}