wokwi-features icon indicating copy to clipboard operation
wokwi-features copied to clipboard

The HX711 chip doesn't emit realistic raw values for the chosen load cells

Open drf5n opened this issue 1 year ago • 0 comments
trafficstars

Describe the bug The HX711 chip emits unrealistically low raw numbers, such as 2100 or 21000 for a 5kg or 50kg load cell

To Reproduce Open the example given on https://docs.wokwi.com/parts/wokwi-hx711 :

https://wokwi.com/projects/345134808605655636

#include "HX711.h"

HX711 scale;

void setup() {
  Serial.begin(9600);
  Serial.println("Initializing the scale");
  scale.begin(A1, A0);
}

void loop() {
  Serial.println(scale.get_units(), 1);
  delay(1000);
}

Adjust the chip to 50kg full-scale. See that the raw, unscaled output is 21000. Observe that 21000/(2^23-1)=0.002503395 or 0.25% of the range of +/-23bit range of the HX711 ADC. The Wokwi HX711 setup uses about 15 bits worth of the 24bit HX711 ADC.

Expected behavior

For a real 50kg load cell with a 1mv/V sensitivity a 5V excitation and the default x128 amplification, I would expect the cell output voltage/HX711 input voltage to be 5V*1mV/V=0.005V, the HX711 internal x128 amplification to make it 0.64V for its internal ADC, and the raw values to be about (2^23-1)*0.64V/(5V/2)= 2147483`, or about 100x higher than the 21000 produced by the Wokwi HX711.

Although most good load cell use does calibration which can scale part of the problem away, the smaller numbers make the simulation not representative of real-life load cells, which makes for low-resolution behavior, and poor portability of programs between actual devices and simulated devices.

Load cells, wheatstone bridges, amplification and ADCs are all difficult enough to work with without an extra confusion artificially attenuating the signal 99.9% to 0.1% of actual devices.

Additionally, for the 5kg loadcell type, a real device would also produce full-scale raw values on the same 1mV/V 5mV/5V range and produce the same 2100000 range. Wokwi's implementation is 99.99% attenuated to 0.01%, 2100 or an 11 bit resolution.

Normal load cells, whether they are 100gm, 1000gm, 1000000gm capacity or more, produce full-scale signals in the ~1mV/V range, or with the HX711's ~5V excitation, the 5mV range, and the amplification should bring that signal up to a large fraction of the ADC range.

Also, it would be nice for the examples linked to the documentation page with the hard-coded scales to be tuned to produce the expected results. For example:

https://wokwi.com/projects/344192176616374868

...should, with the current 21000 full scale output, use a scale line like:

  scale.set_scale(21000.f/50);

Environment (please complete the following information):

  • OS: Mac OSX
  • Browser Chrome
  • Version 127.0.6533.120

Additional context

Thread on discord at: https://discord.com/channels/787627282663211009/1278890584664313896/1278890584664313896

I stumbled onto this issue when I was trying to figure out how to demonstrate calculating the strain in a strain gauge using an HX711, knowing the specifications of the gauge and system, and trying to calculate the expected output.

Another way of thinking of the issue is that instead of doing the x125 amplification, this HX711 amplifies by x0.25 for its 5kg load cell, and x2.5 for its 50kg load cell.

drf5n avatar Aug 30 '24 07:08 drf5n