MPCNC post processor and PWM controlled laser

Greetings

Great job on the post processor. Amazing! However, after a few hours of experimenting with a laser (which happens to be the latest toy, so I’m using it, unfortunately only 3 watts), and I’ve come across a possible issue.

Please read all the way through, I think I came up with a, at least, temporary solution, but let me continue.

My laser uses PWM to control the laser power, not voltage, as from D9. I’ve got it hooked up to Pin 4 and am using an M42 command to turn the laser on and off.

I’ve added the correct commands to the configuration locations in the MPCNC post processor. and it seems to work somewhat. The issue is that M42 is an immediate command.

Let me clarify with an example:
I’m cutting a small circle in paper, and the gcode starts like this:

------excerpt begins--------
;1
;T0 D=0 CR=0 - ZMIN=0 - laser cutter
G90
;Units in mm
G92 X0 Y0 Z0
M84 S1800 ;Change Stepper disable timeout to 30 minutes

;Contour4
G1 Z0 F1000
G1 X-4.851 Y9.12 F2000 <<<<<<< Move to circle start <<<<<<<<<<
M42 P4 S220 <<<<<<<<<< Turn on laser <<<<<<<<<<<<<<<<<<<
G1 X-4.859 Y9.41 F700 <<<<<<< Begin cutting circle <<<<<<<<<<<<<
…etc
-----excerpt ends----------

My issue is that since the M42 command is immediate, it executes before completion of the G1 command in the buffer moving to the start of the circle. so the circles look sort of line “Q’s” with the laser turning on during the initial move command.

I solved the problem by entering “G4 S0 :M42 P4 S220” in the spot to turn the
laser on (and similar for turning the laser off). This solves the problem because the G4 S0 commands waits until the buffer is empty.

Here’s the issue: I’m not sure the colon “:” is an official command delimiter. It works, but from what I’ve read so far on the web, it’s an artifact, and I’m unsure if it will continue to work in the future. So, here’s the request, what would be much better would be if I could enter multiple lines of commands for laser on/off in the MPCNC post processor. If you take a look at ESTLCAM, there’s a multiline text field where multiple lines of code can be entered.

Would it be difficult to make the MPCNC post processor allow for this?

And for the bonus round, could there be a similar thing adding for “Tool Change”, “Program Start”, and “Program End” as ESTLCAM has?

Thanks! Sorry about the long post! And maybe I’m just totally confused - it happens y’know.
Mark Z.

If your laser uses PWM as you say then why are you using M42? You can use pin 44 like everyone else is can’t you? That way you can drive the laser with the M106/M107 commands and the post-processor should work. I haven’t used the laser post so maybe Martin can answer your question since he worked on that part of it.

Aha! See I am just confused. Thanks for your reply. Let me look into that.

I really appreciate the quick reply.

Mark Z.

Duh, found the info in your post “The 2.8 watt, $100 Laser
Upgrade for MPCNC” on v1engineering.com. I’m sure I’ve read that article before, but obviously, it didn’t sink in.

Thanks again.

No problem. Even if your laser only responds to full ON/OFF signals and nothing in between, you can still use the PWM pin 44 to control it. It’ll just be M106 S255 for on and M107 for off, which should appear as 0 and 5v to the laser driver, same as your current pin 4 would. That way you can use the post processor as-is and your laser should be timed with the “cut”.

Mark, I really appreciate your feedback about the laser support on the fusion posts processor.

I’m currently writing a posts processor from scratch (just to learn, not because current does not works or has something wrong). I’ll take your suggestions about adding gcode block commands at start, tool change and finish.

About your specific question, just go with Leo’s solution, use M 106/107 and it will be alot easier.

Thanks, Martin DB, I’ve got plans for an add-on that will need some codes on tool changes if my idea works.

I’ve switched over to Leo68’s pin 44 for the laser and M106/7, and the laser is working great!

Thanks all!

Great Mark!