Back to Supported G-Codes

M3, M4, M5 - Spindle Control Commands

DMC File Mode: Not Supported
Streaming Mode: Supported

Description

The M3, M4, and M5 commands control spindle operation in CNC machines.

  • M3 - Starts the spindle rotating clockwise at a specified speed
  • M4 - Starts the spindle rotating counter-clockwise at a specified speed
  • M5 - Stops the spindle completely

Important: Before using any spindle commands (M3, M4, M5), you must first call theConfigureSpindle()method to configure the DMC axis that controls the spindle and set the counts per revolution conversion factor.

Motor Direction: M3 will command a positive spindle jog and M4 will command a negative spindle jog. The direction the spindle motor moves when given a positive or negative jog is dependent on motor/encoder wiring, as well as motor parameters set. The motor must be configured so a positive jog causes clockwise rotation, and a negative jog causes counter-clockwise rotation.

The implementation of M3, M4, and M5 assumes that if using a servo motor, an encoder is being used and is wired to the controller. If the spindle is commanded with an open loop analog signal, contact Galil.

Syntax

M3 S<speed>
M4 S<speed>
M5

Parameters

ParameterDescriptionExample
SSpindle speed in RPM (M3 and M4 only)S1000

Note: If the S parameter is not provided with M3 or M4, the most recently specified S value will be used.

Examples

Basic Spindle Control

; Start spindle at 1000 RPM clockwise
M3 S1000
; Perform machining operations...
G1 X10 Y10 F500
; Stop spindle when finished
M5

Counter-Clockwise Operation

; Start spindle counter-clockwise for left-hand threading
M4 S800
; Perform threading operation
G1 X5 Z-10 F200
M5

Spindle Speed Changes

; Start at low speed for initial approach
M3 S500
G1 X0 Y0 F300
; Increase speed for cutting operation
M3 S1500
G1 X20 Y20 F800
M5