Skip to content

Commit f5c63aa

Browse files
garethkyGareth Farrington
authored andcommitted
Add support for the ADS131M02 and ADS131M04 ADC sensors
* Support for configuring one or more channels to be summed. * Configure the sample rate and gain * Enable high perfomrance mode by default * Check for unexpected device resets and CRC data errors while sampling Signed-off-by: Gareth Farrington <gareth@waves.ky>
1 parent b2221a8 commit f5c63aa

9 files changed

Lines changed: 774 additions & 7 deletions

File tree

docs/Config_Reference.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5963,6 +5963,70 @@ data_ready_pin:
59635963
# and 'analog_supply'. Default is 'internal'.
59645964
```
59655965

5966+
#### ADS131M02
5967+
The ADS131M02 is a 24 bit, 2-channel delta-sigma ADC with simultaneous
5968+
sampling. It uses SPI communication and provides high precision measurements
5969+
suitable for load cell probing.
5970+
```
5971+
[load_cell]
5972+
sensor_type: ads131m02
5973+
cs_pin:
5974+
# The pin connected to the ADS131M02 chip select line. This parameter must
5975+
# be provided.
5976+
#spi_speed: 8192000
5977+
# SPI bus speed. The default is 8.192 MHz.
5978+
#spi_bus:
5979+
#spi_software_sclk_pin:
5980+
#spi_software_mosi_pin:
5981+
#spi_software_miso_pin:
5982+
# See the "common SPI settings" section for a description of the
5983+
# above parameters.
5984+
data_ready_pin:
5985+
# Pin connected to the ADS131M02 data ready (DRDY) line. This parameter must
5986+
# be provided.
5987+
#channels: 0
5988+
# Comma separated channel list of channels to enable and sum. Valid channels are 0 and 1.
5989+
# The default is 0.
5990+
#gain: 128
5991+
# Programmable gain amplifier setting. Valid values are 1, 2, 4, 8, 16, 32,
5992+
# 64, and 128. The default is 128.
5993+
#sample_rate: 500
5994+
# Sample rate in samples per second. Valid values are 250, 500, 1000, 2000,
5995+
# 4000, 8000, 16000, and 32000. The default is 500.
5996+
```
5997+
5998+
#### ADS131M04
5999+
The ADS131M04 is a 24 bit, 4-channel delta-sigma ADC with simultaneous
6000+
sampling. It uses SPI communication and provides high precision measurements
6001+
suitable for load cell probing. Up to 4 channels can be combined into a single
6002+
sensor ideal for under bed load cells.
6003+
```
6004+
[load_cell]
6005+
sensor_type: ads131m04
6006+
cs_pin:
6007+
# The pin connected to the ADS131M04 chip select line. This parameter must
6008+
# be provided.
6009+
#spi_speed: 8192000
6010+
# SPI bus speed. The default is 8.192 MHz.
6011+
#spi_bus:
6012+
#spi_software_sclk_pin:
6013+
#spi_software_mosi_pin:
6014+
#spi_software_miso_pin:
6015+
# See the "common SPI settings" section for a description of the
6016+
# above parameters.
6017+
data_ready_pin:
6018+
# Pin connected to the ADS131M04 data ready (DRDY) line. This parameter must
6019+
# be provided.
6020+
#channels: 0
6021+
# Comma separated channel list to enable and sum. Valid channels are: 0, 1, 2, 3. The default is channel 0.
6022+
#gain: 128
6023+
# Programmable gain amplifier setting. Valid values are 1, 2, 4, 8, 16, 32,
6024+
# 64, and 128. The same gain is applied to all channels.
6025+
#sample_rate: 500
6026+
# Sample rate in samples per second. Valid values are 250, 500, 1000, 2000,
6027+
# 4000, 8000, 16000, 32000. The default is 500.
6028+
```
6029+
59666030
### [load_cell_probe]
59676031
Load Cell Probe. This combines the functionality of a [probe] and a [load_cell].
59686032

docs/Load_Cell.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ reference_tare_counts: 12345
2525
* [`hx711`](Config_Reference.md#hx711)
2626
* [`hx717`](Config_Reference.md#hx717)
2727
* [`ads1220`](Config_Reference.md#ads1220)
28+
* [`ads131m02`](Config_Reference.md#ads131m02)
29+
* [`ads131m04`](Config_Reference.md#ads131m04)
2830

2931
- `counts_per_gram: 245`\
3032
_Default Value: None_\
@@ -332,7 +334,7 @@ Recommended sensor characteristics:
332334
- Programmable gain amplifier with 128× gain to eliminate external amplifiers
333335
- SPI reset indication to detect sensor restarts, a common indication of electrical problems
334336
- Selectable sample rate between 350 Hz and 2 kHz (rates below 250 Hz require slower probing speeds and increase toolhead force)
335-
- For under-bed applications with multiple load cells, simultaneous sampling on all channels (multiplexed ADCs have settling delays after channel switches)
337+
- For under-bed applications with multiple load cells, use an ADC with simultaneous sampling on all channels, such as the [ADS131M04](Config_Reference.md#ads131m04). Multiplexed ADCs have settling delays after channel switches and issues with time smearing of the readings which reduce accuracy.
336338

337339
Klipper's `bulk_sensor` and `load_cell_probe` infrastructure simplifies support for new sensors. Sensors can be configured from Python. with a minimal sampling loop written in C.
338340

klippy/extras/bus.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def spi_send(self, data, minclock=0, reqclock=0):
129129
[self.oid, data], minclock=minclock, reqclock=reqclock
130130
)
131131

132+
def spi_send_wait_ack(self, data, minclock=0, reqclock=0):
133+
self.spi_send_cmd.send_wait_ack(
134+
[self.oid, data], minclock=minclock, reqclock=reqclock
135+
)
136+
132137
def spi_transfer(self, data, minclock=0, reqclock=0):
133138
return self.spi_transfer_cmd.send(
134139
[self.oid, data], minclock=minclock, reqclock=reqclock

klippy/extras/load_cell/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
from klippy.configfile import ConfigWrapper
77
from klippy.printer import Printer, SubsystemComponentCollection
88

9-
from . import ads1220, hx71x
9+
from . import ads131m0x, ads1220, hx71x
1010
from .load_cell import LoadCell
1111

1212

1313
# register sensors that implement BulkAdcSensor
1414
def register_components(subsystem: SubsystemComponentCollection):
15-
sensors = hx71x.HX71X_SENSOR_TYPES | ads1220.ADS1220_SENSOR_TYPE
15+
sensors = (
16+
hx71x.HX71X_SENSOR_TYPES
17+
| ads1220.ADS1220_SENSOR_TYPE
18+
| ads131m0x.ADS131M0X_SENSOR_TYPES
19+
)
1620
for name, sensor in sensors.items():
1721
subsystem.register_component("load_cell_sensors", name, sensor)
1822

0 commit comments

Comments
 (0)