Laser Mode - fra589/grbl-Mega-5X GitHub Wiki
Overview
In default Grbl operation, every time a spindle state M3 M4 M5
or spindle speed Sxxx
is altered, Grbl would come to a stop, allow the spindle to change, and then continue because time is needed for a milling machine spindle to change speeds.However, if a laser starts and stops like this for every spindle change, this leads to scorching and uneven cutting/engraving. Laser mode updates the spindle PWM pin instantaneously through each motion without unnecessary stops.
Power Control
When laser mode is enabled, Grbl controls laser power by varying the 0-5V voltage from Spindle PWM Pin. (0V = disabled, 5V = full power. 2.5V ≈ 50% laser power. A compile time option exists to shift this linear model to start at a non-zero voltage.)
Frequency
By default, the spindle PWM frequency is about 1.9kHz. (If a different frequency is required, this may be altered by editing the cpu_map.h
file.)
$32 - Laser mode, boolean
Enabling or disabling Grbl's laser mode is easy. Just alter the $32 Grbl setting.
When enabled, Grbl will move continuously through consecutive G1
, G2
, or G3
motion commands when programmed with a S
spindle speed (laser power).
- To Enable: Send Grbl a
$32=1
command. - To Disable: Send Grbl a
$32=0
command. Operation
M3
Constant Laser Power Mode
- Constant laser power mode simply keeps the laser power as programmed, regardless if the machine is moving, accelerating, or stopped. This provides better control of the laser state. With a good G-code program, this can lead to more consistent cuts in more difficult materials.
- For a clean cut and prevent scorching with
M3
constant power mode, it's a good idea to add lead-in and lead-out motions around the line you want to cut to give some space for the machine to accelerate and decelerate. (CAM implementation) - NOTE:
M3
can be used to keep the laser on for focusing.
M4
Dynamic Laser Power Mode
- Dynamic laser power mode will automatically adjust laser power based on the current speed relative to the programmed rate. It essentially ensures the amount of laser energy along a cut is consistent even though the machine may be stopped or actively accelerating. This is very useful for clean, precise engraving and cutting on simple materials across a large range of G-code generation methods by CAM programs. It will generally run faster and may be all you need to use.
- Grbl calculates laser power based on the assumption that laser power is linear with speed and the material. Often, this is not the case. Lasers can cut differently at varying power levels and some materials may not cut well at a particular speed and/power. In short, this means that dynamic power mode may not work for all situations. Always do a test piece prior to using this with a new material or machine.
- When not in motion,
M4
dynamic mode turns off the laser. It only turns on when the machine moves. This generally makes the laser safer to operate, because, unlikeM3
, it will never burn a hole through your table, if you stop and forget to turnM3
off in time.
Note
- Grbl will move continuously through consecutive motion commands when programmed with a new
S
spindle speed (laser power). The spindle PWM pin will be updated instantaneously through each motion without stopping.- Grbl will enforce a laser mode motion stop in a few circumstances. Primarily to ensure alterations stay in sync with the G-code program.
- Any
M3
,M4
,M5
spindle state change. M3
only and no motion programmed:S
spindle speed changeG1 G2 G3
laser powered state change toG0 G80
laser disabled state.
- NOTE:
M4
does not stop for anything but a spindle state change.
- Any
- Grbl will enforce a laser mode motion stop in a few circumstances. Primarily to ensure alterations stay in sync with the G-code program.
- The laser will only turn on when Grbl is in a
G1
,G2
, orG3
motion mode.- In other words, a
G0
rapid motion mode orG38.x
probe cycle will always disable the laser, but will still update the running modal state. When changed to aG1 G2 G3
modal state, Grbl will immediately enable the laser based on the current running state.
- In other words, a
- An
S0
spindle speed of zero will turn off the laser. When programmed with a valid laser motion, Grbl will disable the laser instantaneously without stopping for the duration of that motion and future motions until set greater than zero.M3
constant laser mode, this is a great way to turn off the laser power while continuously moving between aG1
laser motion and aG0
rapid motion without having to stop. Program a shortG1 S0
motion right before theG0
motion and aG1 Sxxx
motion is commanded right after to go back to cutting.
CAM Developer Implementation Notes
- When using
M3
constant laser power mode, try to avoid force-sync conditions during a job whenever possible. Basically every spindle speed change must be accompanied by a valid motion. Any motion is fine, since Grbl will automatically enable and disable the laser based on the modal state. Avoid aG0
andG1
command with no axis words in this mode and in the middle of a job. - Ensure smooth motions throughout by turning the laser on and off without an
M3 M4 M5
spindle state command. There are two ways to do this:- Program a zero spindle speed
S0
:S0
is valid G-code and turns off the spindle/laser without changing the spindle state. In laser mode, Grbl will smoothly move through consecutive motions and turn off the spindle. Conversely, you can turn on the laser with a spindle speedS
greater than zero. Remember thatM3
constant power mode requires any spindle speedS
change to be programmed with a motion to allow continuous motion, whileM4
dynamic power mode does not. - Program an unpowered motion between powered motions: If you are traversing between parts of a raster job that don't need to have the laser powered, program a
G0
rapid between them.G0
enforces the laser to be disabled automatically. The last spindle speed programmed doesn't change, so if a valid powered motion, like aG1
is executed after, it'll immediately re-power the laser with the last programmed spindle speed when executing that motion.
- Program a zero spindle speed