@@ -1,46 +1,57 | |||
|
1 | 1 | #include <math.h> |
|
2 | 2 | #define pinADC 26 |
|
3 | 3 | int analogValue=0; |
|
4 | 4 | float Vout=0; |
|
5 | 5 | float Plinea=62.5,Vpk=0;// Valor entre 1 y 500 kW, las unidades son kW |
|
6 | float Plcal=0,dif=0; | |
|
6 | float Plcal=0,dif=0,difPlow=0; | |
|
7 | 7 | bool serialData=1;//Un valor de 1 indica que se debe ingresar por monitor serial |
|
8 | 8 | float VoutRef=1; |
|
9 | 9 | int numSamples=20; |
|
10 | 10 | int total=0; |
|
11 | 11 | int contador=0; |
|
12 | 12 | void setup() { |
|
13 | 13 | Serial.begin(115200); |
|
14 | 14 | analogSetAttenuation(ADC_11db); |
|
15 | 15 | if(serialData){ |
|
16 | 16 | Serial.println("Ingrese la potencia en la linea:"); |
|
17 | 17 | while (!Serial.available()); // Wait for input |
|
18 | 18 | String potLinChar = Serial.readStringUntil('\n'); |
|
19 | 19 | Plinea=atof(potLinChar.c_str()); |
|
20 | 20 | } |
|
21 | 21 | Vpk=sqrt(10*Plinea)/5; |
|
22 | 22 | VoutRef=ecuacionLineal(Vpk); |
|
23 | 23 | Serial.print("Voltaje de salida de referencia: "); |
|
24 |
Serial.print |
|
|
24 | Serial.print(VoutRef); | |
|
25 | Serial.print("Voltaje pkpk:"); Serial.print(" "); Serial.println(Vpk); | |
|
25 | 26 | } |
|
26 | 27 | void loop() { |
|
28 | int Parray[10]; | |
|
27 | 29 | total=0; |
|
28 | 30 | //analogValue = analogRead(pinADC); |
|
29 | 31 | //Hacemos multisampling para asegurar el buen performance |
|
32 | /* | |
|
30 | 33 | for (int i = 0; i < numSamples; i++) { |
|
31 | 34 | total += analogRead(pinADC); |
|
32 |
|
|
|
33 | int averageValue = total / numSamples; | |
|
35 | }*/ | |
|
36 | //int averageValue = total / numSamples; | |
|
37 | int averageValue=analogRead(pinADC); | |
|
34 | 38 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC |
|
35 | 39 | //Serial.println(Vout); |
|
36 | 40 | Plcal=5*pow((Vout+101),2)/(2*175.19*175.19);//Calculamos la potencia en la línea |
|
37 | 41 | dif=abs(Plinea-Plcal)*100/Plinea;//Hallamos la diferencia porcentual |
|
38 | if(dif>10 && VoutRef>3000) Serial.println("Nivel anómalo de potencia"); | |
|
39 | else if(VoutRef<3000){ | |
|
40 | Serial.println("Potencia menor a la debida"); | |
|
41 | } | |
|
42 | difPlow=abs(Plinea-Plcal); | |
|
43 | if(dif>10 && Vout>120){ | |
|
44 | Serial.print("Nivel anómalo de potencia Ph"); | |
|
45 | Serial.print(" "); Serial.print(Plcal); | |
|
46 | Serial.print(" "); Serial.println(Vout); | |
|
47 | } | |
|
48 | /* else if(VoutRef<3000 && difPlow>5 && Vout>120){ | |
|
49 | Serial.print("Potencia anómala para Plow"); | |
|
50 | Serial.print(" "); Serial.println(Plcal); | |
|
51 | Serial.println(Vout); | |
|
52 | }*/ | |
|
42 | 53 | } |
|
43 | 54 | float ecuacionLineal(float Vpk){ |
|
44 | 55 | float m=175.19,b=-101; |
|
45 | 56 | return Vout=m*Vpk+b; |
|
46 | 57 | } |
General Comments 0
You need to be logged in to leave comments.
Login now