Skip to content

Commit

Permalink
ads1x1x: fix voltage default value, rename continous to continuous an…
Browse files Browse the repository at this point in the history
…d try to be more accurate on the sample timing

Signed-off-by: Konstantin Koch <korsarnek@gmail.com>
  • Loading branch information
korsarNek committed Aug 25, 2024
1 parent 98513bd commit 5f3c060
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4649,7 +4649,7 @@ chip: ADS1115
#mode: single
# Default value is single. Turn off the chip after a single reading or keep
# it running. Turning off saves power but turning it back on will be slower.
# Options are single and continous.
# Options are single and continuous.
#samples_per_second: 128
# Default value is 128. The amount of samples that the ADC can provide per
# second. A lower value makes the samples more accurate, but it takes longer
Expand Down
13 changes: 3 additions & 10 deletions klippy/extras/ads1x1x.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def isADS111X(chip):
0x0A00: 0.256 / 2047.0 # +/-0.256V range = Gain 16
}
ADS1X1X_MODE = {
'continous': 0x0000, # Continuous conversion mode
'continuous': 0x0000, # Continuous conversion mode
'single': 0x0100 # Power-down single-shot mode
}

Expand All @@ -130,9 +130,6 @@ def isADS111X(chip):
'860': 0x00e0 # 860 samples per second
}

ADS101X_CONVERSION_DELAY = 0.002
ADS111X_CONVERSION_DELAY = 0.008

ADS1X1X_COMPARATOR_MODE = {
'TRADITIONAL': 0x0000, # Traditional comparator with hysteresis
'WINDOW': 0x0010 # Window comparator
Expand Down Expand Up @@ -188,7 +185,7 @@ def __init__(self, config):
self._ppins = self._printer.lookup_object("pins")
self._ppins.register_chip(self.name, self)

self.pga = config.getchoice('pga', ADS1X1X_PGA, 'V4.096')
self.pga = config.getchoice('pga', ADS1X1X_PGA, '4.096V')
self.mode = config.getchoice('mode', ADS1X1X_MODE, 'single')
# Comparators are not implemented, they would only be useful if the
# alert pin is used, which we haven't made configurable.
Expand Down Expand Up @@ -238,11 +235,7 @@ def sample(self, sensor):
try:
self._write_register(ADS1X1X_REG_POINTER['CONFIG'],
pin_object.config)
delay = 0
if isADS101X(self.chip):
delay = ADS101X_CONVERSION_DELAY
else:
delay = ADS111X_CONVERSION_DELAY
delay = 1 / (self.samples_per_second_numeric - 1)
while not self.is_ready():
self._reactor.pause(self._reactor.monotonic() + delay)
sample = self._read_register(ADS1X1X_REG_POINTER['CONVERSION'])
Expand Down

0 comments on commit 5f3c060

Please sign in to comment.