ADC_ZX47.ino
39 lines
| 1.0 KiB
| text/x-arduino
|
ArduinoLexer
/ ADC_ZX47 / ADC_ZX47.ino
|
r2 | #include <math.h> | ||
#define pinADC 12 | ||||
|
r1 | int analogValue=0; | ||
|
r2 | float Vref=2.45;// Voltaje de referencia para el ADC | ||
|
r1 | //int IPP=; | ||
float Vout=0; | ||||
|
r2 | float Plinea=57.6;// Valor entre 1 y 500 kW, las unidades son kW | ||
float PdBm=0; | ||||
|
r1 | int VminPot=1;//con esto quiere decir que potencias | ||
|
r2 | bool serialData=0; | ||
float VoutRef=1; | ||||
|
r1 | void setup() { | ||
Serial.begin(115200); | ||||
|
r2 | // analogSetAttenuation(ADC_11db); | ||
if(serialData){ | ||||
Serial.println("Ingrese la potencia en la linea(en kW,debe ser int):"); | ||||
while (!Serial.available()); // Wait for input | ||||
String potLinChar = Serial.readStringUntil('\n'); | ||||
Plinea=atof(potLinChar.c_str()); | ||||
} | ||||
PdBm=10 *(log10(Plinea)-2); | ||||
VoutRef=ecuacionLineal(PdBm); | ||||
Serial.print("Voltaje de salida de referencia: "); | ||||
Serial.println(VoutRef); | ||||
|
r1 | } | ||
void loop() { | ||||
// put your main code here, to run repeatedly: | ||||
analogValue = analogRead(pinADC); | ||||
|
r2 | Vout = analogValue * 3.458 / 4095; | ||
if(abs(Vout-VoutRef)>0.08 && Vout>1.9 ) { | ||||
Serial.print(Vout); | ||||
} | ||||
|
r1 | |||
} | ||||
|
r2 | float ecuacionLineal(float PdBm){ | ||
float m=-0.02451,b=1.048; | ||||
return Vout=m*PdBm+b; | ||||
} | ||||