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