@@ -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,39 +1,87 | |||||
1 | #include <math.h> |
|
1 | #include <math.h> | |
2 |
#define pinADC |
|
2 | #define pinADC 26 | |
|
3 | float find_maximun(float *p); | |||
3 | int analogValue=0; |
|
4 | int analogValue=0; | |
4 | float Vref=2.45;// Voltaje de referencia para el ADC |
|
|||
5 | //int IPP=; |
|
|||
6 | float Vout=0; |
|
5 | float Vout=0; | |
7 |
float Plinea= |
|
6 | float Plinea=62.5,Vpk=0;// Valor entre 1 y 500 kW, las unidades son kW | |
8 | float PdBm=0; |
|
7 | float Plcal=0,dif=0,difPlow=0; | |
9 | int VminPot=1;//con esto quiere decir que potencias |
|
8 | bool serialData=1;//Un valor de 1 indica que se debe ingresar por monitor serial | |
10 | bool serialData=0; |
|
9 | float VoutRef=1,Pmax; | |
11 | float VoutRef=1; |
|
10 | int numSamples=20; | |
|
11 | int total=0; | |||
|
12 | int contador=0,SIZE=40; | |||
|
13 | float *p, Parray[40]; | |||
12 | void setup() { |
|
14 | void setup() { | |
13 | Serial.begin(115200); |
|
15 | Serial.begin(115200); | |
14 |
|
|
16 | analogSetAttenuation(ADC_11db); | |
15 | if(serialData){ |
|
17 | if(serialData){ | |
16 |
Serial.println("Ingrese la potencia en la linea |
|
18 | Serial.println("Ingrese la potencia en la linea:"); | |
17 | while (!Serial.available()); // Wait for input |
|
19 | while (!Serial.available()); // Wait for input | |
18 | String potLinChar = Serial.readStringUntil('\n'); |
|
20 | String potLinChar = Serial.readStringUntil('\n'); | |
19 | Plinea=atof(potLinChar.c_str()); |
|
21 | Plinea=atof(potLinChar.c_str()); | |
20 | } |
|
22 | } | |
21 | PdBm=10 *(log10(Plinea)-2); |
|
23 | Vpk=sqrt(10*Plinea)/5; | |
22 |
VoutRef=ecuacionLineal( |
|
24 | VoutRef=ecuacionLineal(Vpk); | |
23 | Serial.print("Voltaje de salida de referencia: "); |
|
25 | Serial.print("Voltaje de salida de referencia: "); | |
24 |
Serial.print |
|
26 | Serial.print(VoutRef); | |
|
27 | Serial.print("Voltaje pkpk:"); Serial.print(" "); Serial.println(Vpk); | |||
25 | } |
|
28 | } | |
26 |
|
||||
27 | void loop() { |
|
29 | void loop() { | |
28 | // put your main code here, to run repeatedly: |
|
30 | total=0; | |
29 | analogValue = analogRead(pinADC); |
|
31 | //analogValue = analogRead(pinADC); | |
30 | Vout = analogValue * 3.458 / 4095; |
|
32 | /* | |
31 | if(abs(Vout-VoutRef)>0.08 && Vout>1.9 ) { |
|
33 | for (int i = 0; i < numSamples; i++) { | |
32 | Serial.print(Vout); |
|
34 | total += analogRead(pinADC); | |
|
35 | }*/ | |||
|
36 | //int averageValue = total / numSamples; | |||
|
37 | int averageValue=analogRead(pinADC); | |||
|
38 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC | |||
|
39 | //Serial.println(Vout); | |||
|
40 | Plcal=5*pow((Vout+101),2)/(2*175.19*175.19);//Calculamos la potencia en la lΓnea | |||
|
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 | |||
|
43 | Parray[contador]=Plcal; | |||
|
44 | contador =contador+1; | |||
|
45 | } | |||
|
46 | //cuando llenamos los valores hacemos la | |||
|
47 | if (contador==SIZE){ | |||
|
48 | p=&Parray[0]; | |||
|
49 | Pmax=find_maximun(p); | |||
|
50 | contador=0; | |||
|
51 | dif=abs(Plinea-Pmax)*100/Plinea; | |||
|
52 | difPlow=abs(Plinea-Pmax); | |||
|
53 | if(dif>10 && difPlow>7) Serial.println(Pmax); | |||
33 |
|
|
54 | } | |
34 |
|
55 | |||
|
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 | } | |||
|
70 | } | |||
|
71 | } */ | |||
35 | } |
|
72 | } | |
36 |
float ecuacionLineal(float |
|
73 | float ecuacionLineal(float Vpk){ | |
37 |
float m= |
|
74 | float m=175.19,b=-101; | |
38 |
return Vout=m* |
|
75 | return Vout=m*Vpk+b; | |
39 | } |
|
76 | } | |
|
77 | float find_maximun(float *p){ | |||
|
78 | float maxi=*p; | |||
|
79 | float *q; | |||
|
80 | q=p; | |||
|
81 | for(int i=0;i<SIZE;i++){ | |||
|
82 | if(maxi<*(p+i)) { | |||
|
83 | maxi=*(p+i); | |||
|
84 | } | |||
|
85 | } | |||
|
86 | return maxi; | |||
|
87 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now