2017-12-21 5 views
0

Arduino Mega를 기반으로하는 3 상 시스템 모니터링 장치를 배우고/구축하려고합니다. 사용자가 220V/50Hz 3 상 시스템 전압을 모니터링 할 수 있습니다. 올바른 배선 순서 (L1, ℓ2, ℓ3)에 대한 위상 순서 검출 전류.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); 
} 

코드가 오류없이 컴파일하지만 아두 이노 IDE에서 시리얼 모니터를 열 경우에만 phase1(); 실행하고 한 번에 표시 할 가져옵니다.

답변

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); 
} 
관련 문제