@@ -1,43 +1,46 | |||||
1 | #include <math.h> |
|
1 | #include <math.h> | |
2 | #define pinADC 26 |
|
2 | #define pinADC 26 | |
3 | int analogValue=0; |
|
3 | int analogValue=0; | |
4 | float Vref=3100;// Voltaje de referencia para el ADC |
|
|||
5 | float Vout=0; |
|
4 | float Vout=0; | |
6 |
float Plinea= |
|
5 | float Plinea=62.5,Vpk=0;// Valor entre 1 y 500 kW, las unidades son kW | |
7 | int VminPot=1;//con esto quiere decir que potencia es la máxima |
|
6 | float Plcal=0,dif=0; | |
8 |
bool serialData= |
|
7 | bool serialData=1;//Un valor de 1 indica que se debe ingresar por monitor serial | |
9 | float VoutRef=1; |
|
8 | float VoutRef=1; | |
10 | int numSamples=20; |
|
9 | int numSamples=20; | |
11 | int total=0; |
|
10 | int total=0; | |
|
11 | int contador=0; | |||
12 | void setup() { |
|
12 | void setup() { | |
13 | Serial.begin(115200); |
|
13 | Serial.begin(115200); | |
14 |
|
||||
15 | analogSetAttenuation(ADC_11db); |
|
14 | analogSetAttenuation(ADC_11db); | |
16 | if(serialData){ |
|
15 | if(serialData){ | |
17 | Serial.println("Ingrese la potencia en la linea:"); |
|
16 | Serial.println("Ingrese la potencia en la linea:"); | |
18 | while (!Serial.available()); // Wait for input |
|
17 | while (!Serial.available()); // Wait for input | |
19 | String potLinChar = Serial.readStringUntil('\n'); |
|
18 | String potLinChar = Serial.readStringUntil('\n'); | |
20 | Plinea=atof(potLinChar.c_str()); |
|
19 | Plinea=atof(potLinChar.c_str()); | |
21 | } |
|
20 | } | |
22 | PdBm=10 *(log10(Plinea)-2); |
|
21 | Vpk=sqrt(10*Plinea)/5; | |
23 |
VoutRef=ecuacionLineal( |
|
22 | VoutRef=ecuacionLineal(Vpk); | |
24 | Serial.print("Voltaje de salida de referencia: "); |
|
23 | Serial.print("Voltaje de salida de referencia: "); | |
25 | Serial.println(VoutRef); |
|
24 | Serial.println(VoutRef); | |
26 |
|
||||
27 | } |
|
25 | } | |
28 |
|
||||
29 | void loop() { |
|
26 | void loop() { | |
30 | total=0; |
|
27 | total=0; | |
31 | //analogValue = analogRead(pinADC); |
|
28 | //analogValue = analogRead(pinADC); | |
|
29 | //Hacemos multisampling para asegurar el buen performance | |||
32 | for (int i = 0; i < numSamples; i++) { |
|
30 | for (int i = 0; i < numSamples; i++) { | |
33 | total += analogRead(pinADC); |
|
31 | total += analogRead(pinADC); | |
34 | delay(1); |
|
|||
35 | } |
|
32 | } | |
36 | int averageValue = total / numSamples; |
|
33 | int averageValue = total / numSamples; | |
37 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC |
|
34 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC | |
38 | Serial.print(Vout); |
|
35 | //Serial.println(Vout); | |
|
36 | Plcal=5*pow((Vout+101),2)/(2*175.19*175.19);//Calculamos la potencia en la línea | |||
|
37 | 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 | } | |||
39 | } |
|
42 | } | |
40 |
float ecuacionLineal(float |
|
43 | float ecuacionLineal(float Vpk){ | |
41 |
float m= |
|
44 | float m=175.19,b=-101; | |
42 |
return Vout=m* |
|
45 | return Vout=m*Vpk+b; | |
43 | } |
|
46 | } |
General Comments 0
You need to be logged in to leave comments.
Login now