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