MCLP: 8-channel load-cell weighing core on Zynq-7000
An FPGA IP core that reads up to 64 AD7190 load-cell converters in lockstep, corrects and sums them in hardware, corrects weigh-in-motion results with an int8 neural network, and hands the weight to Linux over REST and MQTT.
- 8channels on the ZC702 reference design
- 4800samples/s per channel
- R = 8CIC, then a 64-tap FIR
- 0.89 msint8 inference per load
- 50 Hzresults, up to 600 Hz
- +0.737 nsWNS, all constraints met
Architecture · block diagram
- Main data path
- Logic
- Processor
- Memory
- Interconnect
- Off-chip
The story
Most electronic scales pair a dedicated weigh-scale ADC with a small microcontroller. That works for one load cell on a bench. A truck scale or a weigh-in-motion lane has several load cells, and each cell has its own error. It needs a weight while the load is still moving. It also needs diagnostics, logs and a network connection.
I designed MCLP for that case. It is an IP core for AMD FPGAs that reads 1 to 64 AD7190 converters, one per load cell, and computes the weight in the programmable logic. Around the core are a reference design for the ZC702 board, an 8-channel FMC card in KiCad and PetaLinux software. The blog series describes the signal chain, the card and the tests of the software against the RTL.
Challenges
The core must sample all channels at the same instant. Then it can correct the error of each corner before it sums the channels. Load-cell signals are a few millivolts, so the resolution comes from 24-bit sigma-delta converters, followed by decimation and filtering. I also had to verify the design, software included, before any board existed. Legal-for-trade certification is outside the scope. It belongs to the finished product and its type-approval tests.
What I built
The eight converters share one clock and one SYNC line, so they convert in lockstep. The SPI master reads all of them in parallel, with one receive lane per converter. A sequencer that runs command lists from RAM drives the SPI master. A TDM mux and a CDC FIFO feed one time-shared processing chain at 50 MHz.
The chain decimates each channel by 8 in a CIC filter with no multipliers. It applies a per-channel gain and offset and a corner trim in Q2.30. Then it sums the channels exactly in 40 bits. A 64-tap FIR with reloadable coefficients filters the sum. The weight goes out at 50 Hz, with a stability flag and a weigh-in-motion estimate from the same stream.
For calibration and diagnosis, a raw-capture block taps the chain at four points. It streams timestamped records through an AXI DMA into a ring in DDR. A loopback BIST replaces the converters with an emulator in the PL. Command lists run the checks of the AD7190 itself for open wires and missing excitation.
Version 2.0 adds an inference engine. After each weigh-in-motion load, the engine runs a small int8 neural network on the last 1.7 s of the weight. It writes a corrected estimate to its own registers, and the legal weight path stays the same. The engine does one DSP48 multiply-accumulate per clock and takes 0.89 ms for the default model. Software can replace the model over AXI4-Lite.
I had no hardware and no field data, so I trained the model on a simulator of vehicles that cross the platform. The simulator also measured the old weigh-in-motion rule. That measurement led to a new rule before any model work.
On the Arm side, a PetaLinux layer binds the core and the DMA to UIO. The mclp console handles start-up, calibration and the self-tests. mclpd serves the weight over REST on HTTPS and over MQTT on TLS.
The hardest problem
The software had to run against the hardware before the hardware existed. I put every hardware access in the C code behind one struct. Then I wrote a backend that sends register reads and writes over TCP to a cocotb testbench, which runs the RTL in Icarus Verilog. The backend uses simulated time and a model of the DMA. Later, the same console and service ran inside QEMU on the real PetaLinux image and drove the same RTL. This setup found bugs in the RTL reset values, the UIO binding, the system clock and the MQTT reconnect logic. I fixed all of them before any hardware existed.
I also replaced AMD's CIC and FIR cores with my own RTL, so that I could package the core as one IP. The FIR matches AMD's bit-accurate C model on all 1393 test outputs. A side-by-side run of my CIC and AMD's core found a decimation-phase difference that every earlier test missed.
Result
The core passes its system test at 1, 8 and 64 channels, bit for bit from ADC code to result. The inference engine matches its integer reference. On simulated crossings, the new weigh-in-motion rule brought the 95th-percentile error at 2 km/h from 17.63% to 0.31%. The model lowers the error further at 5 to 20 km/h, for example from 4.36% to 2.75% at 10 km/h.
The reference design meets all timing constraints on the -1 speed grade, with +0.737 ns of setup slack, and uses 9783 LUTs. The console and the network service ran against the RTL from the PC and from QEMU. The ADC card is routed with no ERC or DRC errors. The hardware is not built yet. The next steps are the converter model, the measured resolution and the open items of the card.
Where you'd find something like this
Truck and axle scales
Weigh-in-motion lanes
Platform scales and checkweighers
Silo and tank weighing