aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras
diff options
context:
space:
mode:
authorXiaoK <xiaok@zxkxz.cn>2025-03-30 09:53:52 +0800
committerGitHub <noreply@github.com>2025-03-29 21:53:52 -0400
commit52617455ce0cdd745e7d130be3e4fad6d903f261 (patch)
tree623800e633db6062b382f111ae05c9edfd0104c1 /klippy/extras
parentd679f711ebec3c802407b8d82be416e44df21f21 (diff)
downloadkutter-52617455ce0cdd745e7d130be3e4fad6d903f261.tar.gz
kutter-52617455ce0cdd745e7d130be3e4fad6d903f261.tar.xz
kutter-52617455ce0cdd745e7d130be3e4fad6d903f261.zip
ldc_1612: Supports configurable external crystal frequency (#6734)
You can use the 40Mhz crystal oscillator recommended by TI official manual to get the best performance. refer to: [ldc1612.pdf](https://www.ti.com/cn/lit/ds/symlink/ldc1612.pdf) 7.3.4 Signed-off-by: Xiaokui Zhao <xiaok@zxkxzk.cn>
Diffstat (limited to 'klippy/extras')
-rw-r--r--klippy/extras/ldc1612.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/klippy/extras/ldc1612.py b/klippy/extras/ldc1612.py
index 281d3422..dd41b43a 100644
--- a/klippy/extras/ldc1612.py
+++ b/klippy/extras/ldc1612.py
@@ -12,7 +12,7 @@ BATCH_UPDATES = 0.100
LDC1612_ADDR = 0x2a
-LDC1612_FREQ = 12000000
+DEFAULT_LDC1612_FREQ = 12000000
SETTLETIME = 0.005
DRIVECUR = 15
DEGLITCH = 0x05 # 10 Mhz
@@ -87,6 +87,8 @@ class LDC1612:
self.oid = oid = mcu.create_oid()
self.query_ldc1612_cmd = None
self.ldc1612_setup_home_cmd = self.query_ldc1612_home_state_cmd = None
+ self.frequency = config.getint("frequency", DEFAULT_LDC1612_FREQ,
+ 2000000, 40000000)
if config.get('intb_pin', None) is not None:
ppins = config.get_printer().lookup_object("pins")
pin_params = ppins.lookup_pin(config.get('intb_pin'))
@@ -141,7 +143,7 @@ class LDC1612:
def setup_home(self, print_time, trigger_freq,
trsync_oid, hit_reason, err_reason):
clock = self.mcu.print_time_to_clock(print_time)
- tfreq = int(trigger_freq * (1<<28) / float(LDC1612_FREQ) + 0.5)
+ tfreq = int(trigger_freq * (1<<28) / float(self.frequency) + 0.5)
self.ldc1612_setup_home_cmd.send(
[self.oid, clock, tfreq, trsync_oid, hit_reason, err_reason])
def clear_home(self):
@@ -153,7 +155,7 @@ class LDC1612:
return self.mcu.clock_to_print_time(tclock)
# Measurement decoding
def _convert_samples(self, samples):
- freq_conv = float(LDC1612_FREQ) / (1<<28)
+ freq_conv = float(self.frequency) / (1<<28)
count = 0
for ptime, val in samples:
mv = val & 0x0fffffff
@@ -174,10 +176,10 @@ class LDC1612:
"(e.g. faulty wiring) or a faulty ldc1612 chip."
% (manuf_id, dev_id, LDC1612_MANUF_ID, LDC1612_DEV_ID))
# Setup chip in requested query rate
- rcount0 = LDC1612_FREQ / (16. * (self.data_rate - 4))
+ rcount0 = self.frequency / (16. * (self.data_rate - 4))
self.set_reg(REG_RCOUNT0, int(rcount0 + 0.5))
self.set_reg(REG_OFFSET0, 0)
- self.set_reg(REG_SETTLECOUNT0, int(SETTLETIME*LDC1612_FREQ/16. + .5))
+ self.set_reg(REG_SETTLECOUNT0, int(SETTLETIME*self.frequency/16. + .5))
self.set_reg(REG_CLOCK_DIVIDERS0, (1 << 12) | 1)
self.set_reg(REG_ERROR_CONFIG, (0x1f << 11) | 1)
self.set_reg(REG_MUX_CONFIG, 0x0208 | DEGLITCH)