1
- # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2
1
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
3
2
#
4
3
# SPDX-License-Identifier: MIT
@@ -202,18 +201,13 @@ class Mux(CV):
202
201
)
203
202
204
203
205
- # TODO: Verify/fix negative voltages
206
- # * check sign conversion
207
- # implement AnalogIo/ AnalogRead API
208
- # GND – 0.3 V < V(AINX) < VDD + 0.3 V
209
-
210
-
211
204
class TLA2024 : # pylint:disable=too-many-instance-attributes
212
- """I2C Interface for analog voltage measurements using the TI TLA2024 12-bit 4-channel ADC
205
+ """
206
+
207
+ I2C Interface for analog voltage measurements using the TI TLA2024 12-bit 4-channel ADC
213
208
214
- params:
215
- :param ~busio.I2C i2c_bus: The I2C bus that the ADC is on.
216
- :param int address: The I2C address for the ADC. Defaults to 0x48
209
+ :param i2c_bus: The I2C bus that the ADC is on.
210
+ :param int address: The I2C address for the ADC. Defaults to ~0x48
217
211
"""
218
212
219
213
_raw_adc_read = ROUnaryStruct (_DATA_REG , ">h" )
@@ -225,6 +219,7 @@ class TLA2024: # pylint:disable=too-many-instance-attributes
225
219
_data_rate = RWBits (3 , _CONFIG_REG , 5 , 2 , lsb_first = False )
226
220
227
221
def __init__ (self , i2c_bus , address = _TLA_DEFAULT_ADDRESS ):
222
+
228
223
# pylint:disable=no-member
229
224
230
225
self .i2c_device = I2CDevice (i2c_bus , address )
@@ -249,23 +244,24 @@ def input_channel(self):
249
244
250
245
@input_channel .setter
251
246
def input_channel (self , channel ):
252
- """The input number to measure the voltage at, referenced to GND. Options are 0, 1, 2, 3"""
247
+ """The input number to measure the voltage at, referenced to GND.
248
+
249
+ :param channel: The channel number to switch to, from 0-4"""
250
+
253
251
if channel not in range (4 ):
254
- raise AttributeError (
255
- "``input_channel`` must be set to a number from 0 to 3"
256
- )
252
+ raise AttributeError ("input_channel must be set to a number from 0 to 3" )
257
253
self ._mux = 4 + channel
258
254
259
255
@property
260
256
def mode (self ):
261
- """The measurement mode of the sensor, either Mode.ONE_SHOT or Mode.CONTINUOUS
262
- See the documentation for ``adafruit_tla202x. Mode` ` for more information"""
257
+ """The measurement mode of the sensor. Must be a :py:const:`~ Mode`. See the documentation
258
+ for :py:const:`~ Mode` for more information"""
263
259
return self ._mode
264
260
265
261
@mode .setter
266
262
def mode (self , mode ):
267
263
if not Mode .is_valid (mode ):
268
- raise AttributeError ("`` mode`` must be a valid Mode" )
264
+ raise AttributeError ("mode must be a valid Mode" )
269
265
if mode == Mode .CONTINUOUS : # pylint:disable=no-member
270
266
self ._mode = mode
271
267
return
@@ -280,7 +276,8 @@ def mode(self, mode):
280
276
@property
281
277
def range (self ):
282
278
"""The measurement range of the ADC, changed by adjusting the Programmable Gain Amplifier
283
- `range` must be an ``adafruit_tla202x.Range``"""
279
+ `range` must be a :py:const:`~Range`. See the documentation for :py:const:`~Range`
280
+ for more information"""
284
281
return self ._pga
285
282
286
283
@range .setter
@@ -291,56 +288,42 @@ def range(self, measurement_range):
291
288
292
289
@property
293
290
def data_rate (self ):
294
- """selects the rate at which measurement samples are taken. Must be an
295
- ``adafruit_tla202x. DataRate`` """
291
+ """selects the rate at which measurement samples are taken. Must be a :py:const:`~DataRate`
292
+ . See the documentation for :py:const:`~ DataRate` for more information """
296
293
return self ._data_rate
297
294
298
295
@data_rate .setter
299
296
def data_rate (self , rate ):
300
297
if not DataRate .is_valid (rate ): # pylint:disable=no-member
301
- raise AttributeError ("`` data_rate`` must be a valid DataRate" )
298
+ raise AttributeError ("data_rate must be a valid DataRate" )
302
299
self ._data_rate = rate
303
300
304
301
@property
305
302
def mux (self ):
306
- """selects the inputs that voltage will be measured between. Must be an
307
- `` adafruit_tla202x.Mux`` . See the `` adafruit_tla202x.Mux`` documentation for more
308
- information about the available options"""
303
+ """selects the inputs that voltage will be measured between. Must be a
304
+ :py:const:`~ adafruit_tla202x.Mux`. See the :py:const:`~ adafruit_tla202x.Mux` documentation
305
+ for more information about the available options"""
309
306
return self ._mux
310
307
311
308
@mux .setter
312
309
def mux (self , mux_connection ):
313
- print ("muxin'" )
314
310
if not Mux .is_valid (mux_connection ): # pylint:disable=no-member
315
- raise AttributeError ("`` mux`` must be a valid Mux" )
311
+ raise AttributeError ("mux must be a valid Mux" )
316
312
self ._mux = mux_connection
317
313
318
314
def read (self , channel ):
319
- """Switch to the given channel and take a single ADC reading in One Shot mode"""
315
+ """Switch to the given channel and take a single ADC reading in One Shot mode
316
+
317
+ :param channel: The channel number to switch to, from 0-3
318
+
319
+ """
320
320
if not self .input_channel == channel :
321
321
self .input_channel = channel
322
322
self .mode = Mode .ONE_SHOT # pylint:disable=no-member
323
323
return self ._read_adc ()
324
324
325
325
def _read_volts (self ):
326
- """From datasheet:
327
- ≥ +FS (2^11 – 1) / 2^11 ==> 0x7FF0
328
- +FS /2^11 ==> 0x0010
329
- 0 ==> 0x0000
330
- -FS /2^11 ==> 0xFFF0
331
- ≤ –FS ==> 0x8000
332
-
333
- """
334
-
335
326
value_lsb = self ._read_adc ()
336
- # print("value_lsb:", hex(value_lsb))
337
- # v_fsr = 8192 >> self.range
338
- # if self.range == 0:
339
- # v_fsr = 6144
340
- # v_fsr = float(v_fsr)
341
- # converted = (value_lsb / 2047.0) * v_fsr
342
-
343
- # return converted / 1000.0
344
327
return value_lsb * Range .lsb [self .range ] / 1000.0
345
328
346
329
def _read_adc (self ):
0 commit comments