2017-12-21 30 views
0

私はArduino Megaをベースにした3相システム監視デバイスを学習/構築しようとしています。これにより、220V/50Hzの3相システム電圧正しい配線順序(L1、l2、l3)のための位相シーケンス検出による電流。3相電圧モニタ/ Arduino + EmonLibを使用した位相シーケンス

私はengineer experiencesからこのプロジェクトをフォローしていて、ハードウェアの部品(上のリンクからの回路図と回路)で良好な結果が得られました。
ソフトウェアについては、電圧と電流の測定にEmonLibを使用しました。私はArduinoから正しい読書を得ました。私は、タイマーループをコードに追加することに関連する部分を理解していないと思います。

これは私の修正コードです:

#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); 
} 

コードはエラーなしでコンパイルが、私はArduinoのIDEからシリアルモニターを開いたときにのみ​​は、実行するために取得し、一度表示。

答えて

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

機能外のピンを読み取ろうとしないでください。それは動作しません。変数は0として初期化されます。つまり、コードがwhileループに陥ることになります。あなたがする必要がどのような

です:コードが今取り組んでいる

int s1; 
int s2; 
int s3; 

[...] 

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

それは、今、明確化のための感謝を働いています –

0

、ここでのコピーは次のとおりです。

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); 
} 
関連する問題