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