@@ -38,6 +38,7 @@ def __init__(self, config, sensor):
3838 self .sensor = sensor
3939 self .drive_cur = config .getint ("reg_drive_current" , DRIVECUR ,
4040 minval = 0 , maxval = 31 )
41+ self .high_cur = config .getboolean ("high_current_drive" , False )
4142 self .name = config .get_name ()
4243 gcode = self .printer .lookup_object ('gcode' )
4344 gcode .register_mux_command ("LDC_CALIBRATE_DRIVE_CURRENT" ,
@@ -46,6 +47,8 @@ def __init__(self, config, sensor):
4647 desc = self .cmd_LDC_CALIBRATE_help )
4748 def get_drive_current (self ):
4849 return self .drive_cur
50+ def get_high_cur_flag (self ):
51+ return self .high_cur
4952 cmd_LDC_CALIBRATE_help = "Calibrate LDC1612 DRIVE_CURRENT register"
5053 def cmd_LDC_CALIBRATE (self , gcmd ):
5154 is_in_progress = True
@@ -56,20 +59,43 @@ def handle_batch(msg):
5659 toolhead .dwell (0.100 )
5760 toolhead .wait_moves ()
5861 old_config = self .sensor .read_reg (REG_CONFIG )
59- self .sensor .set_reg (REG_CONFIG , 0x001 | (1 << 9 ))
62+ REF_CLK_SRC = 1 << 9
63+ CFG = 0x001 | REF_CLK_SRC
64+ self .sensor .set_reg (REG_CONFIG , CFG )
6065 toolhead .wait_moves ()
6166 toolhead .dwell (0.100 )
6267 toolhead .wait_moves ()
6368 reg_drive_current0 = self .sensor .read_reg (REG_DRIVE_CURRENT0 )
69+ drive_cur_low = (reg_drive_current0 >> 6 ) & 0x1f
70+ drive_cur_high = 0
71+ # Test high current drive if necessary
72+ if drive_cur_low >= 27 :
73+ HIGH_CURRENT_DRV = 1 << 6
74+ CFG = 0x001 | REF_CLK_SRC | HIGH_CURRENT_DRV
75+ self .sensor .set_reg (REG_CONFIG , CFG )
76+ toolhead .wait_moves ()
77+ toolhead .dwell (0.100 )
78+ toolhead .wait_moves ()
79+ reg_drive_current0 = self .sensor .read_reg (REG_DRIVE_CURRENT0 )
80+ drive_cur_high = (reg_drive_current0 >> 6 ) & 0x1f
81+ # Stop measurements
6482 self .sensor .set_reg (REG_CONFIG , old_config )
6583 is_in_progress = False
84+ drive_cur = drive_cur_low
85+ # High current > 1.5 mA
86+ if drive_cur_high >= 19 :
87+ drive_cur = drive_cur_high
88+ use_high_cur = (drive_cur == drive_cur_high )
6689 # Report found value to user
67- drive_cur = (reg_drive_current0 >> 6 ) & 0x1f
6890 gcmd .respond_info (
91+ "%s: high_current_drive: %s\n "
6992 "%s: reg_drive_current: %d\n "
7093 "The SAVE_CONFIG command will update the printer config file\n "
71- "with the above and restart the printer." % (self .name , drive_cur ))
94+ "with the above and restart the printer." % (
95+ self .name , use_high_cur ,
96+ self .name , drive_cur ))
7297 configfile = self .printer .lookup_object ('configfile' )
98+ configfile .set (self .name , 'high_current_drive' , "%s" % (use_high_cur ,))
7399 configfile .set (self .name , 'reg_drive_current' , "%d" % (drive_cur ,))
74100
75101# Interface class to LDC1612 mcu support
@@ -183,7 +209,13 @@ def _start_measurements(self):
183209 self .set_reg (REG_CLOCK_DIVIDERS0 , (1 << 12 ) | 1 )
184210 self .set_reg (REG_ERROR_CONFIG , (0x1f << 11 ) | 1 )
185211 self .set_reg (REG_MUX_CONFIG , 0x0208 | DEGLITCH )
186- self .set_reg (REG_CONFIG , 0x001 | (1 << 12 ) | (1 << 10 ) | (1 << 9 ))
212+ HIGH_CURRENT_DRV = int (self .dccal .get_high_cur_flag ()) << 6
213+ REF_CLK_SRC = 1 << 9
214+ AUTO_AMP_DIS = 1 << 10
215+ RP_OVERRIDE_EN = 1 << 12
216+ CFG = 0x001 # constant
217+ CFG |= RP_OVERRIDE_EN | AUTO_AMP_DIS | REF_CLK_SRC | HIGH_CURRENT_DRV
218+ self .set_reg (REG_CONFIG , CFG )
187219 self .set_reg (REG_DRIVE_CURRENT0 , self .dccal .get_drive_current () << 11 )
188220 # Start bulk reading
189221 rest_ticks = self .mcu .seconds_to_clock (0.5 / self .data_rate )
0 commit comments