Add SPICE waveform plots and downloadable netlists to circuit design page
Simulated RX and TX paths via mcltspice, generated 4 SVG waveform plots (2000 data points each), and staged all 8 netlists plus the muki01 schematic as downloadable site assets. Presentation: Starlight Tabs for RX/TX waveform pairs, inline schematic image, dark mode CSS filter for white-background SVGs, and netlist inventory with download links.
This commit is contained in:
parent
ac2589623c
commit
48b61f462a
65
site/public/spice/ibus_rx_path.cir
Normal file
65
site/public/spice/ibus_rx_path.cir
Normal file
@ -0,0 +1,65 @@
|
||||
* BMW I/K-Bus Interface - RX Path (Bus to ESP32) - PC817 Optocoupler
|
||||
* Bus drives byte 0x50 (MFL addr) at 9600 baud 8E1
|
||||
* 0x50 = 01010000, LSB first = 00001010, even parity = 0
|
||||
* Frame: START(0) d0(0) d1(0) d2(0) d3(0) d4(1) d5(0) d6(1) d7(0) P(0) STOP(1)
|
||||
* Bus: 12V=idle/HIGH, 0V=active/LOW, bit time=104.17us
|
||||
* ESP32 GPIO thresholds: LOW < 0.825V, HIGH > 2.475V
|
||||
*
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
* U1 config: emitter-follower (collector to VCC, emitter to RX output)
|
||||
|
||||
* === Power Supplies ===
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
|
||||
* === Bus Model ===
|
||||
* External module driving byte 0x50 through 100R source impedance
|
||||
V_BUS V_BUS_SRC 0 PWL(
|
||||
+ 0u 12
|
||||
+ 199.5u 12
|
||||
+ 200u 0
|
||||
+ 720.33u 0
|
||||
+ 720.83u 12
|
||||
+ 824.5u 12
|
||||
+ 825u 0
|
||||
+ 928.67u 0
|
||||
+ 929.17u 12
|
||||
+ 1032.83u 12
|
||||
+ 1033.33u 0
|
||||
+ 1241.17u 0
|
||||
+ 1241.67u 12
|
||||
+ 2000u 12)
|
||||
R_BUS V_BUS_SRC IBUS 100
|
||||
C_BUS IBUS 0 100p
|
||||
|
||||
* === RX Optocoupler (U1) ===
|
||||
* Bus HIGH (12V): LED on -> phototransistor ON -> RX HIGH
|
||||
* Bus LOW (0V): LED off -> phototransistor OFF -> RX LOW (via R4)
|
||||
R1 IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=1m
|
||||
R4 RX 0 1k
|
||||
|
||||
* === PC817 Subcircuit (inlined from LTspice library) ===
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
* === Simulation ===
|
||||
.tran 0 2000u 0 0.1u
|
||||
|
||||
* === Measurements ===
|
||||
.meas tran RX_HIGH MAX V(RX)
|
||||
.meas tran RX_LOW MIN V(RX)
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran LED_CURRENT_MAX MAX I(R1)
|
||||
.meas tran RX_RISE TRIG V(RX) VAL=0.825 RISE=1 TARG V(RX) VAL=2.475 RISE=1
|
||||
.meas tran RX_FALL TRIG V(RX) VAL=2.475 FALL=1 TARG V(RX) VAL=0.825 FALL=1
|
||||
.backanno
|
||||
.end
|
||||
80
site/public/spice/ibus_tx_path.cir
Normal file
80
site/public/spice/ibus_tx_path.cir
Normal file
@ -0,0 +1,80 @@
|
||||
* BMW I/K-Bus Interface - TX Path (ESP32 to Bus) - PC817 + BC547
|
||||
* MCU TX drives Q1 (BC547B) which drives U2 (PC817) LED
|
||||
* U2 phototransistor pulls bus LOW against 4.7k pull-up to 12V
|
||||
* Test pattern: alternating 3-bit-time (312us) pulses
|
||||
* TX 0V = bus idle (HIGH), TX 3.3V = bus active (LOW via U2)
|
||||
* Includes U1 RX path for loopback observation
|
||||
* Signal inversion: TX HIGH -> bus LOW (documented in design)
|
||||
*
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
* === Power Supplies ===
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
|
||||
* === TX Test Signal ===
|
||||
* 0V=idle (U2 OFF, bus HIGH), 3.3V=active (U2 ON, bus LOW)
|
||||
* Alternating ~3 bit times (312us) to show inversion
|
||||
V_TX TX 0 PWL(
|
||||
+ 0u 0
|
||||
+ 199.5u 0
|
||||
+ 200u 3.3
|
||||
+ 512u 3.3
|
||||
+ 512.5u 0
|
||||
+ 825u 0
|
||||
+ 825.5u 3.3
|
||||
+ 1137u 3.3
|
||||
+ 1137.5u 0
|
||||
+ 2000u 0)
|
||||
|
||||
* === Bus Model ===
|
||||
* Idle pull-up: represents combined impedance of other modules' inputs
|
||||
* No active driver — only U2 phototransistor drives the bus here
|
||||
R_PULL V12 IBUS 4.7k
|
||||
C_BUS IBUS 0 100p
|
||||
|
||||
* === TX Driver: Q1 (BC547B) ===
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
|
||||
* === TX Optocoupler (U2) ===
|
||||
* LED path: VCC -> R2 -> U2 anode(1) -> U2 cathode(2) -> Q1 collector
|
||||
* Phototransistor: collector(3) = IBUS, emitter(4) = GND
|
||||
R2 VCC U2_A 220
|
||||
XU2 U2_A Q1C IBUS 0 PC817 Igain=1m
|
||||
|
||||
* === RX Optocoupler (U1) for Loopback ===
|
||||
* Shows what the MCU sees on RX when it transmits
|
||||
R1_RX IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=1m
|
||||
R4_RX RX 0 1k
|
||||
|
||||
* === PC817 Subcircuit (inlined from LTspice library) ===
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
* === Transistor Model ===
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
* === Simulation ===
|
||||
.tran 0 2000u 0 0.1u
|
||||
|
||||
* === Measurements ===
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran IBUS_SWING PP V(IBUS)
|
||||
.meas tran TX_TO_BUS_DELAY TRIG V(TX) VAL=1.65 RISE=1 TARG V(IBUS) VAL=6 FALL=1
|
||||
.meas tran U2_LED_CURRENT MAX I(R2)
|
||||
.meas tran RX_LOOPBACK_HIGH MAX V(RX)
|
||||
.meas tran RX_LOOPBACK_LOW MIN V(RX)
|
||||
.meas tran Q1_BASE_CURRENT MAX I(R3)
|
||||
.backanno
|
||||
.end
|
||||
BIN
site/public/spice/muki01-optocoupler-schematic.png
Normal file
BIN
site/public/spice/muki01-optocoupler-schematic.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
70
site/public/spice/opto_vs_kline_510.cir
Normal file
70
site/public/spice/opto_vs_kline_510.cir
Normal file
@ -0,0 +1,70 @@
|
||||
* Optocoupler (PC817) vs K-Line: Can it handle 510 ohm pull-up?
|
||||
* Tests BMW opto design against OBD-II K-line worst-case impedance
|
||||
* R2 sweep to find if any value works at 510 ohm + 10400 baud
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
.param R2val 220
|
||||
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
|
||||
* === TX Test Signal at 10400 baud (96.15us bit period) ===
|
||||
* Two pulses to show both edges
|
||||
V_TX TX 0 PWL(
|
||||
+ 0u 0
|
||||
+ 99u 0
|
||||
+ 100u 3.3
|
||||
+ 292u 3.3
|
||||
+ 292.5u 0
|
||||
+ 580u 0
|
||||
+ 580.5u 3.3
|
||||
+ 772u 3.3
|
||||
+ 772.5u 0
|
||||
+ 1500u 0)
|
||||
|
||||
* === K-Line Bus Model: 510 ohm pull-up (ISO 9141 minimum spec) ===
|
||||
R_PULL V12 KLINE 510
|
||||
C_BUS KLINE 0 100p
|
||||
|
||||
* === TX Driver: Q1 (BC547B) ===
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
|
||||
* === TX Optocoupler (U2) ===
|
||||
R2 VCC U2_A {R2val}
|
||||
XU2 U2_A Q1C KLINE 0 PC817 Igain=1m
|
||||
|
||||
* === RX Optocoupler (U1) on same K-Line wire ===
|
||||
R1_RX KLINE U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=1m
|
||||
R4_RX RX 0 1k
|
||||
|
||||
* === PC817 Subcircuit ===
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
* === BC547B Model ===
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
* === Sweep R2 to find what works at 510 ohm bus ===
|
||||
.step param R2val list 47 68 100 150 220 330 470
|
||||
|
||||
.tran 0 1500u 0 0.1u
|
||||
|
||||
* === Measurements ===
|
||||
.meas tran KLINE_HIGH MAX V(KLINE)
|
||||
.meas tran KLINE_LOW MIN V(KLINE)
|
||||
.meas tran KLINE_SWING PP V(KLINE)
|
||||
.meas tran LED_CURRENT MAX I(R2)
|
||||
.meas tran RX_HIGH MAX V(RX)
|
||||
.meas tran RX_LOW MIN V(RX)
|
||||
.backanno
|
||||
.end
|
||||
64
site/public/spice/opto_vs_kline_ctr.cir
Normal file
64
site/public/spice/opto_vs_kline_ctr.cir
Normal file
@ -0,0 +1,64 @@
|
||||
* Optocoupler vs K-Line: CTR grade sweep at 510 ohm + R2=100
|
||||
* Tests all PC817 grades with aggressive R2 at K-line impedance
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
.param CTRgain 1m
|
||||
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
|
||||
* === TX Test Signal at 10400 baud ===
|
||||
V_TX TX 0 PWL(
|
||||
+ 0u 0
|
||||
+ 99u 0
|
||||
+ 100u 3.3
|
||||
+ 292u 3.3
|
||||
+ 292.5u 0
|
||||
+ 580u 0
|
||||
+ 580.5u 3.3
|
||||
+ 772u 3.3
|
||||
+ 772.5u 0
|
||||
+ 1500u 0)
|
||||
|
||||
* === K-Line: 510 ohm pull-up ===
|
||||
R_PULL V12 KLINE 510
|
||||
C_BUS KLINE 0 100p
|
||||
|
||||
* === TX Driver ===
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
|
||||
* === TX Optocoupler (R2=100 for maximum LED current) ===
|
||||
R2 VCC U2_A 100
|
||||
XU2 U2_A Q1C KLINE 0 PC817 Igain={CTRgain}
|
||||
|
||||
* === RX Optocoupler on same K-Line ===
|
||||
R1_RX KLINE U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain={CTRgain}
|
||||
R4_RX RX 0 1k
|
||||
|
||||
* === PC817 Subcircuit ===
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
* === BC547B Model ===
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
.step param CTRgain list 0.5m 1.0m 1.5m 2.3m 3.4m
|
||||
.tran 0 1500u 0 0.1u
|
||||
|
||||
.meas tran KLINE_HIGH MAX V(KLINE)
|
||||
.meas tran KLINE_LOW MIN V(KLINE)
|
||||
.meas tran LED_CURRENT MAX I(R2)
|
||||
.meas tran RX_HIGH MAX V(RX)
|
||||
.meas tran RX_LOW MIN V(RX)
|
||||
.backanno
|
||||
.end
|
||||
24
site/public/spice/rx_path_vibus.svg
Normal file
24
site/public/spice/rx_path_vibus.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 29 KiB |
26
site/public/spice/rx_path_vrx.svg
Normal file
26
site/public/spice/rx_path_vrx.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 30 KiB |
33
site/public/spice/tx_path_vibus.svg
Normal file
33
site/public/spice/tx_path_vibus.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 57 KiB |
31
site/public/spice/tx_path_vrx_loopback.svg
Normal file
31
site/public/spice/tx_path_vrx_loopback.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 56 KiB |
38
site/public/spice/tx_sweep_ctr.cir
Normal file
38
site/public/spice/tx_sweep_ctr.cir
Normal file
@ -0,0 +1,38 @@
|
||||
* TX Path - CTR Grade Sweep (Igain) with Current R2=470 and Tough Bus
|
||||
* Shows how different PC817 grades perform with 1k bus pull-up
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
.param CTRgain 1m
|
||||
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
V_TX TX 0 PWL(0u 0 199.5u 0 200u 3.3 512u 3.3 512.5u 0 2000u 0)
|
||||
R_PULL V12 IBUS 1k
|
||||
C_BUS IBUS 0 100p
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
R2 VCC U2_A 470
|
||||
XU2 U2_A Q1C IBUS 0 PC817 Igain={CTRgain}
|
||||
R1_RX IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain={CTRgain}
|
||||
R4_RX RX 0 1k
|
||||
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
.step param CTRgain list 0.3m 0.5m 0.8m 1.0m 1.5m 2.3m 3.4m
|
||||
.tran 0 1500u 0 0.5u
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.backanno
|
||||
.end
|
||||
40
site/public/spice/tx_sweep_r2.cir
Normal file
40
site/public/spice/tx_sweep_r2.cir
Normal file
@ -0,0 +1,40 @@
|
||||
* TX Path - R2 Sweep at Worst-Case CTR (Igain=0.5m ~ PC817A min)
|
||||
* Finding optimal R2 for 3.3V ESP32 design
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
.param R2val 470
|
||||
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
V_TX TX 0 PWL(0u 0 199.5u 0 200u 3.3 512u 3.3 512.5u 0 2000u 0)
|
||||
R_PULL V12 IBUS 4.7k
|
||||
C_BUS IBUS 0 100p
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
R2 VCC U2_A {R2val}
|
||||
XU2 U2_A Q1C IBUS 0 PC817 Igain=0.5m
|
||||
R1_RX IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=0.5m
|
||||
R4_RX RX 0 1k
|
||||
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
.step param R2val list 100 150 220 270 330 390 470
|
||||
.tran 0 1500u 0 0.5u
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.meas tran LED_CURRENT MAX I(R2)
|
||||
.meas tran BUS_RISE TRIG V(IBUS) VAL=0.5 RISE=1 TARG V(IBUS) VAL=3.5 RISE=1
|
||||
.backanno
|
||||
.end
|
||||
39
site/public/spice/tx_sweep_rpull.cir
Normal file
39
site/public/spice/tx_sweep_rpull.cir
Normal file
@ -0,0 +1,39 @@
|
||||
* TX Path - Bus Impedance Sweep at Current R2=470 and Typical CTR
|
||||
* Finding where the design breaks with different bus loading
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
.param Rpull 4700
|
||||
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
V_TX TX 0 PWL(0u 0 199.5u 0 200u 3.3 512u 3.3 512.5u 0 2000u 0)
|
||||
R_PULL V12 IBUS {Rpull}
|
||||
C_BUS IBUS 0 100p
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
R2 VCC U2_A 470
|
||||
XU2 U2_A Q1C IBUS 0 PC817 Igain=1m
|
||||
R1_RX IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=1m
|
||||
R4_RX RX 0 1k
|
||||
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
.step param Rpull list 510 1000 2200 3300 4700 6800 10000
|
||||
.tran 0 1500u 0 0.5u
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.meas tran BUS_RISE TRIG V(IBUS) VAL=0.5 RISE=1 TARG V(IBUS) VAL=3.5 RISE=1
|
||||
.backanno
|
||||
.end
|
||||
82
site/public/spice/tx_validated_r2_220.cir
Normal file
82
site/public/spice/tx_validated_r2_220.cir
Normal file
@ -0,0 +1,82 @@
|
||||
* BMW I/K-Bus Interface - TX Path VALIDATED (R2=220 fix for 3.3V ESP32)
|
||||
* Tests worst realistic scenario: PC817A typical CTR + 1k bus pull-up
|
||||
* Also includes RX loopback to verify full signal path
|
||||
*
|
||||
* Fix: R2 reduced from 470 to 220 ohms
|
||||
* Effect: LED current increases from 4.66mA to ~9.3mA
|
||||
* Phototransistor base drive doubles: 9.3uA -> 18.6uA
|
||||
* Max collector current: 11.2mA -> 22.4mA
|
||||
* Supports bus pull-ups down to ~530 ohms
|
||||
*
|
||||
* PC817 pin order: 1=Anode, 2=Cathode, 3=Collector, 4=Emitter
|
||||
|
||||
* === Power Supplies ===
|
||||
V_BAT V12 0 12
|
||||
V_MCU VCC 0 3.3
|
||||
|
||||
* === TX Test Signal (byte 0x68 = RAD address) ===
|
||||
* Inverted UART: 0V=idle, 3.3V=pulling bus LOW
|
||||
* 0x68 = 01101000, LSB first = 00010110
|
||||
* 3 ones -> even parity = 1
|
||||
* Frame: START(1), 0,0,0,1,0,1,1,0, P(1), STOP(0)
|
||||
* (inverted: start=HIGH, data inverted, stop=LOW)
|
||||
V_TX TX 0 PWL(
|
||||
+ 0u 0
|
||||
+ 199.5u 0
|
||||
+ 200u 3.3
|
||||
+ 512u 3.3
|
||||
+ 512.5u 0
|
||||
+ 825u 0
|
||||
+ 825.5u 3.3
|
||||
+ 1137u 3.3
|
||||
+ 1137.5u 0
|
||||
+ 2000u 0)
|
||||
|
||||
* === Bus Model: 1k pull-up (loaded bus, worst realistic case) ===
|
||||
R_PULL V12 IBUS 1k
|
||||
C_BUS IBUS 0 100p
|
||||
|
||||
* === TX Driver: Q1 (BC547B) ===
|
||||
R5 TX R5_R3 470
|
||||
R3 R5_R3 Q1B 10k
|
||||
Q1 Q1C Q1B 0 BC547B
|
||||
|
||||
* === TX Optocoupler (U2) ===
|
||||
* FIX: R2 changed from 470 to 220 for 3.3V ESP32 compatibility
|
||||
R2 VCC U2_A 220
|
||||
XU2 U2_A Q1C IBUS 0 PC817 Igain=1m
|
||||
|
||||
* === RX Optocoupler (U1) for Loopback ===
|
||||
R1_RX IBUS U1_A 2k
|
||||
XU1 U1_A 0 VCC RX PC817 Igain=1m
|
||||
R4_RX RX 0 1k
|
||||
|
||||
* === PC817 Subcircuit ===
|
||||
.subckt PC817 1 2 3 4
|
||||
R1 N003 2 2
|
||||
D1 1 N003 LD
|
||||
G1 3 N004 N003 2 {Igain}
|
||||
C1 1 2 18p
|
||||
Q1 3 N004 4 [4] NP
|
||||
.model LD D(Is=1e-20 Cjo=18p)
|
||||
.model NP NPN(Bf=1200 Vaf=140 Ikf=100m Rc=1 Cjc=19p Cje=7p Cjs=7p C2=3e-15)
|
||||
.ends PC817
|
||||
|
||||
* === BC547B Model ===
|
||||
.model BC547B NPN(IS=2.39E-14 NF=1.008 ISE=3.545E-15 NE=1.541 BF=294.3 IKF=0.1357 VAF=63.2 NR=1.004 ISC=6.272E-14 NC=1.243 BR=7.946 IKR=0.1144 VAR=25.9 RB=1 IRB=1.00E-06 RBM=1 RE=0.4683 RC=0.85 XTB=0 EG=1.11 XTI=3 CJE=1.358E-11 VJE=0.65 MJE=0.3279 TF=4.391E-10 XTF=120 VTF=2.643 ITF=0.7495 PTF=0 CJC=3.728E-12 VJC=0.3997 MJC=0.2955 XCJC=0.6193 TR=1.00E-32 CJS=0 VJS=0.75 MJS=0.333 FC=0.9579 Vceo=45 Icrating=100m mfg=NXP)
|
||||
|
||||
* === Simulation ===
|
||||
.tran 0 2000u 0 0.1u
|
||||
|
||||
* === Measurements ===
|
||||
.meas tran IBUS_HIGH MAX V(IBUS)
|
||||
.meas tran IBUS_LOW MIN V(IBUS)
|
||||
.meas tran IBUS_SWING PP V(IBUS)
|
||||
.meas tran U2_LED_CURRENT MAX I(R2)
|
||||
.meas tran Q1_VCE_SAT MIN V(Q1C)
|
||||
.meas tran RX_LOOPBACK_HIGH MAX V(RX)
|
||||
.meas tran RX_LOOPBACK_LOW MIN V(RX)
|
||||
.meas tran BUS_RISE TRIG V(IBUS) VAL=1.0 RISE=1 TARG V(IBUS) VAL=7.0 RISE=1
|
||||
.meas tran BUS_FALL TRIG V(IBUS) VAL=7.0 FALL=1 TARG V(IBUS) VAL=1.0 FALL=1
|
||||
.backanno
|
||||
.end
|
||||
@ -3,6 +3,8 @@ title: Circuit Design
|
||||
description: "PC817 optocoupler interface — SPICE-validated circuit for BMW I/K-Bus"
|
||||
---
|
||||
|
||||
import { Tabs, TabItem } from '@astrojs/starlight/components';
|
||||
|
||||
BMW I/K-Bus interface for ESP32, galvanically isolated via PC817 optocouplers. Based on the [muki01/I-K_Bus](https://github.com/muki01/I-K_Bus) optocoupler schematic, modified for 3.3V ESP32 operation (R2: 470 to 220 ohm).
|
||||
|
||||
---
|
||||
@ -43,9 +45,9 @@ Galvanic isolation is maintained across both optocouplers. The only electrical c
|
||||
GND Q1 emitter ──> GND
|
||||
```
|
||||
|
||||
Reference images in `reference/`:
|
||||
- `muki01-optocoupler-schematic.png` -- original schematic from muki01
|
||||
- `muki01-transistor-schematic.png` -- non-isolated alternative (not used here)
|
||||
Original schematic from [muki01/I-K_Bus](https://github.com/muki01/I-K_Bus) (R2 modified from 470 to 220 ohm for 3.3V):
|
||||
|
||||
<img src="/spice/muki01-optocoupler-schematic.png" alt="muki01 optocoupler schematic showing PC817 RX/TX paths with BC547 driver" class="schematic-img" />
|
||||
|
||||
---
|
||||
|
||||
@ -75,6 +77,19 @@ Test stimulus: byte `0x50` (MFL address) at 9600 baud, 8E1 framing. Bus modeled
|
||||
|
||||
The 5.8us rise time consumes 5.6% of the 104.17us bit period at 9600 baud. Sampling at bit center (52us into the bit) sees a fully settled signal.
|
||||
|
||||
<Tabs>
|
||||
<TabItem label="V(RX) — ESP32 Side">
|
||||
<img src="/spice/rx_path_vrx.svg" alt="RX path waveform: V(RX) shows clean 0 to 3.13V digital levels for byte 0x50 at 9600 baud, with 5.8us rise time through PC817 emitter-follower" class="waveform-plot" />
|
||||
|
||||
ESP32 RX pin voltage. Bus HIGH (12V idle) maps to 3.13V, bus LOW maps to ~0V. Signal polarity preserved — no software inversion needed. The exponential rise/fall edges are the PC817 phototransistor charging/discharging through R4.
|
||||
</TabItem>
|
||||
<TabItem label="V(IBUS) — Bus Side">
|
||||
<img src="/spice/rx_path_vibus.svg" alt="RX path waveform: V(IBUS) shows 12V bus signal for byte 0x50, square wave modulated by 100 ohm source impedance" class="waveform-plot" />
|
||||
|
||||
Bus-side voltage. The stimulus is byte `0x50` (MFL steering wheel address) driven through 100 ohm source impedance. Bus swings between ~0V (active drive) and ~11.5V (bus idle, slight sag from R1 loading).
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
---
|
||||
|
||||
## TX Path (MCU to Bus via U2 + Q1)
|
||||
@ -109,6 +124,19 @@ Test conditions: 3.3V VCC, R2=220 ohm, 1k ohm bus pull-up to 12V (worst realisti
|
||||
|
||||
The 9.1us bus rise time is passive -- set by the RC time constant of the bus pull-up and parasitic capacitance. On a real BMW bus, the TH3122 transceivers in other modules provide low-impedance active drive. Actual rise times will be similar or faster.
|
||||
|
||||
<Tabs>
|
||||
<TabItem label="V(IBUS) — Bus Voltage">
|
||||
<img src="/spice/tx_path_vibus.svg" alt="TX path waveform: V(IBUS) shows bus pulled to 0.27V by optocoupler against 1k pull-up, V(TX) shows ESP32 drive signal" class="waveform-plot" />
|
||||
|
||||
V(ibus) is the bus voltage; V(tx) is the ESP32 drive signal. When TX goes HIGH, Q1 drives U2's LED, and the phototransistor pulls the bus to 0.27V. When TX goes LOW, the bus returns to 8.35V via the 1k pull-up. Note the signal inversion — TX HIGH produces bus LOW.
|
||||
</TabItem>
|
||||
<TabItem label="V(RX) — Loopback">
|
||||
<img src="/spice/tx_path_vrx_loopback.svg" alt="TX path waveform: RX loopback shows V(TX) drive signal and V(RX) received through U1, confirming full signal chain integrity" class="waveform-plot" />
|
||||
|
||||
Full signal chain verification. V(tx) is the ESP32 drive; V(rx) is the loopback received through U1. The RX loopback confirms end-to-end signal integrity. Note the RX signal is inverted relative to TX — the two optocouplers' inversions cancel out, but the bus-side common-emitter in U2 adds one inversion that the emitter-follower in U1 does not cancel.
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
---
|
||||
|
||||
## The R2 Fix: 470 ohm to 220 ohm for 3.3V ESP32
|
||||
@ -270,25 +298,18 @@ These are approximate. The SPICE model includes a phototransistor (NPN with Bf=1
|
||||
|
||||
All files in `reference/`. Simulations target 9600 baud (BMW I/K-Bus) unless noted.
|
||||
|
||||
| File | Description |
|
||||
|---|---|
|
||||
| `ibus_rx_path.cir` | RX path: bus byte 0x50 at 9600 baud through U1 (PC817) to ESP32 RX. Measures V(RX) levels, LED current, rise/fall times. 3.3V VCC, 100 ohm bus source impedance. |
|
||||
| `ibus_tx_path.cir` | TX path: ESP32 TX through Q1 (BC547B) and U2 (PC817) to bus. Alternating pulses, 4.7k bus pull-up. Includes U1 RX loopback. R2=220 ohm, Igain=1m. |
|
||||
| `tx_validated_r2_220.cir` | TX validation: R2=220 ohm fix against worst realistic loading (1k bus pull-up). Byte 0x68 at 9600 baud. Measures bus swing, rise/fall times, Q1 Vce_sat, RX loopback. The primary validation netlist for the R2 fix. |
|
||||
| `tx_sweep_r2.cir` | Parameter sweep: R2 from 100 to 470 ohm. Worst-case CTR (Igain=0.5m), 4.7k bus pull-up. Single TX pulse. Identifies R2=330 ohm as the pass/fail threshold. |
|
||||
| `tx_sweep_rpull.cir` | Parameter sweep: bus pull-up from 510 to 10k ohm. R2=470 ohm (original), typical CTR (Igain=1m). Shows failure at 510 ohm, pass at 1k and above. Demonstrates why R2=470 is insufficient for loaded buses. |
|
||||
| `tx_sweep_ctr.cir` | Parameter sweep: CTR grade (Igain 0.3m to 3.4m). R2=470 ohm, 1k bus pull-up. Shows PC817A (typical) is marginal, PC817B+ passes. Motivated the R2 reduction as an alternative to grade selection. |
|
||||
| `opto_vs_kline_510.cir` | K-line compatibility: R2 sweep (47 to 470 ohm) against 510 ohm pull-up at 10400 baud. Typical CTR. Shows R2=220 ohm is marginal, R2=100 ohm is the minimum for K-line. |
|
||||
| `opto_vs_kline_ctr.cir` | K-line compatibility: CTR grade sweep at 510 ohm pull-up, R2=100 ohm, 10400 baud. Shows worst-case PC817A fails even with aggressive R2. Confirms transistor circuit is preferred for K-line. |
|
||||
|
||||
Waveform plots (SVG, from initial simulations):
|
||||
All netlists are SPICE-compatible `.cir` files that can be opened directly in LTspice. They include inlined PC817 subcircuit models — no external library dependencies.
|
||||
|
||||
| File | Description |
|
||||
|---|---|
|
||||
| `rx_path_vibus.svg` | Bus voltage waveform during RX simulation |
|
||||
| `rx_path_vrx.svg` | ESP32 RX pin voltage during RX simulation |
|
||||
| `tx_path_vibus.svg` | Bus voltage waveform during TX simulation |
|
||||
| `tx_path_vrx_loopback.svg` | RX loopback voltage during TX simulation |
|
||||
| [`ibus_rx_path.cir`](/spice/ibus_rx_path.cir) | RX path: bus byte 0x50 at 9600 baud through U1 to ESP32 RX. 3.3V VCC, 100 ohm bus source impedance. |
|
||||
| [`ibus_tx_path.cir`](/spice/ibus_tx_path.cir) | TX path: ESP32 TX through Q1 and U2 to bus. Alternating pulses, 4.7k bus pull-up. Includes RX loopback. |
|
||||
| [`tx_validated_r2_220.cir`](/spice/tx_validated_r2_220.cir) | **Primary validation netlist.** R2=220 ohm against 1k bus pull-up. Byte 0x68 at 9600 baud. |
|
||||
| [`tx_sweep_r2.cir`](/spice/tx_sweep_r2.cir) | Sweep: R2 from 100 to 470 ohm. Worst-case CTR (Igain=0.5m), 4.7k bus. |
|
||||
| [`tx_sweep_rpull.cir`](/spice/tx_sweep_rpull.cir) | Sweep: bus pull-up from 510 to 10k ohm. R2=470 ohm (original), typical CTR. |
|
||||
| [`tx_sweep_ctr.cir`](/spice/tx_sweep_ctr.cir) | Sweep: CTR grade (Igain 0.3m to 3.4m). R2=470 ohm, 1k bus. |
|
||||
| [`opto_vs_kline_510.cir`](/spice/opto_vs_kline_510.cir) | K-line: R2 sweep at 510 ohm pull-up, 10400 baud. |
|
||||
| [`opto_vs_kline_ctr.cir`](/spice/opto_vs_kline_ctr.cir) | K-line: CTR sweep at 510 ohm, R2=100 ohm, 10400 baud. |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -28,3 +28,23 @@ table {
|
||||
th {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Waveform SVG plots */
|
||||
.waveform-plot {
|
||||
width: 100%;
|
||||
border: 1px solid var(--sl-color-gray-5);
|
||||
border-radius: 6px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
:root[data-theme='dark'] .waveform-plot {
|
||||
filter: invert(0.88) hue-rotate(180deg);
|
||||
border-color: var(--sl-color-gray-4);
|
||||
}
|
||||
|
||||
/* Reference schematic image */
|
||||
.schematic-img {
|
||||
border: 1px solid var(--sl-color-gray-5);
|
||||
border-radius: 6px;
|
||||
margin-block: 1rem;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user