ADC
Module for interfacing with the ADS131M0x family of ADC chips.
This module provides a class for communicating with and configuring the ADS131M0x ADC chips. It supports SPI communication to reset, configure, calibrate, and read data from the ADC in units of millivolts.
ADS131M0x
¶
Bases: ADCBase
Class used for communication with the ADS131M0x family of ADC chips.
This class allows you to configure the ADS131M0x family of chips as well as read out the ADC values in units of millivolts.
Class Attributes
_MAX_CHANNELS (int): Maximum number of channels supported. _BYTES_PER_WORD (int): Number of bytes per word in SPI communication. _RESOLUTION (int): ADC resolution in bits. _SPI_MODE (int): SPI mode used for communication. _BLANK_WORD (ClassVar[list[int]]): Blank word for SPI messages. _RESET_WORD (ClassVar[list[int]]): SPI command for resetting the ADC. _STANDBY_WORD (ClassVar[list[int]]): SPI command for putting the ADC in standby. _WAKEUP_WORD (ClassVar[list[int]]): SPI command for waking up the ADC. _RREG_PREFIX (int): Prefix for read register commands. _WREG_PREFIX (int): Prefix for write register commands. _ID_REG (int): Address of the ID register. _STATUS_REG (int): Address of the status register. _MODE_REG (int): Address of the mode register. _CLOCK_REG (int): Address of the clock register. _GAIN1_REG (int): Address of the first gain register. _GAIN2_REG (int): Address of the second gain register. _CFG_REG (int): Address of the configuration register. _DISABLE_CHANNELS_CLOCK (int): Value to disable channel clocks. _ENABLE_CHANNELS_CLOCK (int): Value to enable channel clocks. _MODE_CFG (int): Mode configuration value. _OCAL_MSB_ADDRS (ClassVar[list[int]]): List of MSB addresses for offset calibration. _OCAL_LSB_ADDRS (ClassVar[list[int]]): List of LSB addresses for offset calibration. _GCAL_MSB_ADDRS (ClassVar[list[int]]): List of MSB addresses for gain calibration. _GCAL_LSB_ADDRS (ClassVar[list[int]]): List of LSB addresses for gain calibration. _CHANNEL_CFG_ADDRS (ClassVar[list[int]]): List of addresses for channel configuration. _GCAL_STEP_SIZE (float): Step size used in gain calibration.
Source code in opensourceleg/sensors/adc.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
data: Any
property
¶
Get the latest ADC data.
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The list of voltage readings (in millivolts) for each channel. |
gains: list[int]
property
¶
Get the gain settings (in logarithmic scale) for each ADC channel.
Returns:
Type | Description |
---|---|
list[int]
|
list[int]: A list of gain values for each channel. |
is_streaming: bool
property
¶
Check if the ADC is currently streaming data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if streaming; otherwise, False. |
__init__(tag='ADS131M0x', spi_bus=0, spi_chip=0, num_channels=6, max_speed_hz=8192000, channel_gains=[32, 128] * 3, voltage_reference=1.2, gain_error=None, offline=False)
¶
Initializes the ADS131M0x instance.
Validates the provided configuration and sets up internal parameters for SPI communication, channel gains, and calibration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spi_bus |
int
|
SPI bus number where the ADC is connected. Default is 0. |
0
|
spi_chip |
int
|
Chip select (CS) signal number for the ADC. Default is 0. |
0
|
num_channels |
int
|
Number of active channels on the ADC. Default is 6. |
6
|
max_speed_hz |
int
|
Maximum SPI clock speed in hertz. Default is 8192000. |
8192000
|
channel_gains |
list[int]
|
List of gains for each channel's programmable gain amplifier. Default is [32, 128] repeated 3 times (for 6 channels). |
[32, 128] * 3
|
voltage_reference |
float
|
Reference voltage used by the ADC. Default is 1.2 V. |
1.2
|
gain_error |
Optional[list[int]]
|
Optional user-calculated gain error corrections per channel. Default is an empty list. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the length of channel_gains does not equal num_channels, or if gain_error is provided and its length does not equal num_channels, or if any gain is not a power of 2 between 1 and 128. |
Source code in opensourceleg/sensors/adc.py
calibrate()
¶
Perform offset and gain calibration on the ADC.
This method performs an offset calibration (zeroing) and, if gain error corrections are provided, performs a gain calibration.
Source code in opensourceleg/sensors/adc.py
read_register(address)
¶
Read the value stored in the register at the specified address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
int
|
The address of the register to read. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The value stored at the register. |
Source code in opensourceleg/sensors/adc.py
reset()
¶
Reset all ADC register values.
Sends a reset command followed by blank words to initialize the device registers.
start()
¶
Open the SPI port, reset the ADC, configure gain settings, and begin streaming ADC data.
This method initializes the SPI communication, resets the device, sets the channel gains, transitions the device to continuous conversion mode, and clears any stale data.
Source code in opensourceleg/sensors/adc.py
stop()
¶
Stop streaming ADC data and close the SPI port.
This method transitions the ADC to standby mode and closes the SPI connection.
update()
¶
Read ADC data from the device.
Waits until the ADC channels are ready to be read and then updates the internal data with the latest voltage values in millivolts.
Source code in opensourceleg/sensors/adc.py
write_register(address, reg_val)
¶
Write a specific value to the register at the designated address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
int
|
The address of the register to write. |
required |
reg_val |
int
|
The value to be written to the register. |
required |