diff --git a/ADC_ZX47/ADC_ZX47.ino b/ADC_ZX47/ADC_ZX47.ino index d8cafb9..c4f0f74 100644 --- a/ADC_ZX47/ADC_ZX47.ino +++ b/ADC_ZX47/ADC_ZX47.ino @@ -1,19 +1,20 @@ #include -#define pinADC 12 +#define pinADC 26 int analogValue=0; -float Vref=2.45;// Voltaje de referencia para el ADC -//int IPP=; +float Vref=3100;// Voltaje de referencia para el ADC float Vout=0; -float Plinea=57.6;// Valor entre 1 y 500 kW, las unidades son kW -float PdBm=0; -int VminPot=1;//con esto quiere decir que potencias -bool serialData=0; +float Plinea=57.6,PdBm=0;;// Valor entre 1 y 500 kW, las unidades son kW +int VminPot=1;//con esto quiere decir que potencia es la máxima +bool serialData=0;//Un valor de 1 indica que se debe ingresar por monitor float VoutRef=1; +int numSamples=20; +int total=0; void setup() { Serial.begin(115200); - // analogSetAttenuation(ADC_11db); + + analogSetAttenuation(ADC_11db); if(serialData){ - Serial.println("Ingrese la potencia en la linea(en kW,debe ser int):"); + Serial.println("Ingrese la potencia en la linea:"); while (!Serial.available()); // Wait for input String potLinChar = Serial.readStringUntil('\n'); Plinea=atof(potLinChar.c_str()); @@ -22,16 +23,19 @@ void setup() { VoutRef=ecuacionLineal(PdBm); Serial.print("Voltaje de salida de referencia: "); Serial.println(VoutRef); + } void loop() { - // put your main code here, to run repeatedly: - analogValue = analogRead(pinADC); - Vout = analogValue * 3.458 / 4095; - if(abs(Vout-VoutRef)>0.08 && Vout>1.9 ) { - Serial.print(Vout); + total=0; + //analogValue = analogRead(pinADC); + for (int i = 0; i < numSamples; i++) { + total += analogRead(pinADC); + delay(1); } - + int averageValue = total / numSamples; + Vout = 0.8291*averageValue+90.27;//Ajuste realizado para el ADC + Serial.print(Vout); } float ecuacionLineal(float PdBm){ float m=-0.02451,b=1.048;