toreonify's notes

Compensating vibrations during measurement

As part of a program for an AVR MCU to control and monitor an electric motor, I cobbled together a filter for a load cell weight scale.

Load cell was connected to a readily available HX711 ADC module. As soon as we looked at the values it gave we were not impressed. It jumped around from 1 to 5 kg and everything in between when load was applied.

But here is a catch - that load was not static. We've moved to an industrial module that had filter built-in to be able to gather information for an ongoing experiment. For a while it was a good option, until we've increased polling rates. It still reported values that happened almost a second ago. You can see that contrast in comparison to RPM values on a graph.

industrial-module

Also, it had an RS-485 connection with custom command set that returned weight in BCD and with separate non-fixed comma position. Urgh, that is not convenient for an 8-bit controller. For example, voltage for that motor is returned as an integer with fixed comma position, so it is easier to process.

This is what input data without a filter on HX711 looked like:

input-data

SyAn saved the day. It is a small but capable program for constructing and modeling PID controllers. I'm bad at control theory, so I experimented until I had values that looked fine.

One of the cool features is that it can export filter as a code in one of the supported languages. For some reason it had incorrectly written lines for adders and I had to fix them manually. Also, derivative term caused an overflow with float variable type. Switching to double fixed this. Maybe it's an implementation quirk of float on AVR.

filter

Filter output:

output-data

All of the captured data:

all-data

Filter applied on real MCU:

filter-on-device

Conclusion

It can be more precise with a proper calibration because I used a default calibration coefficient that seems to have an error, combined with a filter error, total deviation is about -1kg compared to similar experiments on an industrial module. Pulling on a motor with a digital scale on a hook revealed smaller deviation in readings.

I didn't make a prefectly smooth line with a filter, because reaction time is more critical than a 100-200 grams of fluctuations.

Thoughts? Leave a comment