@@ -1,39 +1,43 | |||
|
1 | 1 | #include <math.h> |
|
2 |
#define pinADC |
|
|
2 | #define pinADC 26 | |
|
3 | 3 | int analogValue=0; |
|
4 |
float Vref= |
|
|
5 | //int IPP=; | |
|
4 | float Vref=3100;// Voltaje de referencia para el ADC | |
|
6 | 5 | float Vout=0; |
|
7 | float Plinea=57.6;// Valor entre 1 y 500 kW, las unidades son kW | |
|
8 | float PdBm=0; | |
|
9 | int VminPot=1;//con esto quiere decir que potencias | |
|
10 | bool serialData=0; | |
|
6 | float Plinea=57.6,PdBm=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 | |
|
8 | bool serialData=0;//Un valor de 1 indica que se debe ingresar por monitor | |
|
11 | 9 | float VoutRef=1; |
|
10 | int numSamples=20; | |
|
11 | int total=0; | |
|
12 | 12 | void setup() { |
|
13 | 13 | Serial.begin(115200); |
|
14 | // analogSetAttenuation(ADC_11db); | |
|
14 | ||
|
15 | analogSetAttenuation(ADC_11db); | |
|
15 | 16 | if(serialData){ |
|
16 |
Serial.println("Ingrese la potencia en la linea |
|
|
17 | Serial.println("Ingrese la potencia en la linea:"); | |
|
17 | 18 | while (!Serial.available()); // Wait for input |
|
18 | 19 | String potLinChar = Serial.readStringUntil('\n'); |
|
19 | 20 | Plinea=atof(potLinChar.c_str()); |
|
20 | 21 | } |
|
21 | 22 | PdBm=10 *(log10(Plinea)-2); |
|
22 | 23 | VoutRef=ecuacionLineal(PdBm); |
|
23 | 24 | Serial.print("Voltaje de salida de referencia: "); |
|
24 | 25 | Serial.println(VoutRef); |
|
26 | ||
|
25 | 27 | } |
|
26 | 28 | |
|
27 | 29 | void loop() { |
|
28 | // put your main code here, to run repeatedly: | |
|
29 | analogValue = analogRead(pinADC); | |
|
30 | Vout = analogValue * 3.458 / 4095; | |
|
31 | if(abs(Vout-VoutRef)>0.08 && Vout>1.9 ) { | |
|
32 | Serial.print(Vout); | |
|
30 | total=0; | |
|
31 | //analogValue = analogRead(pinADC); | |
|
32 | for (int i = 0; i < numSamples; i++) { | |
|
33 | total += analogRead(pinADC); | |
|
34 | delay(1); | |
|
33 | 35 | } |
|
34 | ||
|
36 | int averageValue = total / numSamples; | |
|
37 | Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC | |
|
38 | Serial.print(Vout); | |
|
35 | 39 | } |
|
36 | 40 | float ecuacionLineal(float PdBm){ |
|
37 | 41 | float m=-0.02451,b=1.048; |
|
38 | 42 | return Vout=m*PdBm+b; |
|
39 | 43 | } |
General Comments 0
You need to be logged in to leave comments.
Login now