-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement single-shot measurements (#6)
- Loading branch information
Showing
17 changed files
with
1,129 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
ADS111x - Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs | ||
With Internal Reference, Oscillator, and Programmable Comparator | ||
datasheet: https://www.ti.com/lit/ds/symlink/ads1115.pdf | ||
""" | ||
|
||
import logging | ||
|
||
from attrs import define | ||
|
||
from feeph.ads1xxx.ads111x import Ads111x, Ads111xConfig | ||
from feeph.ads1xxx.settings import CLAT, CMOD, CPOL, CQUE, DOM, DRS, MUX, PGA, SSC | ||
|
||
LH = logging.getLogger('feeph.ads1xxx') | ||
|
||
|
||
@define | ||
class Ads1113Config(Ads111xConfig): | ||
""" | ||
The 16-bit Config register is used to control the operating mode, input | ||
selection, data rate, full-scale range, and comparator modes. | ||
""" | ||
# fmt: off | ||
ssc: SSC = SSC.NO_OP # single-shot conversion trigger | ||
dom: DOM = DOM.SSM # device operation mode | ||
drs: DRS = DRS.MODE4 # data rate setting | ||
# fmt: on | ||
|
||
def as_uint16(self): | ||
# non-configurable values are set to their default | ||
value = 0b0000_0000_0000_0000 | ||
value |= self.ssc.value | ||
value |= MUX.MODE0.value # no input multiplexer | ||
value |= PGA.MODE2.value # no programmable gain amplifier | ||
value |= self.dom.value | ||
value |= self.drs.value | ||
value |= CMOD.TRD.value # no comparator mode | ||
value |= CPOL.ALO.value # no comparator polarity | ||
value |= CLAT.NLC.value # no comparator latch | ||
value |= CQUE.DIS.value # no comparator queue | ||
return value | ||
|
||
|
||
class Ads1113(Ads111x): | ||
""" | ||
ADS1113 - Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs | ||
With Internal Reference, Oscillator, and Programmable Comparator | ||
datasheet: https://www.ti.com/lit/ds/symlink/ads1113.pdf | ||
""" | ||
_has_pga = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
ADS111x - Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs | ||
With Internal Reference, Oscillator, and Programmable Comparator | ||
datasheet: https://www.ti.com/lit/ds/symlink/ads1115.pdf | ||
""" | ||
|
||
import logging | ||
|
||
from attrs import define | ||
|
||
from feeph.ads1xxx.ads111x import Ads111x, Ads111xConfig | ||
from feeph.ads1xxx.settings import CLAT, CMOD, CPOL, CQUE, DOM, DRS, MUX, PGA, SSC | ||
|
||
LH = logging.getLogger('feeph.ads1xxx') | ||
|
||
|
||
@define | ||
class Ads1114Config(Ads111xConfig): | ||
""" | ||
The 16-bit Config register is used to control the operating mode, input | ||
selection, data rate, full-scale range, and comparator modes. | ||
""" | ||
# fmt: off | ||
ssc: SSC = SSC.NO_OP # single-shot conversion trigger | ||
pga: PGA = PGA.MODE2 # programmable gain amplifier | ||
dom: DOM = DOM.SSM # device operation mode | ||
drs: DRS = DRS.MODE4 # data rate setting | ||
cmod: CMOD = CMOD.TRD # comparator mode | ||
cpol: CPOL = CPOL.ALO # comparator polarity | ||
clat: CLAT = CLAT.NLC # comparator latch | ||
cque: CQUE = CQUE.DIS # comparator queue | ||
# fmt: on | ||
|
||
def as_uint16(self): | ||
value = 0b0000_0000_0000_0000 | ||
value |= self.ssc.value | ||
value |= MUX.MODE0.value # no input multiplexer | ||
value |= self.pga.value | ||
value |= self.dom.value | ||
value |= self.drs.value | ||
value |= self.cmod.value | ||
value |= self.cpol.value | ||
value |= self.clat.value | ||
value |= self.cque.value | ||
return value | ||
|
||
|
||
class Ads1114(Ads111x): | ||
""" | ||
ADS1113 - Ultra-Small, Low-Power, I2C-Compatible, 860-SPS, 16-Bit ADCs | ||
With Internal Reference, Oscillator, and Programmable Comparator | ||
datasheet: https://www.ti.com/lit/ds/symlink/ads1114.pdf | ||
""" | ||
_has_pga = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from enum import Enum | ||
|
||
from feeph.ads1xxx.settings import PGA | ||
|
||
|
||
class UNIT(Enum): | ||
STEPS = 0 | ||
MICRO = 1 | ||
|
||
|
||
def convert_step_to_microvolts(step: int, pga: PGA) -> int: | ||
""" | ||
convert the step value to microvolts | ||
``` | ||
PGA.MODE2: | ||
-32768 -> -2048mV | ||
+32767 -> +2048mV | ||
``` | ||
""" | ||
factor = { | ||
PGA.MODE0: 6144, | ||
PGA.MODE1: 4096, | ||
PGA.MODE2: 2048, | ||
PGA.MODE3: 1024, | ||
PGA.MODE4: 512, | ||
PGA.MODE5: 256, | ||
PGA.MODE6: 256, # same as MODE5 | ||
PGA.MODE7: 256, # same as MODE5 | ||
} | ||
# it doesn't make much sense to return a floating point value | ||
# 1 step at the highest precision level (PGA.MODE5) is 7.8µV | ||
return round(step * (factor[pga] * 1000 / 32767)) |
Oops, something went wrong.