Skip to content

Commit c4e06b1

Browse files
fix channel select data buffer issue
clears the data buffer before changing channels to avoid ghosting adds a timeout counter for the Cycle Ready flag check rather than a fixed settling time delay (improves latency)
1 parent f873994 commit c4e06b1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cedargrove_nau7802.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ def channel(self):
184184

185185
@channel.setter
186186
def channel(self, chan=1):
187-
"""Select the active channel. Valid channel numbers are 1 and 2."""
187+
"""Select the active channel. Valid channel numbers are 1 and 2.
188+
Returns True unless a cycle ready (CR) timeout occurs."""
189+
190+
self.read() # Clear the data buffer
188191

189192
if chan == 1:
190193
self._c2_chan_select = 0x0
@@ -193,9 +196,12 @@ def channel(self, chan=1):
193196
else:
194197
raise ValueError("Invalid Channel Number")
195198

196-
time.sleep(0.500) # Fixed settling time
199+
# Check cycle ready flag; timeout after 1.0 sec
200+
t0 = time.monotonic()
197201
while not self._pu_cycle_ready:
198-
pass
202+
if time.monotonic() - t0 > 1.0:
203+
return False
204+
return True
199205

200206
@property
201207
def ldo_voltage(self):

0 commit comments

Comments
 (0)