Welcome! Log In Create A New Profile

Advanced

Clarification - reaction time Marlin 2.1.2.5

Posted by promanowski 
Clarification - reaction time Marlin 2.1.2.5
September 07, 2025 10:23AM
Hello, I can’t find where delay is hidden so if someone can be so polite and give me a hint. In general i try to modify Marlin FW and MKS Gen L board to handle EDM machine. I have sperate spark generator that also is sensing if there is short. So in marlin i add my own M1910 code that is moving Z axis a bit back and a bit fwd (to hold original position). My problem is like this, when M1910 code (my own new Mcode) is called from terminal all works fine (reaction is ~100ms). But when it’s called by change GPIO state that is proper configurated time to react during movement is like 1000ms(measured on scope). Question - where or How i can put my M1910 code to work in the same time regime like M410 ? - i don't see declaration of M410 in code ;/

Code of this M1910 is below - and it works OK there is proper reaction if used by serial terminal
// ###  insdie gcode.cpp gcode.h also have addtional info for M1910
void GcodeSuite::M1910() {
  float saved_z = current_position.z;       
  //float real_z = planner.get_axis_position_mm(Z_AXIS); 
  edm_mode=true;    			// set flag when 1st used 
  SERIAL_ECHO(" before synchro: ");	// debug
  SERIAL_ECHO(millis());			// debug
  planner.synchronize();  			// Stop movment
  SERIAL_ECHO(" after synchro: ");		//debug
  SERIAL_ECHO(millis());			//debug
  current_position.z -= 0.35;			// move bit back
  line_to_current_position();			// alig axis
   current_position.z += 0.35;		// move to start position
  line_to_current_position();			// align axis
  SERIAL_ECHO(" after all ");		//debug
  SERIAL_ECHO(millis());			// debug
}
Than inside MarlinCore.cpp i have this code - its sensing LOW state at one of GPIO and when it sens it change of state triggers its checked at idle()
// ## MarlinCore.cpp
// ## this is called at idle loop
void edm_trigger_update() {
if(edm_mode==true){
	static bool edm_triggered_last = false;  // this is to handle only one change from Hi to Low state
	bool edm_triggered_now = (digitalRead(EDM_TRIGGER_PIN) == LOW);  // this is to handle only one change from Hi to Low state
		if (edm_triggered_now && !edm_triggered_last) {
			SERIAL_ECHO("Loop enters: "); 	// debug
 			SERIAL_ECHO(millis());		// debug
			queue.enqueue_one("M410");	// let’s stop current movment
			SERIAL_ECHO(" enqueue_one M410 at: "); // debug
			SERIAL_ECHO( millis());			// debug
			  queue.enqueue_one("M1910");	// lets call bit back bit FWD
			  //SERIAL_ECHO(" enqueue_one M1910 at: "); // debug
			SERIAL_ECHO(millis());		// debug
					}
 	edm_triggered_last = edm_triggered_now; // this is to handle only one change from Hi to Low state
 }
}

Result of debag from code "enqueue_one M1910 at: 25921 before synchro: 26923 after synchro: 26924 after all 26927 " -> So its look like my “void edm_trigger_update()” is finished ad mils time 25 921 but inside it ansychronisly code M1910 is still running and all actions are taken after those ~1000ms ( 26 297)
Re: Clarification - reaction time Marlin 2.1.2.5
September 07, 2025 03:39PM
I'm not sure if its related to your delay or not

but M410 can be handled by EMERGENCY_PARSER, ie it jumps to the head of the queue as soon as its is seen in the serial buffer.

code is in Marlin/src/feature/e_parser.h / Marlin/src/feature/e_parser.cpp
Re: Clarification - reaction time Marlin 2.1.2.5
September 08, 2025 10:56AM
Hi, thank for response - after long debugging ... 10h .. my expected behavior was reached by changing cleaning_buffer_counter = TEMP_TIMER_FREQUENCY; to 10 - looks like TEMP_TIMER_FREQUENCY is equal to 1000 and this is reason of delay of 1 second. Now new bad behavior is emerging -> my algorithm works like charm but there is no ok returned after reaching to final position. So algorithm works like this - > when
a)GPIO is triggered falling edge we call M410 ->
b)at end of M410 it copy from buffer last send G command from terminal ,
c)than we execute move back <> move bit fwd
d)than copied command is injected to realization (we continue to move to final position)
e) when axis reach final position i expect to see ok – this is never visible -> why queue.enqueue_one(last_executed_gcode) <- this dont give OK ? or i need to set some flag ? or my expecation is not proper one ? how send parser know that move is finished ?
“// M1910
void EDM_reaction(){   // zmiana
  // last_executed_gcode is copied in  gcode.cpp  = last gcode
  float saved_z = current_position.z; 
  current_position.z -= 0.35;
  line_to_current_position();
   current_position.z += 0.35;
  line_to_current_position();
  if (last_executed_gcode[0]) {
queue.enqueue_one(last_executed_gcode) ;// inject command one more time expect to se OK in terminal because coordinates were reached
  }

Edited 1 time(s). Last edit at 09/08/2025 11:00AM by promanowski.
Sorry, only registered users may post in this forum.

Click here to login