@@ -1,14 +1,16 | |||||
1 | #include <math.h> |
|
1 | #include <math.h> | |
2 | #define pinADC 26 |
|
2 | #define pinADC 26 | |
|
3 | float find_maximun(float *p); | |||
3 | int analogValue=0; |
|
4 | int analogValue=0; | |
4 | float Vout=0; |
|
5 | float Vout=0; | |
5 | float Plinea=62.5,Vpk=0;// Valor entre 1 y 500 kW, las unidades son kW |
|
6 | float Plinea=62.5,Vpk=0;// Valor entre 1 y 500 kW, las unidades son kW | |
6 | float Plcal=0,dif=0,difPlow=0; |
|
7 | float Plcal=0,dif=0,difPlow=0; | |
7 | bool serialData=1;//Un valor de 1 indica que se debe ingresar por monitor serial |
|
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 | int numSamples=20; |
|
10 | int numSamples=20; | |
10 | int total=0; |
|
11 | int total=0; | |
11 | int contador=0; |
|
12 | int contador=0,SIZE=15; | |
|
13 | float *p, Parray[15]; | |||
12 | void setup() { |
|
14 | void setup() { | |
13 | Serial.begin(115200); |
|
15 | Serial.begin(115200); | |
14 | analogSetAttenuation(ADC_11db); |
|
16 | analogSetAttenuation(ADC_11db); | |
@@ -25,7 +27,6 void setup() { | |||||
25 | Serial.print("Voltaje pkpk:"); Serial.print(" "); Serial.println(Vpk); |
|
27 | Serial.print("Voltaje pkpk:"); Serial.print(" "); Serial.println(Vpk); | |
26 | } |
|
28 | } | |
27 | void loop() { |
|
29 | void loop() { | |
28 | int Parray[10]; |
|
|||
29 | total=0; |
|
30 | total=0; | |
30 | //analogValue = analogRead(pinADC); |
|
31 | //analogValue = analogRead(pinADC); | |
31 | //Hacemos multisampling para asegurar el buen performance |
|
32 | //Hacemos multisampling para asegurar el buen performance | |
@@ -41,9 +42,18 void loop() { | |||||
41 | dif=abs(Plinea-Plcal)*100/Plinea;//Hallamos la diferencia porcentual |
|
42 | dif=abs(Plinea-Plcal)*100/Plinea;//Hallamos la diferencia porcentual | |
42 | difPlow=abs(Plinea-Plcal); |
|
43 | difPlow=abs(Plinea-Plcal); | |
43 | if(dif>10 && Vout>120){ |
|
44 | if(dif>10 && Vout>120){ | |
44 | Serial.print("Nivel anómalo de potencia Ph"); |
|
45 | Parray[contador]=Plcal; | |
45 | Serial.print(" "); Serial.print(Plcal); |
|
46 | contador =contador+1; | |
46 | Serial.print(" "); Serial.println(Vout); |
|
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 | /* else if(VoutRef<3000 && difPlow>5 && Vout>120){ |
|
58 | /* else if(VoutRef<3000 && difPlow>5 && Vout>120){ | |
49 | Serial.print("Potencia anómala para Plow"); |
|
59 | Serial.print("Potencia anómala para Plow"); | |
@@ -55,3 +65,14 float ecuacionLineal(float Vpk){ | |||||
55 | float m=175.19,b=-101; |
|
65 | float m=175.19,b=-101; | |
56 | return Vout=m*Vpk+b; |
|
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