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