modelHx711

HX711 converter: 24-bit amplifier and ADC for a gauge bridge, PD_SCK/DOUT serial link

Extends from Internal.Devices.PartialSupplyPin (Supply of a peripheral: optional GND and VCC pins, internal supply rail - GND shown and ideal internal supply VOH by default).

Information

The HX711 (Avia Semiconductor) is the converter of electronic scales: a programmable-gain amplifier followed by a 24-bit analog-to-digital converter, designed to read a gauge bridge directly. This model reproduces its behaviour as seen from the microcontroller, based on the datasheet.

Bridge side

The module supplies the bridge through E+/E− (voltage AVDD) and measures the differential voltage between A+ and A−. The conversion is ratiometric: the result depends on the ratio between the bridge output and its excitation, not on the value of the supply.

code = vIn · gain / vRef · 224, rounded and clamped to [−223, 223−1] (full scale: ±AVDD/(2·gain), i.e. ±17 mV at gain 128).

Microcontroller side

  • Every 1/rate seconds, a new data is ready: DOUT goes to 0. If the previous one has not been read, DOUT first goes back up briefly (tUpdate), so that each new data is announced by a falling edge.
  • Each rising edge of PD_SCK shifts a bit out on DOUT, most significant first. After the 24 data bits, 1 to 3 extra pulses choose the gain of the next conversion: 25 pulses → 128 (channel A), 26 → 32 (channel B), 27 → 64 (channel A). DOUT then goes back to 1.
  • PD_SCK held high for more than 60 µs powers the chip down. When it returns to 0, the chip restarts as at power-up: gain 128, and first data after 4 conversions (400 ms at 10 samples/s).

The microcontroller therefore drives PD_SCK bit by bit (bit-banging). Its pin accesses must take simulated time (parameter MCU.gpioOpTime, 5 µs by default): otherwise, the pulses would have a zero duration.

Simplifications

  • Channel B (inputs B+/B−, gain 32) is not wired: it reads 0 V.
  • Each conversion is an instantaneous sample of the input (no averaging over the period), with no settling time after a gain change.
  • The noise (noiseLsb, standard deviation in LSB) is Gaussian and reproducible: the seed fixes the sequence of draws.

The icon shows the gain and the last converted code. The cyan light signals a data ready, the amber light the power-down.

Parameters

TypeNameDefaultDescription
Electrical › Supply
BooleanuseSupplyPin (from PartialSupplyPin)falseShow the VCC supply pin: the peripheral is supplied by the circuit (its high levels follow VCC, its consumption IQ is drawn from VCC) - unchecked: ideal internal supply VOH, nothing to wire
Modelica.Units.SI.VoltageVOH (from PartialSupplyPin)Interfaces.VOHLogic high voltage: ideal internal supply, high level of the outputs and of the pull-ups - with the VCC pin, the voltage of VCC is used instead
Modelica.Units.SI.CurrentIQ (from PartialSupplyPin)1e-3Current drawn from VCC by the peripheral (quiescent consumption, outputs excluded)
BooleanuseGroundPin (from PartialSupplyPin)trueShow the GND pin - unchecked: the peripheral is referenced to the simulation ground (0 V), nothing to wire
SI.VoltageVDropout0.1Dropout of the analog regulator of the module: with the VCC pin, AVDD is limited to VCC - VDropout
Conversion
Realrate10Conversion rate (RATE pin of the chip: 10 or 80 samples per second)
SI.VoltageAVDD4.3Excitation voltage of the bridge, E+ output (module supplied with 5 V) - with the VCC pin, at most VCC - VDropout
RealnoiseLsb0Conversion noise, standard deviation in LSB (0 = perfect, reproducible measurement)
Integerseed711Noise seed: same seed, same sequence of measurements
Timing
SI.TimetPowerDown60e-6PD_SCK held high longer than this: power-down
SI.TimetUpdate10e-6Time during which DOUT goes back up before each new data, when the previous one has not been read
IntegersettlingConversions4Conversions discarded after power-up or wake-up (400 ms at 10 samples/s)
Electrical › Levels
SI.VoltageVOLInterfaces.VOLLow level of DOUT
SI.VoltageVIHInterfaces.VIHThreshold above which an input reads high (PD_SCK)
SI.VoltageVILInterfaces.VILThreshold below which an input reads low (PD_SCK)
Electrical › Impedances
SI.ResistanceROutInterfaces.ROutSeries resistance of the DOUT output

Connectors

TypeNameDefaultDescription
Modelica.Electrical.Analog.Interfaces.NegativePinGND (from PartialSupplyPin)Common reference (ground), to be connected to the microcontroller's one - shown when useGroundPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinVCC (from PartialSupplyPin)Supply of the peripheral (e.g. 3V3(OUT) of a Raspberry Pi Pico) - shown when useSupplyPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinPD_SCKSerial clock and power-down control (SCK pin of the module), driven by the microcontroller
Modelica.Electrical.Analog.Interfaces.PositivePinDOUTSerial data (DT pin of the module), read by the microcontroller
Modelica.Electrical.Analog.Interfaces.PositivePinE_plusBridge excitation (+)
Modelica.Electrical.Analog.Interfaces.PositivePinA_plusDifferential input of channel A (+), from S+ of the bridge
Modelica.Electrical.Analog.Interfaces.NegativePinA_minusDifferential input of channel A (-), from S- of the bridge
Modelica.Electrical.Analog.Interfaces.NegativePinE_minusBridge excitation (-), connected to the module ground

Components

TypeNameDefaultDescription
IntegercodeLast conversion result (two's complement, 24 bits)
IntegergainGain of the current conversion (128 or 64 on channel A, 32 on channel B)
IntegerpulsesPD_SCK pulses received since the data became ready
BooleanreadyData ready, not read yet: DOUT is at 0
BooleanpoweredDownPowered down (PD_SCK held high longer than tPowerDown)
SI.VoltagevInDifferential voltage of channel A, A+ - A-
SI.VoltagevRefExcitation voltage, E+ - E-: reference of the conversion (ratiometric measurement)