Skip to content

Commit abda66d

Browse files
nefelim4agKevinOConnor
authored andcommitted
ldc1612: enable frequency div to reduce noise
BTT Eddy uses 12MHz clock in frequency. Coil is oscillating at 3+MHz. Which is out of spec for LDC1612 sensors. Division of coil frequency seems to reduce output noise. Signed-off-by: Timofey Titovets <[email protected]>
1 parent e60fe3d commit abda66d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

klippy/extras/ldc1612.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ def __init__(self, config, calibration=None):
8787
self.oid = oid = mcu.create_oid()
8888
self.query_ldc1612_cmd = None
8989
self.ldc1612_setup_home_cmd = self.query_ldc1612_home_state_cmd = None
90-
self.frequency = config.getint("frequency", DEFAULT_LDC1612_FREQ,
91-
2000000, 40000000)
90+
self.clock_freq = config.getint("frequency", DEFAULT_LDC1612_FREQ,
91+
2000000, 40000000)
92+
# Coil frequency divider, assume 12MHz is BTT Eddy
93+
# BTT Eddy's coil frequency is > 1/4 of reference clock
94+
self.sensor_div = 1 if self.clock_freq != DEFAULT_LDC1612_FREQ else 2
95+
self.freq_conv = float(self.clock_freq * self.sensor_div) / (1<<28)
9296
if config.get('intb_pin', None) is not None:
9397
ppins = config.get_printer().lookup_object("pins")
9498
pin_params = ppins.lookup_pin(config.get('intb_pin'))
@@ -143,7 +147,7 @@ def add_client(self, cb):
143147
def setup_home(self, print_time, trigger_freq,
144148
trsync_oid, hit_reason, err_reason):
145149
clock = self.mcu.print_time_to_clock(print_time)
146-
tfreq = int(trigger_freq * (1<<28) / float(self.frequency) + 0.5)
150+
tfreq = int(trigger_freq / self.freq_conv + 0.5)
147151
self.ldc1612_setup_home_cmd.send(
148152
[self.oid, clock, tfreq, trsync_oid, hit_reason, err_reason])
149153
def clear_home(self):
@@ -155,7 +159,7 @@ def clear_home(self):
155159
return self.mcu.clock_to_print_time(tclock)
156160
# Measurement decoding
157161
def _convert_samples(self, samples):
158-
freq_conv = float(self.frequency) / (1<<28)
162+
freq_conv = self.freq_conv
159163
count = 0
160164
for ptime, val in samples:
161165
mv = val & 0x0fffffff
@@ -176,11 +180,11 @@ def _start_measurements(self):
176180
"(e.g. faulty wiring) or a faulty ldc1612 chip."
177181
% (manuf_id, dev_id, LDC1612_MANUF_ID, LDC1612_DEV_ID))
178182
# Setup chip in requested query rate
179-
rcount0 = self.frequency / (16. * self.data_rate)
183+
rcount0 = self.clock_freq / (16. * self.data_rate)
180184
self.set_reg(REG_RCOUNT0, int(rcount0 + 0.5))
181185
self.set_reg(REG_OFFSET0, 0)
182-
self.set_reg(REG_SETTLECOUNT0, int(SETTLETIME*self.frequency/16. + .5))
183-
self.set_reg(REG_CLOCK_DIVIDERS0, (1 << 12) | 1)
186+
self.set_reg(REG_SETTLECOUNT0, int(SETTLETIME*self.clock_freq/16. + .5))
187+
self.set_reg(REG_CLOCK_DIVIDERS0, (self.sensor_div << 12) | 1)
184188
self.set_reg(REG_ERROR_CONFIG, (0x1f << 11) | 1)
185189
self.set_reg(REG_MUX_CONFIG, 0x0208 | DEGLITCH)
186190
self.set_reg(REG_CONFIG, 0x001 | (1<<12) | (1<<10) | (1<<9))

0 commit comments

Comments
 (0)