|
58 | 58 | _CONFIG_RESET = const(0x8000) # Reset Bit
|
59 | 59 |
|
60 | 60 | _CONFIG_BVOLTAGERANGE_MASK = const(0x2000) # Bus Voltage Range Mask
|
| 61 | +_CONFIG_BVOLTAGERANGE_LSB = const(13) # Bus Voltage Range LSB position |
61 | 62 | _CONFIG_BVOLTAGERANGE_16V = const(0x0000) # 0-16V Range
|
62 | 63 | _CONFIG_BVOLTAGERANGE_32V = const(0x2000) # 0-32V Range
|
63 | 64 |
|
64 | 65 | _CONFIG_GAIN_MASK = const(0x1800) # Gain Mask
|
| 66 | +_CONFIG_GAIN_LSB = const(11) # Gain LSB position |
65 | 67 | _CONFIG_GAIN_1_40MV = const(0x0000) # Gain 1, 40mV Range
|
66 | 68 | _CONFIG_GAIN_2_80MV = const(0x0800) # Gain 2, 80mV Range
|
67 | 69 | _CONFIG_GAIN_4_160MV = const(0x1000) # Gain 4, 160mV Range
|
68 | 70 | _CONFIG_GAIN_8_320MV = const(0x1800) # Gain 8, 320mV Range
|
69 | 71 |
|
70 | 72 | _CONFIG_BADCRES_MASK = const(0x0780) # Bus ADC Resolution Mask
|
71 |
| -_CONFIG_BADCRES_9BIT = const(0x0080) # 9-bit bus res = 0..511 |
72 |
| -_CONFIG_BADCRES_10BIT = const(0x0100) # 10-bit bus res = 0..1023 |
73 |
| -_CONFIG_BADCRES_11BIT = const(0x0200) # 11-bit bus res = 0..2047 |
74 |
| -_CONFIG_BADCRES_12BIT = const(0x0400) # 12-bit bus res = 0..4097 |
| 73 | +_CONFIG_BADCRES_LSB = const(7) # Bus ADC Resolution LSB position |
| 74 | +_CONFIG_BADCRES_9BIT = const(0x0000) # 9-bit bus res = 0..511 |
| 75 | +_CONFIG_BADCRES_10BIT = const(0x0080) # 10-bit bus res = 0..1023 |
| 76 | +_CONFIG_BADCRES_11BIT = const(0x0100) # 11-bit bus res = 0..2047 |
| 77 | +_CONFIG_BADCRES_12BIT = const(0x0180) # 12-bit bus res = 0..4097 |
| 78 | +_CONFIG_BADCRES_12BIT_2S_1060US = const(0x0480) # 2 x 12-bit bus samples averaged together |
| 79 | +_CONFIG_BADCRES_12BIT_4S_2130US = const(0x0500) # 4 x 12-bit bus samples averaged together |
| 80 | +_CONFIG_BADCRES_12BIT_8S_4260US = const(0x0580) # 8 x 12-bit bus samples averaged together |
| 81 | +_CONFIG_BADCRES_12BIT_16S_8510US = const(0x0600) # 16 x 12-bit bus samples averaged together |
| 82 | +_CONFIG_BADCRES_12BIT_32S_17MS = const(0x0680) # 32 x 12-bit bus samples averaged together |
| 83 | +_CONFIG_BADCRES_12BIT_64S_34MS = const(0x0700) # 64 x 12-bit bus samples averaged together |
| 84 | +_CONFIG_BADCRES_12BIT_128S_69MS = const(0x0780) # 128 x 12-bit bus samples averaged together |
75 | 85 |
|
76 | 86 | _CONFIG_SADCRES_MASK = const(0x0078) # Shunt ADC Resolution and Averaging Mask
|
| 87 | +_CONFIG_SADCRES_LSB = const(3) # Shunt ADC Resolution and Averaging LSB position |
77 | 88 | _CONFIG_SADCRES_9BIT_1S_84US = const(0x0000) # 1 x 9-bit shunt sample
|
78 | 89 | _CONFIG_SADCRES_10BIT_1S_148US = const(0x0008) # 1 x 10-bit shunt sample
|
79 | 90 | _CONFIG_SADCRES_11BIT_1S_276US = const(0x0010) # 1 x 11-bit shunt sample
|
|
87 | 98 | _CONFIG_SADCRES_12BIT_128S_69MS = const(0x0078) # 128 x 12-bit shunt samples averaged together
|
88 | 99 |
|
89 | 100 | _CONFIG_MODE_MASK = const(0x0007) # Operating Mode Mask
|
| 101 | +_CONFIG_MODE_LSB = const(0) # Operating Mode LSB position |
90 | 102 | _CONFIG_MODE_POWERDOWN = const(0x0000)
|
91 | 103 | _CONFIG_MODE_SVOLT_TRIGGERED = const(0x0001)
|
92 | 104 | _CONFIG_MODE_BVOLT_TRIGGERED = const(0x0002)
|
@@ -147,6 +159,63 @@ def _read_register(self, reg):
|
147 | 159 | value = (buf[1] << 8) | (buf[2])
|
148 | 160 | return value
|
149 | 161 |
|
| 162 | + @property |
| 163 | + def config(self): |
| 164 | + return self._read_register(_REG_CONFIG) |
| 165 | + |
| 166 | + @config.setter |
| 167 | + def config(self,value): |
| 168 | + self._write_register(_REG_CONFIG,value) |
| 169 | + |
| 170 | + @property |
| 171 | + def reset(self): |
| 172 | + self._write_register(_REG_CONFIG,_CONFIG_RESET) |
| 173 | + |
| 174 | + @property |
| 175 | + def bus_voltage_range(self): |
| 176 | + return (self.config & _CONFIG_BVOLTAGERANGE_MASK) >> _CONFIG_BVOLTAGERANGE_LSB |
| 177 | + |
| 178 | + @bus_voltage_range.setter |
| 179 | + def bus_voltage_range(self,value): |
| 180 | + value = (value << _CONFIG_BVOLTAGERANGE_LSB) & _CONFIG_BVOLTAGERANGE_MASK |
| 181 | + self.config = value | (self.config & ~_CONFIG_BVOLTAGERANGE_MASK) |
| 182 | + |
| 183 | + @property |
| 184 | + def gain(self): |
| 185 | + return (self.config & _CONFIG_GAIN_MASK) >> _CONFIG_GAIN_LSB |
| 186 | + |
| 187 | + @gain.setter |
| 188 | + def gain(self,value): |
| 189 | + value = (value << _CONFIG_GAIN_LSB) & _CONFIG_GAIN_MASK |
| 190 | + self.config = value | (self.config & ~_CONFIG_GAIN_MASK) |
| 191 | + |
| 192 | + @property |
| 193 | + def bus_adc_res(self): |
| 194 | + return (self.config & _CONFIG_BADCRES_MASK) >> _CONFIG_BADCRES_LSB |
| 195 | + |
| 196 | + @bus_adc_res.setter |
| 197 | + def bus_adc_res(self,value): |
| 198 | + value = (value << _CONFIG_BADCRES_LSB) & _CONFIG_BADCRES_MASK |
| 199 | + self.config = value | (self.config & ~_CONFIG_BADCRES_MASK) |
| 200 | + |
| 201 | + @property |
| 202 | + def shunt_adc_res(self): |
| 203 | + return (self.config & _CONFIG_SADCRES_MASK) >> _CONFIG_SADCRES_LSB |
| 204 | + |
| 205 | + @shunt_adc_res.setter |
| 206 | + def shunt_adc_res(self,value): |
| 207 | + value = (value << _CONFIG_SADCRES_LSB) & _CONFIG_SADCRES_MASK |
| 208 | + self.config = value | (self.config & ~_CONFIG_SADCRES_MASK) |
| 209 | + |
| 210 | + @property |
| 211 | + def mode(self): |
| 212 | + return (self.config & _CONFIG_MODE_MASK) >> _CONFIG_MODE_LSB |
| 213 | + |
| 214 | + @mode.setter |
| 215 | + def mode(self,value): |
| 216 | + value = (value << _CONFIG_MODE_LSB) & _CONFIG_MODE_MASK |
| 217 | + self.config = value | (self.config & ~_CONFIG_MODE_MASK) |
| 218 | + |
150 | 219 | @property
|
151 | 220 | def shunt_voltage(self):
|
152 | 221 | """The shunt voltage (between V+ and V-) in Volts (so +-.327V)"""
|
|
0 commit comments