Skip to content

M4 (dynamic/rate-adjusted) laser power not zeroed on G0 block immediately following a rate-adjusted G1 block #1002

Open

Description

@Alijambo

Title

M4 (dynamic/rate-adjusted) laser power not zeroed on G0 block immediately following a rate-adjusted G1 block

Environment

Description

With $32=1 (laser mode) and a spindle driven via PWM (update_pwm/get_pwm, QuadTimer-based on this driver), issuing M4 once at the start of a job and then alternating G1 (cut, with S value) / G0 (travel) blocks — the standard pattern for LightBurn's "dynamic power" / automatic G0-suppression mode — the laser does not reliably turn off during G0 travel moves that immediately follow a rate-adjusted G1 cut. It stays on, apparently outputting whatever PWM duty the previous cut's velocity-scaled power last computed to, until the next G1 re-establishes power.

This is fully reproducible and confirmed independent of hardware: multimeter checks confirm no floating-pin issue on the laser's TTL input (deliberate ~1k pull-down present on all three input options on the adapter board), and the exact same G-code/job run through the GRBL-M3 device profile (explicit per-segment M3/S0/M5, no dynamic power) behaves correctly — laser reliably off during every travel move. Switching purely between the GRBL/M4 and GRBL-M3 device profiles, with no other change, reproduces/resolves the symptom every time.

Steps to Reproduce

  1. $32=1 (laser mode), PWM spindle with update_pwm/get_pwm set (QuadTimer/iMXRT1062 driver, spindleSetStateVariable/spindleSetSpeed per driver.c).
  2. Send M4 once.
  3. Send a G1 move with axis words and an S value large enough to be clearly visible (e.g. G1 X10 S16800 F1000).
  4. Immediately follow with a G0 travel move with axis words and no S word (S is sticky/modal from the prior line), e.g. G0 X5 Y5.
  5. Observe laser output during step 4.

Expected Behavior

Per motion_is_lasercut() (gcode.c), G0 is never a lasercut motion, so laser_disable is set and plan_data.spindle.rpm is planned as 0.0f for the block regardless of the modal S value. stepper.c:1080-1081 additionally forces sys.step_control.update_spindle_rpm on for every new block when cap.laser is set, which should force a fresh RPM-and-PWM recompute at the very start of the new G0 block, overriding whatever the previous G1 block's dynamic-power segments last commanded.

Actual Behavior

Laser output continues at (or near) the level from the end of the preceding G1 block's dynamic-power ramp, through the G0 travel move, until the next G1 block re-establishes commanded power.

Analysis / What's Been Ruled Out

  • Not a hardware/wiring issue. Laser TTL input confirmed pulled down (~1k) with board unpowered; PSU power-up sequencing in Start G-code was reordered (mode/RPM settings established before power-up) with no change in behavior.
  • Not the previously-fixed M3-in-G0/G80 issue (Unexpected Laser Behaviour #644). That fix (e8a0aee) is already present; also, our reproduction is specific to M4/CCW (is_rpm_rate_adjusted) blocks, not stationary M3 S<n> commands.
  • Not a PWM-timer stale-duty-register issue at settings-change time. We independently found and fixed a real, separate bug where spindleConfig() (driver.c) re-arms the QuadTimer's compare mode via pwm_config() without resetting the duty register, causing spurious full-power output on any $30/$31/$32 write. That fix is unrelated to this issue — this M4/G0 symptom persists after that fix, with no $-setting writes involved during the run at all.
  • Parser-level logic traced and appears correct, per the code reading above (gcode.c laser_disable/is_rpm_rate_adjusted computation, stepper.c dynamic_rpm per-block flag and the update_spindle_rpm |= cap.laser force-update at block start). We could not identify a structural gap through static code reading alone; this looks like it may be a timing-sensitive issue in the stepper ISR at the G1(dynamic)→G0(non-dynamic) block boundary, which is difficult to confirm without a live debugger/oscilloscope on the PWM output.

Additional Context

Given the safety implications of a laser that doesn't reliably turn off during rapid moves, we are not currently using M4/dynamic power for real jobs and have reverted to M3 (constant power, explicit per-segment on/off), which is fully confirmed reliable. Happy to provide the full reproduction G-code file, run further tests, or add temporary debug instrumentation if that would help pin down the exact point of failure in the stepper ISR.

Activity

  1. terjeio commented on Aug 13, 2026

    @terjeio
    Contributor

    aCtual bEhaviour:

    Works as intended.

    aDittional cOntext:

    Tested on real hardware, version and settings:

    %
    ;
    ; 2026-08-13T06:22
    ;
    ; grblHAL
    ; 1.1f.20260811
    ; [OPT:VNMSL,100,1024,3,4]
    ; [NEWOPT:ENUMS,RT+,ES,REBOOT,EXPR,ATC=1,SED,RTC,YM,SD]
    ; [FIRMWARE:grblHAL]
    ; [NVS STORAGE:*FLASH 16K]
    ; [FREE MEMORY:88K]
    ; [DRIVER:STM32F446@180MHz]
    ; [DRIVER VERSION:260729]
    ; [BOARD:Nucleo-64 CNC Breakout]
    ; [AUX IO:6,2,0,0]
    ; [CLUSTER:16]
    ; [PLUGIN:LightBurn clusters v0.07]
    ; [PLUGIN:FS stream v1.14]
    ; [PLUGIN:FS macro plugin v0.24]
    ; [PLUGIN:Tool table v0.04]
    ; [PLUGIN:SDCARD v1.28]
    ;
    $N0=
    $N1=
    ; 0 - Step pulse time
    $0=5.0
    ; 1 - Step idle delay
    $1=25
    ; 2 - Step pulse invert
    $2=0
    ; 3 - Step direction invert
    $3=0
    ; 4 - Invert stepper enable output(s)
    $4=7
    ; 5 - Invert limit inputs
    $5=0
    ; 6 - Invert probe inputs
    $6=0
    ; 9 - PWM spindle options
    $9=1
    ; 10 - Status report options
    $10=511
    ; 11 - Junction deviation
    $11=0.010
    ; 12 - Arc tolerance
    $12=0.002
    ; 13 - Report in inches
    $13=0
    ; 14 - Invert control inputs
    $14=0
    ; 15 - Invert coolant outputs
    $15=0
    ; 16 - Invert spindle signals
    $16=0
    ; 17 - Pullup disable control inputs
    $17=0
    ; 18 - Pullup disable limit inputs
    $18=0
    ; 19 - Pullup disable probe inputs
    $19=0
    ; 20 - Soft limits enable
    $20=0
    ; 21 - Hard limits enable
    $21=0
    ; 22 - Homing cycle
    $22=0
    ; 23 - Homing direction invert
    $23=0
    ; 24 - Homing locate feed rate
    $24=25.0
    ; 25 - Homing search seek rate
    $25=500.0
    ; 26 - Homing switch debounce delay
    $26=250
    ; 27 - Homing switch pull-off distance
    $27=1.000
    ; 28 - G73 Retract distance
    $28=0.100
    ; 29 - Pulse delay
    $29=0.0
    ; 30 - Maximum spindle speed
    $30=1000.000
    ; 31 - Minimum spindle speed
    $31=0.000
    ; 32 - Mode of operation
    $32=1
    ; 33 - Spindle PWM frequency
    $33=5000
    ; 34 - Spindle PWM off value
    $34=0.0
    ; 35 - Spindle PWM min value
    $35=0.0
    ; 36 - Spindle PWM max value
    $36=100.0
    ; 37 - Steppers to keep enabled
    $37=0
    ; 39 - Enable legacy RT commands
    $39=1
    ; 40 - Limit jog commands
    $40=0
    ; 41 - Parking cycle
    $41=0
    ; 42 - Parking axis
    $42=2
    ; 43 - Homing passes
    $43=1
    ; 44 - Axes homing, first phase
    $44=4
    ; 45 - Axes homing, second phase
    $45=3
    ; 46 - Axes homing, third phase
    $46=0
    ; 56 - Parking pull-out distance
    $56=5.0
    ; 57 - Parking pull-out rate
    $57=100.0
    ; 58 - Parking target
    $58=-5.0
    ; 59 - Parking fast rate
    $59=500.0
    ; 60 - Restore overrides
    $60=0
    ; 61 - Safety door options
    $61=0
    ; 62 - Sleep enable
    $62=0
    ; 63 - Feed hold actions
    $63=3
    ; 64 - Force init alarm
    $64=0
    ; 65 - Probing options
    $65=0
    ; 100 - X-axis travel resolution
    $100=250.000
    ; 101 - Y-axis travel resolution
    $101=250.000
    ; 102 - Z-axis travel resolution
    $102=250.000
    ; 110 - X-axis maximum rate
    $110=500.000
    ; 111 - Y-axis maximum rate
    $111=500.000
    ; 112 - Z-axis maximum rate
    $112=500.000
    ; 120 - X-axis acceleration
    $120=10.000
    ; 121 - Y-axis acceleration
    $121=10.000
    ; 122 - Z-axis acceleration
    $122=10.000
    ; 130 - X-axis maximum travel
    $130=200.000
    ; 131 - Y-axis maximum travel
    $131=200.000
    ; 132 - Z-axis maximum travel
    $132=200.000
    ; 370 - Invert I/O Port inputs
    $370=0
    ; 372 - Invert I/O Port outputs
    $372=0
    ; 384 - Disable G92 persistence
    $384=0
    ; 392 - Spindle on delay
    $392=4.0
    ; 393 - Coolant on delay
    $393=1.0
    ; 394 - Spindle on delay
    $394=0.0
    ; 398 - Planner buffer blocks
    $398=100
    ; 481 - Autoreport interval
    $481=0
    ; 484 - Unlock required after E-Stop
    $484=1
    ; 485 - Keep tool number over reboot
    $485=0
    ; 486 - Lock coordinate systems
    $486=0
    ; 534 - Output NGC debug messages
    $534=0
    ; 539 - Spindle off delay
    $539=0.0
    ; 650 - File systems options
    $650=0
    ; 673 - Coolant on delay
    $673=0.0
    ; 675 - Macro ATC options
    $675=0
    ; 676 - Reset actions
    $676=15
    ; 680 - Stepper enable delay
    $680=0
    ; 700 - Subroutine options
    $700=0
    %
    

    aNalysis:

    Likely not a core issue, could be a driver issue or incorrect setting(s) - $9?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions