Triggersequences with M62/M63 #523
-
Hi everyone, I am trying to implement a triggersequence similary like a row of M-Code M62/M63. The aim of the game is that I want to move to a position, e.g. X100 Y100, and set a digital output to high for 1 stepper pulse length at this position. Then I want to trigger all 100 stepper pulses of the x-axis to high for 1 stepper pulse length, the other 99 stepper pulses I have a low signal. For this use case I have implemented a new M-Code command, with the M-Code template. The new M-Code command uses the linked list, that is also used for the M62 or M63, but I need to store more data like number of pulses or period of one pulse. Therefore, I extended the struct output_command with 2 bool, 2 uint16_t and 2 uint8_t variables (picture 2). In stepper_driver_interrupt_handler I initialize my triggersequence struct (see in picture 1) and a counter in the stepperSetStepOutputs counts the stepper pulses. If I have enough time, the trigger sequence runs well, but with many arcs and many trigger sequences, the motor has a step loss, probably the stepper_driver_interrupt_handler is no longer triggered at the expected times. Does anyone have any ideas on how I can improve my code so that the ISR stepper_driver_interrupt_handler take less execution time or does anyone have a different approach to implementing a trigger sequence with motion synchronization? I hope you can help me. Many thanks in advance. Best regards Andre |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Which driver(s) is your target? One? Many? A general comment would be not to modify the core, you can "hook in" your code to be executed on the stepper IRQ, either before of after a step is generated. This would allow you to keep all your code in a separate plugin. |
Beta Was this translation helpful? Give feedback.
If you combine your new M-code with M62/M63 I believe you can keep your custom linked list in the plugin. When hal.port.digital_out() gets called set a flag in your plugin and act on that on the next hal.stepper.pulse_start() call.
At the time of your new M-code is parsed get the position from gc_state, save it in your list and later compare that to the position in the hal.stepper.pulse_start() struct parameter when the associated M62/M63 is executed.
If you want you can also add a number of virtual digital outputs and use the port numbers of these as an id if that makes it easier to keep track.