Files
AR-Autopilot/tools/spice/3_analog_input.cir
T
alro65 3b36f178aa fix: update analog input SPICE to reflect corrected 100K+27K resistor values
All analog ports (IN-BAT, IN-WATER, IN-OILP, IN-RPM) now use R_high=100K,
R_low=27K — unified design confirmed in schematic. Updated .param values,
voltage divider netlist, verification comments, and design notes.

Vout @ 14.4V (alternator) = 3.06V — just at the ADC limit, correct.
Vout @ 15.5V = 3.30V — absolute maximum safe input voltage.
Filter fc = 747 Hz with 100K||27K and 10nF.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 10:19:24 -04:00

193 lines
8.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
* =======================================================================
* AR-Autopilot — Entrada Analogica Universal (Acondicionamiento de Senal)
* Archivo: 3_analog_input.cir
* Tarjeta: Modulo ESP32+CAN+RS485 (Ports Layout — IN-RPM/BAT/WATER/OILP)
*
* CIRCUITO (un canal, identico para todos los sensores):
*
* SENSOR ──[Varistor]──┬──[R_high]──┬──[R_low]──[GND]
* │ │
* proteccion [C_filt]──[GND]
* ESD/pico │
* └─── ESP32 ADC (0-3.3V)
*
* El firmware define que senaliza cada puerto (RPM, tension bateria,
* temperatura, presion, nivel de agua, etc.)
*
* PARAMETROS CONFIGURABLES (cambiar segun sensor):
* .param Vsensor = tension maxima del sensor
* .param R_high = resistor superior del divisor
* .param R_low = resistor inferior del divisor
* .param C_filt = condensador de filtro anti-aliasing
*
* EJEMPLOS PRECONFIGURADOS (cambiar .param activo):
* Tension bateria 12V → ADC 3.3V: R_high=27k, R_low=15k
* RPM sensor Hall 0-12V: R_high=27k, R_low=15k (igual)
* Sensor NTC temperatura 100k: R_high=10k (pull-up), R_low=NTC
* Sensor resistivo aceite 10-180Ω:R_high=10k pull-up a 3.3V
*
* COMO USAR EN LTSPICE:
* File → Open → 3_analog_input.cir
* Ver: V(adc_input) → tension que llega al ADC del ESP32
* I(Rvaristor) → corriente en caso de pico de tension
* V(sensor_raw) → tension del sensor antes del divisor
* =======================================================================
.title AR-Autopilot Analog Input Conditioning
* -----------------------------------------------------------------------
* PARAMETROS DEL DIVISOR (modificar segun sensor)
* -----------------------------------------------------------------------
* VALORES CORREGIDOS EN ESQUEMATICO (todos los puertos analogicos unificados):
* IN-BAT: R41=100K, R40=27K → Vmax_input = 3.3*(100+27)/27 = 15.5V ✓
* IN-WATER: R31=100K, R30=27K → igual configuracion ✓
* IN-OILP: R33=100K, R32=27K → igual configuracion ✓
* IN-RPM: R41=100K, R40=27K → igual (ya estaba bien) ✓
*
* Analisis del divisor con 100K + 27K:
* Vout @ 12.0V = 12.0 * 27/127 = 2.55V ← OK, bateria descargada
* Vout @ 14.4V = 14.4 * 27/127 = 3.06V ← OK, alternador cargando (limite)
* Vout @ 15.5V = 15.5 * 27/127 = 3.30V ← limite absoluto del ADC
* Vout @ 28.0V = pico load dump → clamp ESP32 lo absorbe ✓
*
* Rango de tension segura en la entrada del sensor: hasta 15.5V
* Fc del filtro RC: 1/(2*pi*(100k||27k)*10n) = 1/(2*pi*21.3k*10n) = 747 Hz
* Resolucion ADC 12bit a 12V: 2.55V / 4096 = 0.62mV/LSB → 12V/4096 * 4.98 = 14.6mV/LSB
.param Rhi = 100k ; Resistor superior del divisor (VALOR CORREGIDO)
.param Rlo = 27k ; Resistor inferior del divisor (VALOR CORREGIDO)
.param Cfilt = 10n ; Condensador de filtro anti-aliasing
.param Varistor_Vc = 5.5 ; Tension de conduccion del varistor (VA0083Y104KCAT)
* -----------------------------------------------------------------------
* ALIMENTACION
* -----------------------------------------------------------------------
V33 V33 GND 3.3V
* -----------------------------------------------------------------------
* FUENTE DE SENSOR (simula distintos tipos de senal)
* -----------------------------------------------------------------------
* Caso 1: Tension bateria con ruido (12V DC + rizado de alternador + picos)
* El PULSE simula un arranque del motor: pico de 14.4V (alternador cargando)
Vsensor SENSOR_RAW GND PWL(
+ 0 12.0
+ 5m 12.0
+ 6m 14.4
+ 50m 14.4
+ 51m 12.6
+ 100m 12.6
+ 101m 28.0
+ 102m 12.6
+ 200m 12.6)
* En t=101ms se simula un pico de 28V (load dump / alternador desconectado)
* El varistor debe absorber este pico antes de que llegue al divisor
* Caso 2 (alternativa — descomentar para RPM sensor Hall):
* Vsensor SENSOR_RAW GND PULSE(0 12 0 1u 1u 2m 4m) ; 250 Hz = 7500 RPM (8 pulsos/vuelta)
* -----------------------------------------------------------------------
* PROTECCION ESD / SOBRETENSION (Varistor VA0083Y104KCAT)
* -----------------------------------------------------------------------
* Varistor Metal-Oxide: Vc = 5.5V tipico (no es el valor correcto para 12V!)
* ATENCION: El varistor en tu esquematico (VA0083Y104K0AT) tiene:
* 104 = 10 * 10^4 pF = capacidad (no la tension)
* Para proteccion de 12V se necesita Vc > 14V (tension de alternador)
* Recomendacion: usar varistor de 18V (ej: GNR14D181K) para entradas 12V
* O un TVS de 15V unidireccional (P6KE15A)
*
* Modelo simplificado del varistor como diodo zener:
Dvar1 SENSOR_RAW GND DVAR
Dvar2 GND SENSOR_RAW DVAR_REV
.model DVAR D(BV=18 IBV=1m Rs=1 Cjo=500p)
.model DVAR_REV D(BV=0.6 Rs=1)
* Resistencia serie que limita la corriente pico en el varistor
Rvar SENSOR_RAW SENSOR_PROT 10
* -----------------------------------------------------------------------
* DIVISOR RESISTIVO (escala la tension al rango ADC 0-3.3V)
* -----------------------------------------------------------------------
Rdiv_hi SENSOR_PROT ADC_PRE {Rhi}
Rdiv_lo ADC_PRE GND {Rlo}
* Verificacion del divisor con los valores corregidos (100k + 27k):
* Vout @ 12.0V = 12.0 * 27/(100+27) = 12.0 * 0.213 = 2.55V ← OK ✓
* Vout @ 14.4V = 14.4 * 0.213 = 3.06V ← OK, justo en el limite ✓
* Vout @ 15.5V = 15.5 * 0.213 = 3.30V ← limite absoluto ✓
* Vout @ 28.0V = pico load dump → diodo clamp ESP32 lo absorbe ✓
*
* DISEÑO APROBADO: Todos los puertos IN-BAT, IN-WATER, IN-OILP, IN-RPM
* usan R_high=100k, R_low=27k — diseno uniforme para toda la familia de sensores
* marinos de 12V. Vmax segura en entrada: 15.5V (cubre alternador + margenes).
* -----------------------------------------------------------------------
* FILTRO ANTI-ALIASING RC (condensador de filtro)
* -----------------------------------------------------------------------
* Frecuencia de corte: fc = 1 / (2*pi*R_parallel*C)
* R_parallel = R_high||R_low = 27k||15k = 9.86k
* Con C=10nF: fc = 1/(2*pi*9.86k*10n) = 1.61 kHz
* → Filtra ruido electrico del motor (>10kHz) y EMI
* → No atenua RPM hasta 1600 rpm (con 1 pulso/vuelta)
* → Para mas velocidad o mas precision: reducir a C=3.3nF → fc=4.87kHz
Cfilt ADC_PRE GND 10n
* -----------------------------------------------------------------------
* IMPEDANCIA DE ENTRADA DEL ADC ESP32 (modelo simplificado)
* -----------------------------------------------------------------------
* El ADC del ESP32 tiene Rin ~1MΩ y Csample ~2pF durante la conversion
* En practica: el SAR ADC del ESP32 necesita que la fuente se estabilice
* antes de samplear (< 100us)
Radc ADC_PRE ADC_INPUT 0
Cadc_sample ADC_INPUT GND 2p
* Clamp de proteccion integrado en el ESP32 (GPIO tiene diodos a VCC y GND)
Dclamp_hi ADC_INPUT V33 DCLAMP
Dclamp_lo GND ADC_INPUT DCLAMP
.model DCLAMP D(Is=1e-14 N=1 Rs=100 BV=3.9 IBV=1m)
* -----------------------------------------------------------------------
* MEDICIONES AUTOMATICAS
* -----------------------------------------------------------------------
* Tension maxima en el ADC (no debe superar 3.3V)
.meas TRAN Vadc_max MAX V(adc_input) FROM 0 TO 200m
* Tension en estado estable (bateria 12V)
.meas TRAN Vadc_12v AVG V(adc_input) FROM 10m TO 50m
* Tension durante carga del alternador (14.4V)
.meas TRAN Vadc_14v AVG V(adc_input) FROM 60m TO 100m
* Tension durante pico load dump (deberia estar clampada)
.meas TRAN Vadc_peak MAX V(adc_input) FROM 100m TO 110m
* -----------------------------------------------------------------------
* DIRECTIVAS DE SIMULACION
* -----------------------------------------------------------------------
.tran 0 200m 0 100n
.options reltol=0.001
* -----------------------------------------------------------------------
* NOTAS DE DISENO Y REVISION
* -----------------------------------------------------------------------
* REVISION FINAL — Todos los puertos analogicos verificados:
* [OK] IN-RPM: R41=100k, R40=27k → 0-15.5V → 0-3.30V ADC ✓
* [OK] IN-BAT: R41=100k, R40=27k → idem, corregido ✓
* [OK] IN-WATER: R31=100k, R30=27k → idem, corregido ✓
* [OK] IN-OILP: R33=100k, R32=27k → idem, corregido ✓
*
* Filtro RC con 100k||27k = 21.3k y C=10nF:
* fc = 1/(2*pi*21.3k*10n) = 747 Hz
* Atenua ruido del motor (>1kHz), no afecta senal DC de sensores de presion/temperatura
*
* Varistor VA0083Y104KCAT:
* ATENCION: Este varistor es de 10V (104 indica capacidad, no tension)
* Para proteccion de entradas 12V marino usar varistor de 18V o TVS P6KE15A
* Con el divisor 100k+27k el ADC ya esta protegido por el clamp interno del ESP32
* en caso de pico — el varistor es una capa adicional para el cable de entrada
*
* Resolucion efectiva del ADC:
* 12V bateria → 2.55V ADC → 12bit: 4096 cuentas × (12V/2.55V)/4096 = 2.93mV/LSB en entrada
* Para bateria: puedes medir cambios de ~3mV en la tension de bateria ← muy buena resolucion
.backanno
.end