Skip to content

Commit 5fa1321

Browse files
committed
Improved Threading synchronization, and minor changes
Improved Threading synchronization Added a step enable delay to support servo drivers in step/dir mode (like Lichuan A4 series) Some minor changes Update setting_codes_en_US.csv Update config.h
1 parent d10a1dd commit 5fa1321

File tree

9 files changed

+48
-37
lines changed

9 files changed

+48
-37
lines changed

doc/csv/setting_codes_en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"$-Code"," Setting"," Units"," Setting Description"
22
"0","Step pulse time","microseconds","Sets time length per step. Minimum 3usec."
3-
"1","Step idle delay","milliseconds","Sets a short hold delay when stopping to let dynamics settle before disabling steppers. Value 255 keeps motors enabled with no delay."
3+
"1","Step enable & idle delay","milliseconds","Sets a short hold delay when starting & stopping to let dynamics settle after enabling but before stepping or disabling steppers. Value 255 keeps motors enabled with no delay."
44
"2","Step pulse invert","mask","Inverts the step signal. Set axis bit to invert (00000ZYX)."
55
"3","Step direction invert","mask","Inverts the direction signal. Set axis bit to invert (00000ZYX)."
66
"4","Invert step enable pin","boolean","Inverts the stepper driver enable pin signal."

grbl/config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@
423423
// values for certain setups have ranged from 5 to 20us.
424424
// #define STEP_PULSE_DELAY 10 // Step pulse delay in microseconds. Default disabled.
425425

426+
// Creates a delay between the first step pulse after enabling and after the last step pulse before disabling.
427+
// Lichuan servo's running in step-dir mode need a 100 ms delay between the motor enable signal and the first step pulse
428+
// They also needs some time after the last step pulse before they can be disabled without losing steps
429+
// The delay is executed in the st_wake_up() and st_go_idle() routine
430+
// The delay time is the same as the stepper_idle_lock_time ($1)
431+
#define STEP_ENABLE_DELAY // Step enable and disable delay in milliseconds. Used for running servo's in step-dir mode (Lichuan) // default enabled
432+
426433
// The number of linear motions in the planner buffer to be planned at any give time. The vast
427434
// majority of RAM that Grbl uses is based on this buffer size. Only increase if there is extra
428435
// available RAM, like when re-compiling for a Mega or Sanguino. Or decrease if the Arduino

grbl/grbl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#define grbl_h
2323

2424
// Grbl versioning system
25-
#define GRBL_VERSION "1.1g2"
26-
#define GRBL_VERSION_BUILD "20200510.Mega"
25+
#define GRBL_VERSION "1.1g3"
26+
#define GRBL_VERSION_BUILD "20211002.Mega"
2727

2828
// Define standard libraries used by Grbl.
2929
#include <util/atomic.h>

grbl/planner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ float plan_compute_profile_nominal_speed(plan_block_t *block)
265265
system_clear_threading_exec_flag(EXEC_PLANNER_SYNC_PULSE); // clear the bit to avoid processing again.
266266
threading_millimeters_target-=threading_mm_per_synchronization_pulse; // calculate the new target
267267
synchronization_millimeters_error=threading_millimeters_target-block->millimeters; // calculate the position error. Note that block->millimeters counts down This has to be compensated at the next spindle pulse
268-
block->programmed_rate=(threading_mm_per_synchronization_pulse-synchronization_millimeters_error) / ((float) threading_index_timer_tics_passed / threading_feed_rate_calculation_factor); //calculate the new feed rate to reduce the error. threading_feed_rate_calculation_factor= ((float) 15000000 * (float) settings.sync_pulses_per_revolution));
268+
block->programmed_rate=(threading_mm_per_index_pulse-synchronization_millimeters_error) / (((float) threading_sync_timer_tics_passed ) / threading_feed_rate_calculation_factor); //calculate the new feed rate to reduce the error.
269269
if (block->programmed_rate>block->rapid_rate) // limit speed to max-rate set for this block
270-
block->programmed_rate=block->rapid_rate; //block->rapid_rate
270+
block->programmed_rate=block->rapid_rate; // don't run faster than block->rapid_rate
271271
}
272272
} else {
273273
if (!(block->condition & PL_COND_FLAG_NO_FEED_OVERRIDE)) { nominal_speed *= (0.01*sys.f_override); }

grbl/protocol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ void protocol_exec_rt_system()
252252
process_spindle_index_pulse(); // Process the pulse so the RPM will be updated in the real time status report
253253
if (spindle_synchronization_active()) { // if spindle synchronization is active
254254
if bit_istrue(settings.status_report_mask,BITFLAG_RT_STATUS_SYNC_STATE){ // if setting report mask is set for reporting the synchronization status in the real time status report
255-
system_set_threading_exec_flag((EXEC_SYNCHRONIZATION_STATE_REPORT | EXEC_SYNCHRONIZATION_STATE_REPORT_FINAL)); // set the reporting flags to report the synchronization status now and once when finished
255+
system_set_threading_exec_flag(EXEC_SYNCHRONIZATION_STATE_REPORT); // set the reporting flags to report the synchronization status now and once when finished
256256
}
257257
if bit_istrue(settings.status_report_mask,BITFLAG_FEED_BACK_SYNC_STATUS){ // if setting report mask is set for synchronization error feedback
258-
system_set_threading_exec_flag((EXEC_SYNCHRONIZATION_STATE_FEEDBACK_ERROR)); // set the reporting flags to feedback the synchronization error
258+
system_set_threading_exec_flag((EXEC_SYNCHRONIZATION_STATE_FEEDBACK_ERROR)); // set the reporting flags to feedback the synchronization error
259259
}
260260
}
261261
}

grbl/report.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void report_util_setting_string(uint8_t n) {
5050
serial_write('(');
5151
switch(n) {
5252
case 0: printPgmString(PSTR("stp pulse")); break;
53-
case 1: printPgmString(PSTR("idl delay")); break;
53+
case 1: printPgmString(PSTR("idl delay")); break;
5454
case 2: printPgmString(PSTR("stp inv")); break;
5555
case 3: printPgmString(PSTR("dir inv")); break;
5656
case 4: printPgmString(PSTR("stp en inv")); break;
@@ -101,8 +101,8 @@ static void report_util_uint16_setting(uint16_t n, int val) {
101101
print_uint32_base10((uint32_t)val);
102102
report_util_line_feed(); // report_util_setting_string(n);
103103
}
104-
static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) {
105-
report_util_setting_prefix(n);
104+
static void report_util_float_setting(uint8_t n, float val, uint8_t n_decimal) {
105+
report_util_setting_prefix(n);
106106
printFloat(val,n_decimal);
107107
report_util_line_feed(); // report_util_setting_string(n);
108108
}
@@ -196,7 +196,7 @@ void report_init_message()
196196

197197
// Grbl help message
198198
void report_grbl_help() {
199-
printPgmString(PSTR("[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $SLP $C $X $H ~ ! ? ctrl-x]\r\n"));
199+
printPgmString(PSTR("[HLP:$$ $# $G $I $N $x=val $Nx=line $J=line $SLP $C $X $H ~ ! ? ctrl-x]\r\n"));
200200
}
201201

202202
// Grbl global settings print out.
@@ -321,8 +321,8 @@ void report_gcode_modes()
321321
switch (gc_state.modal.program_flow) {
322322
case PROGRAM_FLOW_PAUSED : serial_write('0'); break;
323323
// case PROGRAM_FLOW_OPTIONAL_STOP : serial_write('1'); break; // M1 is ignored and not supported.
324-
case PROGRAM_FLOW_COMPLETED_M2 :
325-
case PROGRAM_FLOW_COMPLETED_M30 :
324+
case PROGRAM_FLOW_COMPLETED_M2 :
325+
case PROGRAM_FLOW_COMPLETED_M30 :
326326
print_uint8_base10(gc_state.modal.program_flow);
327327
break;
328328
}
@@ -342,12 +342,12 @@ void report_gcode_modes()
342342
} else { serial_write('9'); }
343343

344344
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
345-
if (sys.override_ctrl == OVERRIDE_PARKING_MOTION) {
345+
if (sys.override_ctrl == OVERRIDE_PARKING_MOTION) {
346346
report_util_gcode_modes_M();
347347
print_uint8_base10(56);
348348
}
349349
#endif
350-
350+
351351
printPgmString(PSTR(" T"));
352352
print_uint8_base10(gc_state.tool);
353353

@@ -389,7 +389,7 @@ void report_build_info(char *line)
389389
serial_write('N'); // Line number reporting standard.
390390
serial_write('M'); // M7 mist coolant standard.
391391
serial_write('+'); // Safety door support standard.
392-
serial_write('X'); // Extended lathe command set
392+
serial_write('X'); // Extended lathe command set
393393
serial_write('1'); // Extended lathe command set Version 1: G33 spindle synchronization support for threading.
394394
#ifdef COREXY
395395
serial_write('C');
@@ -618,24 +618,21 @@ void report_realtime_status()
618618
}
619619
if (cl_state & COOLANT_STATE_FLOOD) { serial_write('F'); }
620620
if (cl_state & COOLANT_STATE_MIST) { serial_write('M'); }
621-
}
621+
}
622622
}
623623
#endif
624-
625-
// report the synchronization state (G33)
626-
//if (spindle_synchronization_active()) {
627-
if (bit_istrue(threading_exec_flags,(EXEC_SYNCHRONIZATION_STATE_REPORT))) { // report if a report is flagged
628-
printPgmString(PSTR("|Se:"));
629-
printFloat_CoordValue(synchronization_millimeters_error); // print the synchronization error in the unit set
630-
bit_false(threading_exec_flags,EXEC_SYNCHRONIZATION_STATE_REPORT); // clear the flag to avoid reporting the same value again
631-
}
632-
//} else if (bit_istrue(threading_exec_flags,EXEC_SYNCHRONIZATION_STATE_REPORT_FINAL)) { // if a final report is flagged and spindle synchronization is inactive
633-
else {
634-
printPgmString(PSTR("|Se:")); // Report report a 0 value after G33 , looks better in a GUI
635-
printFloat(0,2);
636-
bit_false(threading_exec_flags,EXEC_SYNCHRONIZATION_STATE_REPORT_FINAL); // clear the flag to avoid reporting the same value again
624+
625+
// report the synchronization state (G33)
626+
if (bit_istrue(threading_exec_flags,(EXEC_SYNCHRONIZATION_STATE_REPORT))) { // report if a report is flagged
627+
printPgmString(PSTR("|Se:"));
628+
printFloat_CoordValue(synchronization_millimeters_error); // print the synchronization error in the unit set
629+
bit_false(threading_exec_flags,EXEC_SYNCHRONIZATION_STATE_REPORT); // clear the flag to avoid reporting the same value again
630+
}
631+
else {
632+
printPgmString(PSTR("|Se:")); // report a 0 value after G33 , looks better in a GUI
633+
printFloat(0,2);
637634
}
638-
635+
639636
serial_write('>');
640637
report_util_line_feed();
641638
}

grbl/stepper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ void st_wake_up()
255255
st.step_outbits = step_port_invert_mask;
256256
#endif // Ramps Board
257257

258+
#ifdef STEP_ENABLE_DELAY
259+
delay_ms(settings.stepper_idle_lock_time); //Wait a bit to give the driver time to wake up. Is used for servo drivers in step-dir mode like Lichuan
260+
#endif
261+
258262
// Initialize step pulse timing from settings. Here to ensure updating after re-writing.
259263
#ifdef STEP_PULSE_DELAY
260264
// Set total step pulse time after direction pin set. Ad hoc computation from oscilloscope.

grbl/threading.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ volatile uint32_t threading_index_Last_timer_tics; // Time at the last index
2929
volatile uint32_t threading_index_timer_tics_passed=0; // Time passed at the last index pulse
3030
volatile uint32_t threading_index_spindle_speed; // The measured spindle speed used for G33 initial speed and reporting the real spindle speed
3131
float threading_mm_per_synchronization_pulse; // The factor to calculate the feed rate from the spindle speed
32+
float threading_mm_per_index_pulse; // The factor to calculate the feed rate from the spindle speed
3233
volatile float threading_millimeters_target; // The threading feed target as reported by the planner
3334
volatile float synchronization_millimeters_error; // The synchronization feed error calculated at every synchronization pulse. It can be reported to check the threading accuracy
3435
float threading_feed_rate_calculation_factor; // factor is used in plan_compute_profile_nominal_speed(), depends on the number of synchronization pulses and is calculated on startup for performance reasons.
@@ -38,9 +39,10 @@ float threading_feed_rate_calculation_factor; // factor is used in plan_comp
3839
void threading_init(float K_value)
3940
{
4041
threading_mm_per_synchronization_pulse= K_value / (float) settings.sync_pulses_per_revolution; // Calculate the global mm feed per synchronization pulse value.
41-
threading_feed_rate_calculation_factor = ((float) 15000000 * (float) settings.sync_pulses_per_revolution); //calculate the factor to speedup the planner during threading
42-
timekeeper_reset(); //reset the timekeeper to avoid calculation errors when timer overflow occurs (to be sure)
43-
threading_reset(); //Sets the target position to zero and calculates the next target position
42+
threading_mm_per_index_pulse= K_value; // Calculate the global mm feed per synchronization pulse value.
43+
threading_feed_rate_calculation_factor = ((float) 15000000 / (float) settings.sync_pulses_per_revolution); // Calculate the factor to speedup the planner during threading
44+
timekeeper_reset(); // Reset the timekeeper to avoid calculation errors when timer overflow occurs (to be sure)
45+
threading_reset(); // Sets the target position to zero and calculates the next target position
4446
}
4547
// Reset variables to start the threading
4648
void threading_reset()
@@ -75,7 +77,7 @@ void process_spindle_index_pulse()
7577
void process_spindle_synchronization_pulse()
7678
{
7779
threading_sync_timer_tics_passed=get_timer_ticks()-threading_sync_Last_timer_tics; // Calculate the time between synchronization pulses
78-
threading_sync_timer_tics_passed+=threading_sync_timer_tics_passed; // adjust for calculating the next time
80+
threading_sync_Last_timer_tics+=threading_sync_timer_tics_passed; // adjust for calculating the next time
7981
threading_sync_pulse_count++; // Increase the synchronization pulse count
8082
}
8183

grbl/threading.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ extern volatile uint32_t threading_index_spindle_speed; // The spindle speed
3232
extern volatile float threading_millimeters_target; // The threading target feed to go as reported by the planner
3333
extern volatile float synchronization_millimeters_error; // The threading feed error calculated at every synchronization pulse
3434
extern float threading_mm_per_synchronization_pulse; // Z-axis motion at each sync pulse. Is not declared as volatile because it is not updated by an ISR routine.
35-
extern float threading_feed_rate_calculation_factor; // factor used in plan_compute_profile_nominal_speed() and is calculated on startup for performance reasons.
35+
extern float threading_mm_per_index_pulse; // Z-axis motion at each index pulse. Is not declared as volatile because it is not updated by an ISR routine.
36+
extern float threading_feed_rate_calculation_factor; // Factor is used in plan_compute_profile_nominal_speed() and is calculated at threading start for performance reasons.
3637

37-
void threading_init(float K_value); //initializes the G33 threading pass using the K value set in the gcode
38+
void threading_init(float K_value); // Initializes the G33 threading pass using the K value set in the gcode
3839
uint32_t timer_tics_passed_since_last_index_pulse();
3940
void process_spindle_index_pulse();
4041
void process_spindle_synchronization_pulse();

0 commit comments

Comments
 (0)