Skip to content

Commit 205146d

Browse files
committed
Comment conversion result read logic
1 parent 1f94daf commit 205146d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

adafruit_ads1x15/ads1x15.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ def _conversion_value(self, raw_adc):
157157

158158
def _read(self, pin):
159159
"""Perform an ADC read. Returns the signed integer result of the read."""
160+
# Immediately return conversion register result if in CONTINUOUS mode and pin has not changed
160161
if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin:
161162
return self._conversion_value(self.get_last_result(True))
163+
164+
# Assign last pin read if in SINGLE mode or first sample in CONTINUOUS mode on this pin
162165
self._last_pin_read = pin
166+
167+
# Configure ADC every time before a conversion in SINGLE mode or changing channels in CONTINUOUS mode
163168
if self.mode == Mode.SINGLE:
164169
config = _ADS1X15_CONFIG_OS_SINGLE
165170
else:
@@ -171,12 +176,15 @@ def _read(self, pin):
171176
config |= _ADS1X15_CONFIG_COMP_QUE_DISABLE
172177
self._write_register(_ADS1X15_POINTER_CONFIG, config)
173178

179+
# Wait for conversion to complete
180+
# ADS1x1x devices settle within a single conversion cycle
174181
if self.mode == Mode.SINGLE:
175-
# poll conversion complete status bit
182+
# Continuously poll conversion complete status bit
176183
while not self._conversion_complete():
177184
pass
178185
else:
179-
# just sleep (can't poll in continuous)
186+
# Can't poll registers in CONTINUOUS mode
187+
# Wait expected time for two conversions to complete
180188
time.sleep(2 / self.data_rate)
181189

182190
return self._conversion_value(self.get_last_result(False))

0 commit comments

Comments
 (0)