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