Source code coming soon. The GitHub repository is private for now and opens to everyone very soon.
BetterSPICE Beta 0.8.0 Join the beta Download soon
Part VI  Parts and modelsReferenceContentsIndex
38

Devices: interface chips, switches and microcontrollers

Level translators, bus transceivers, isolators, analog switches, microcontrollers, memory and display chips. The parameter tables use the same columns as Devices: passives. Every part has labelled fields with units in the inspector and in All parameters, and the live stimulus of a sensor (light, temperature, field, strain, distance, load) is its main field, first in the list, with a slider range that fits it. A field that shows auto takes a value derived from other parameters until you type one (for example the must-operate voltage of a relay is 0.75 of its coil voltage). Clear it to go back. A variant placed from the library starts with its own typical values, such as 1 kΩ for a Pt1000 or 1.2 V dropout for an AMS1117. A part placed from the library can start with its own values, and a part made with the Part Wizard takes them from its datasheet fields (Part templates reference).

38.1Level translators

Level translators
TypePinsVariantsClass
lvlshift (U)1t45: VCCA, GND, A, B, DIR, VCCB. 2t45: 8 pins. txs2: VCCA, VCCB, OE, GND, A1, A2, B1, B2. txs8: 20 pins.1t45, 2t45 (direction pin), txs2, txs8 (automatic direction)approximate

The 1T45 and 2T45 buffer in the direction set by DIR, each side powered by its own supply. The TXS types have pull-ups on both sides and a pass transistor: whichever side is pulled low pulls the other low, which works for I²C and other open-drain buses.

Level translators
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Propagation delaytpds5 ns≥ 0Default, inspector, part file1t45, 2t45.
Pull-up resistancer_puΩ10 kΩ> 0Default, inspector, part fileTXS, each side.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

38.2RS-485, CAN and RS-232 transceivers

RS-485, CAN and RS-232 transceivers
TypePinsVariantsClass
rs485 (U)RO, nRE, DE, DI, GND, A, B, VCCnone (MAX485 class)approximate
RS-485, CAN and RS-232 transceivers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Differential outputvodV2.0> 0Default, inspector, part file
Driver output resistanceroutΩ25> 0Default, inspector, part file
Receiver hysteresisvthV0.2> 0Default, inspector, part file
Input resistancerinΩ12 kΩ> 0Default, inspector, part file
Delaytpds50 ns≥ 0Default, inspector, part file
Fail-safefailsafe0 / 10Default, inspector, part fileAn idle bus reads 1.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

RS-485, CAN and RS-232 transceivers
TypePinsVariantsClass
can (U)5v: TXD, GND, VCC, RXD, VREF, CANL, CANH, S. 3v3: D, GND, VCC, R, VREF, CANL, CANH, RS.5v (TJA1050), 3v3 (SN65HVD230)approximate
RS-485, CAN and RS-232 transceivers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Dominant differential voltagev_domV2.0> 0Default, inspector, part file
Recessive bias resistancerinΩ25 kΩ> 0Default, inspector, part file
Receiver thresholdvthV0.7> 0Default, inspector, part file
Delaytpds100 ns≥ 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

RS-485, CAN and RS-232 transceivers
TypePinsVariantsClass
rs232 (U)C1+, V+, C1-, C2+, C2-, V-, T2OUT, R2IN, R2OUT, T2IN, T1IN, R1OUT, R1IN, T1OUT, GND, VCCmax232, max3232approximate

V+ and V- come from an internal charge pump, so the pump capacitors aren’t needed in the simulation. Drivers invert and swing to about V+ - 1 V and V- + 1 V.

RS-485, CAN and RS-232 transceivers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Charge pump voltagev_pumpV0 (2 VCC - 1)> 0Default, inspector, part file
Pump output resistancerout_pumpΩ200> 0Default, inspector, part file
Receiver input resistancerinΩ5 kΩ> 0Default, inspector, part file
Receiver thresholdvthV1.3 (± 0.25)> 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

38.3Digital isolators

Digital isolators
TypePinsVariantsClass
isolator (U)2ch: VCC1, INA, INB, GND1, GND2, OUTB, OUTA, VCC2. 4ch: 13 pins with EN2. i2c: VCC1, SDA1, SCL1, GND1, GND2, SCL2, SDA2, VCC2.2ch, 4ch, i2capproximate

Side 2 follows side 1 after tpd, each side powered by its own supply, with no connection across the barrier. The I²C variant passes both lines both ways as open drain.

Digital isolators
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Delaytpds10 ns≥ 0Default, inspector, part file
Supply current per sideiccA1.5 mA≥ 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

38.4Analog switches and multiplexers

Analog switches and multiplexers
TypePinsVariantsClass
amux (U)1x8 (4051): Y0 … Y7, Z, S0 … S2, EN, VDD, VSS, VEE. 1x4, 1x16 (4067), 2x4 (4052), 3x2 (4053), spst_quad (4066), spst, spdt, dual_spdt.1x8, 1x4, 1x16, 2x4, 3x2, spst_quad, spst, spdt, dual_spdtapproximate

The select pins choose the channel joined to the common pin, with break-before-make, an on-resistance that depends on the supply and the signal, capacitances and charge injection. EN is active low unless en_high is set. The family sets the logic thresholds: use cd4000 for the CD405x and 4066.

Analog switches and multiplexers
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
On resistanceronΩ100> 0Default, inspector, part fileAt ron_vdd.
Off resistanceroffΩ1 GΩ> 0Default, inspector, part file
Supply for ronron_vddV5> 0Default, inspector, part fileron scales with (ron_vdd / supply)0.8.
Ron flatnessron_flat0.3≥ 0Default, inspector, part fileSignal dependence.
Switching timetsws100 ns> 0Default, inspector, part file
Break-before-maket_bbms10 ns≥ 0Default, inspector, part file
Channel / common capacitancecs, cdF5 pF, 25 pF≥ 0Default, inspector, part file
Charge injectionqinjC2 pCanyDefault, inspector, part file
Supply currenticcA1 µA≥ 0Default, inspector, part file
EN active highen_high0 / 10Default, inspector, part file
Normally closednc0 / 10Default, inspector, part filespst.
Logic familyfamilyhcDefault, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

38.5Microcontrollers

Microcontrollers
TypePinsVariantsClass
mcu (U)generic: the pins you declare in the code, else the pins named in pinout. atmega328p_tqfp32, attiny85_dip8, stm32f103c8_lqfp48: the package pins.generic, atmega328p_tqfp32, attiny85_dip8, stm32f103c8_lqfp48behavioural, runs your program

A microcontroller runs the program on its Code tab, in a small language made for pins: GPIO, ADC, DAC, PWM, UART, I²C, SPI and CAN. Each pin or bus you declare is added to the chip. Programming the MCU describes the language, every peripheral and the warnings. Without a program the chip only draws its supply current (10 mA by default), its pins are inputs with clamp diodes, and the generic variant has just VDD and GND. A program that contains fn name( is the old control-block script and runs with a pinmap, as in Programmable control blocks:

"pinmap": { "PA0": "ain0", "PA1": "ain1", "PB0": "out0", "PB1": "out1" }

The parameters are in Parameters. For a chip without a program, gpio sets the mode of each pin: PB0=out1 PB1=pwm:1000:0.25 PA0=in_pu.

38.6Chips and displays

Chips and displays
TypePinsVariantsClass
chip, display (U, DS)chip: generic (any pins, named from pinout), eeprom, spi_flash, rtc, i2c_dev, spi_dev, usb_uart. display: hd44780, oled_i2c, oled_spi, tft_spi, epaper.as listedevery variant works: eeprom, spi_flash, rtc, i2c_dev, spi_dev and usb_uart talk on their bus, generic is an IC box you can open as a subcircuit, and the displays decode what they are sent

Five chips answer a microcontroller: eeprom (24C02, I²C at 0x50), spi_flash (W25Q, JEDEC id, read, page program, sector erase), rtc (DS1307, I²C at 0x68, BCD time that counts simulated time), and the configurable i2c_dev and spi_dev (below). Memory, flash and RTC chips lists their commands. The displays decode what’s written to them: the HD44780 shows its text on the symbol, the SSD1306 OLED takes I²C or SPI, and the ILI9341 TFT and the e-paper take SPI. A display adds its backlight LED (vf_bl 3.1 V).

USB-UART bridge

The usb_uart variant is a CH340C-class USB-to-UART bridge (SOP-16: GND, TXD, RXD, V3, UD+, UD−, NC1, NC2, CTS, DSR, RI, DCD, DTR, RTS, R232, VCC). Its UART side is real. Its USB side is the Console: what the chip receives on RXD shows there as text, and text you type in the Console goes out on TXD. It’s how a program running on a microcontroller talks to the PC (UART).

  • TXD idles high and sends each byte as an 8N1 frame at baud, push-pull from VCC behind 50 Ω with 20 ns edges. The bit times are exact.
  • RXD has a 50 kΩ pull-up and thresholds at 0.3 and 0.4 of VCC. A start edge is found as an event and every bit is sampled in the middle. Each byte received becomes Console text: a line feed ends a line, a carriage return is dropped, a partial line is shown after 5 idle byte times or at 120 characters, and other control bytes show as \xNN.
  • Send: the send text goes out at send_at once the chip is powered, and again whenever you change it while the circuit runs (a rebuild doesn’t send it twice). Escapes: \n \r \t \\ \xNN.
  • DTR# and RTS# are outputs, high until dtr or rts is 1, which drives the pin low, as a terminal does when it opens the port. Through 100 nF, DTR resets an Arduino. CTS#, DSR#, RI# and DCD# have 50 kΩ pull-ups. With flow at 1, TXD waits while CTS# is high.
  • V3 is the internal 3.3 V regulator output when VCC is 5 V (give it a decoupling capacitor to GND). It only sources: tied to a 3.3 V VCC it carries nothing. Below 2.5 V on VCC the chip sends and receives nothing.
  • A stop bit that is low on RXD is a framing error. The sender’s baud rate differs from the chip’s, so the chip warns W_UART once. More than 4096 bytes waiting to be sent warn W_UART too, and the rest are dropped.
USB-UART bridge
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Supply currentiddA1 mA≥ 0Default, inspector, part file
Baud ratebaudbaud115200300 to 3 000 000Default, inspector, part file8N1, the same on both sides.
Text to send on TXDsendtextemptyDefault, inspector, part fileSent at send_at, and again whenever it changes.
Send start timesend_ats1 ms≥ 0File or All parameters
Console line endingeollflf, cr, crlf, noneDefault, inspector, part fileAdded to text typed in the Console input.
DTR asserteddtr0 / 10Live sliderLive toggle.
RTS assertedrts0 / 10Live sliderLive toggle.
Hardware flow controlflow0 / 10File or All parametersTXD waits while CTS# is high.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Live values: rx_bytes, tx_bytes (bytes received and sent) and tx_queued (bytes waiting). The Console input bar and the way to use it are in Console.

I²C and SPI register devices

i2c_dev (VDD, GND, SCL, SDA, INT, ADDR) and spi_dev (VDD, GND, SCK, MOSI, MISO, CS, INT) stand in for any sensor or peripheral that is a block of 8-bit registers: a temperature sensor, an accelerometer, an ADC, a port expander. You give the register map. The chip answers a microcontroller (Memory, flash and RTC chips) or any bus you drive yourself.

  • Register map: regs sets the starting values as register=value pairs, hex or decimal: 0x00=0x12 0x01=0x34. Registers not listed start at 0. ro lists read-only registers or ranges (0x00 0x10-0x13): writes to them are acknowledged and ignored. After each byte the register pointer moves to the next register, and it wraps after size registers (256 for I²C, 128 for SPI).
  • A live reading: with value_reg set, value × scale, rounded, sits in value_bytes (1 or 2) read-only registers from value_reg, most significant byte first, two’s complement when negative. Drag value while the circuit runs, as you would turn up the heat on a sensor. A TMP102 is value_reg 0 and scale 16 (0.0625 °C per count).
  • INT is open drain: it pulls low while value is at or above int_above, and stays released when int_above is empty. Give it a pull-up.
  • I²C: the chip answers at addr (7 bit, 0x48 by default), or at addr + 1 with ADDR high, and doesn’t acknowledge any other address. The first data byte of a write sets the register pointer and the next bytes are written from there. A read returns the registers from the pointer, so a program writes the pointer, then reads, as with most sensors. SDA is open drain: SDA and SCL need pull-ups (2.2 kΩ to 10 kΩ).
  • SPI: CS is active low, mode 0 by default (cpol, cpha choose modes 1 to 3). The first byte after CS falls is the command: bit 7 set reads, bit 7 clear writes, and bits 6 to 0 are the first register. Then data goes in (write) or comes out (read). MISO sends 0x00 during the command byte and is high impedance while CS is high, so several chips can share it.
  • Inputs switch at 0.3 and 0.7 of VDD. The live values show the register pointer and the contents of registers 0x00 to 0x0F and of every listed register.
I²C and SPI register devices
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
I²C addressaddr72 (0x48)0 to 127Default, inspector, part filei2c_dev. ADDR high adds 1.
Initial register valuesregstextemptyDefault, inspector, part fileregister=value pairs.
Read-only registersrotextemptyDefault, inspector, part fileNumbers or ranges.
Number of registerssize256 / 1281 to 256File or All parametersThe pointer wraps here.
Live readingvalue0anyLive sliderChanges in place while running.
Counts per unitscale1anyDefault, inspector, part file
Register of the readingvalue_regnone0 to 255Default, inspector, part fileEmpty: no reading.
Reading widthvalue_bytesbytes21 or 2Default, inspector, part file
INT low at a reading ofint_aboveneveranyDefault, inspector, part file
Clock idles highcpol0 / 10Default, inspector, part filespi_dev.
Sample on the second edgecpha0 / 10Default, inspector, part filespi_dev.
Supply currentiddA1 mA≥ 0Default, inspector, part file

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Try it
Read a temperature sensor over I²C
  1. Place a microcontroller, a chip (variant i2c_dev) with value_reg 0 and scale 16, and 4.7 kΩ pull-ups from SDA and SCL to VDD.
  2. Give the microcontroller this program: bus T i2c SDA SCL 400kHz, then a loop of send T 0x48 0, read T 0x48 2 into raw, print "counts" raw and wait 100ms.
  3. Run, then drag the chip’s Live reading from 25 to 30.

You should seeThe Console shows counts 400 (25 × 16), then 480 after you drag the reading.

Generic IC

The generic variant is an IC box with any pins, named by pinout (name:side, as the Subcircuit / IC). The library now offers one Generic IC tile in its place (the Subcircuit / IC), and a circuit saved with the older box keeps it unchanged. It draws idd from each supply pin (a pin named VCC, VDD, V3, VBAT, AVDD, DVDD, VIN or V+) to the ground pin, and every other pin is a high-impedance input with clamp diodes and a 1 GΩ leak, so the board around it simulates. pullups lists pins that get 50 kΩ to the supply. To give it a behaviour, double-click it, or right-click it and choose Edit subcircuit: it becomes a sheet in place, with one sheet pin on each pin (the wiring stays connected) and one port per pin inside, and it opens in its own ↳ tab. Draw the inside there (Editing a subcircuit).