@@ -157,9 +157,14 @@ def _conversion_value(self, raw_adc):
157
157
158
158
def _read (self , pin ):
159
159
"""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
160
161
if self .mode == Mode .CONTINUOUS and self ._last_pin_read == pin :
161
162
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
162
165
self ._last_pin_read = pin
166
+
167
+ # Configure ADC every time before a conversion in SINGLE mode or changing channels in CONTINUOUS mode
163
168
if self .mode == Mode .SINGLE :
164
169
config = _ADS1X15_CONFIG_OS_SINGLE
165
170
else :
@@ -171,12 +176,15 @@ def _read(self, pin):
171
176
config |= _ADS1X15_CONFIG_COMP_QUE_DISABLE
172
177
self ._write_register (_ADS1X15_POINTER_CONFIG , config )
173
178
179
+ # Wait for conversion to complete
180
+ # ADS1x1x devices settle within a single conversion cycle
174
181
if self .mode == Mode .SINGLE :
175
- # poll conversion complete status bit
182
+ # Continuously poll conversion complete status bit
176
183
while not self ._conversion_complete ():
177
184
pass
178
185
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
180
188
time .sleep (2 / self .data_rate )
181
189
182
190
return self ._conversion_value (self .get_last_result (False ))
0 commit comments