Skip to main content
CNC.wiki

Rigid Tapping on Siemens Sinumerik: G331 and G332 Programming

Learn to program rigid tapping on Siemens Sinumerik controllers using G331 and G332. Avoid common alarms like 14092 and 22024 with these expert CNC tips.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

Introduction

A sudden state change in the NC/PLC interface signal DB380x DBX2001.6 ("invert M3/M4") while a tapping tool is actively cutting inside a workpiece immediately triggers a catastrophic tool break. This unexpected interruption halts the Sinumerik spindle rotation while the linear axis continues feeding, leaving a sheared carbide tap lodged in the metal and rendering the part scrap. Operators are left with a machine stoppage, damaged workholding, and a wasted setup.

To address these critical synchronization challenges, Siemens controllers use G331 and G332 commands to execute closed-loop, position-controlled rigid tapping. Rather than relying on a mechanical compensating chuck, the controller strictly interpolates the linear axis motion and spindle rotation. This ensures the thread pitch matches the programmer's specification exactly, preventing pitch deviations and reducing machining failures.

Technical Summary

PropertyDetails
Command CodeG331 (Tapping), G332 (Retraction)
Modal GroupRigid Tapping Cycles / Interpolation Motion (Modal)
Supported BrandsSiemens
Critical ParametersAxis coordinate (X, Y, Z) and Thread pitch (I, J, K)
Main ConstraintRequires spindle position encoder, closed-loop position-controlled mode via SPOS, and active linear feedrate mode G94.

Quick Read

  • Execute SPOS First: Run the spindle positioning command SPOS in a block preceding G331 to place the spindle into closed-loop position control and avoid Alarm 14092.
  • Activate Linear Feedrate: Program linear feedrate mode G94 prior to G331/G332 execution to prevent the spindle-not-in-standstill error and Alarm 16715.
  • Automatic Rotation Direction: Control the spindle direction automatically by configuring the mathematical sign of the thread pitch parameter K (positive for right-hand threads, negative for left-hand threads).
  • Match Gear Stages: Match your programmed speed S with the active gear stage thresholds to prevent cycle aborts and Alarm 16748.
  • Suppress Interface Alarms: Set machine data parameter MD35035 bit 22 to suppress the PLC's "invert M3/M4" evaluation and avoid Alarm 22024 during cutting.
  • Restore Position Control: Use SPOS=IC(0) in MDA mode to restore spindle position-control before running G332 recovery after a system power-off.

Basic Concepts

The Siemens G331 and G332 commands execute closed-loop, position-controlled rigid tapping without the mechanical assistance of a compensating chuck. The practical programming effect is that the linear axis traversing motion and the spindle rotation are strictly interpolated together to precisely match the desired thread pitch. Programmers must watch vigilantly to ensure the master spindle is explicitly placed into position-controlled mode (using the SPOS command) before invoking G331; failing to do so immediately triggers alarm code 14092 and aborts the cycle.

Operators must also monitor system states carefully, particularly during recovery operations. For example, if executing a tapping retraction in MDA mode after a complete system power-off, operators must first enable the spindle via SPOS=IC(0) before running G332, or the control will block the recovery. Additionally, if the NC/PLC interface signal "invert M3/M4" is inadvertently toggled while the tap is engaged, the control immediately halts the process and outputs alarm code 22024 to proactively prevent a catastrophic tool break inside the workpiece, which would otherwise result in a scrap part. Extra care must be taken in multi-axis environments, such as machines operating a double turret, to ensure spindle states and feed modes (G94) are properly synchronized.

Command Structure

The Sinumerik rigid tapping syntax is structured around two distinct operational commands: G331 for cutting the thread into the workpiece, and G332 for reversing the spindle and retracting the tool. These commands require the programmer to define the target coordinate and the thread pitch along the axis of movement. The spindle speed is set during the G331 block, whereas the subsequent G332 block retains the speed and automatically handles the axis reversal.

Programming can be completed using either axis-specific names and thread pitches or Cartesian coordinates. For standard single-axis moves, the command references the coordinate name and the corresponding pitch parameter. If the pitch value is positive, a right-hand thread is generated; if negative, a left-hand thread is cut.

G331 <axis> <thread pitch> S...
G332 <axis> <thread pitch>
G331 X... Y... Z... I... J... K... S...
G332 X... Y... Z... I... J... K...
ParameterDescriptionPermissible Range
<axis> / X..., Y..., Z...Geometry axis coordinate or traversing distance at the end of the thread (final drilling depth).Absolute or incremental coordinates
<thread pitch> / I..., J..., K...Thread pitch. Positive pitch specifies right-handed thread (clockwise, M3), negative pitch specifies left-handed thread (counter-clockwise, M4).±0.001 to ±2000.00 mm/rev
S...Spindle speed in rpm. Optional parameter. If omitted, the last active speed is used.Spindle speed in rpm

Brand Applications

Siemens

Siemens Sinumerik controls utilize G331 and G332 to command rigid tapping without the aid of a compensating chuck. Programmers must ensure the spindle is in position control prior to calling G331. The spindle positioning command SPOS serves this purpose by establishing the initial position control loop. A failure to execute this command prior to G331 results in the NC program halting and generating Alarm 14092. The control also checks for linear feedrate mode, requiring G94 to be active before starting the tapping block.

Several machine data parameters configure the safety and mechanical properties of the tapping cycle. The parameter MD35035 $MA_SPIND_FUNCTION_MASK bit 22 controls whether the NC/PLC interface signal DB380x DBX2001.6 ("invert M3/M4") is evaluated. Setting this bit to 1 prevents the safety alarm from triggering, allowing the machine to ignore external inversion commands during G331/G332. Additionally, the machine parameter MD35010 $MA_GEAR_STEP_CHANGE_ENABLE bit 5 activates a dedicated second gear-stage data block, providing unique minimum and maximum speed switching thresholds specifically for rigid tapping operations.

Brand Comparison

System SeriesSpindle Position ControlGear Stage ManagementPLC Inversion Safety
Sinumerik 840D slFully supported via SPOS; supports recovery in MDA mode using SPOS=IC(0).Dedicated second gear-stage data block (MD35010 bit 5) fully configurable.Full suppression configuration available via MD35035 bit 22.
Sinumerik 828DSupported via SPOS; standard recovery procedures apply.Supports gear stage thresholds with simplified data blocks.Inversion safety evaluation active; configurable via machine data.
Sinumerik 808DSupported via SPOS; requires position encoder.Basic gear stage control; secondary gear-stage data blocks are generally not supported.Evaluates DB380x DBX2001.6 with limited customization options.

Technical Analysis

Siemens polar coordinate programming and rigid tapping interpolation are mathematically isolated from standard path coordinates. In tapping, Siemens exhibits several behaviors during rigid tapping that most clearly distinguish it from other control brands. First, Siemens relies entirely on the mathematical sign of the programmed thread pitch (e.g., a positive K for right-hand threads or a negative K for left-hand threads) to automatically dictate the spindle's direction of rotation. This completely eliminates the need to program explicit M3 or M4 rotation commands within the tapping cycle itself. Second, Siemens provides a dedicated "second gear-stage data block" evaluated specifically for G331/G332. This allows the machine to apply independent minimum and maximum speed switching thresholds tailored strictly for tapping, maximizing motor torque and acceleration without hitting electrical current limits. Third, Siemens incorporates an advanced safety stop-response configuration via MD11550 $MN_STOP_MODE_MASK. This allows programmers to define an implicit stop delay area that actively prevents the machine from halting mid-cut during G331 and G332 operations—even if continuous path mode is interrupted or a dwell time is encountered—safely preventing the tap from seizing in the material.

On the high-end Sinumerik 840D sl, the secondary gear-stage block (activated via MD35010 bit 5) is fully optimized for custom spindle acceleration curves. The 828D compact systems run simplified versions of these data blocks, which still prevent current overload but restrict fine-tuning. The basic 808D relies on standard gear ranges, making speed matching more critical for operators to avoid speed-matching faults.

Program Examples

N10 G94 ; Ensure linear feedrate mode is active
N20 SPOS=0 ; Position the spindle to enable closed-loop position control
N30 G331 Z-50 K-4 S200 ; Tapping down to Z-50, pitch -4mm (left-hand), spindle speed 200 rpm
N40 G332 Z3 K-4 ; Retracting to Z3, pitch -4mm, automatic spindle reversal
N50 SPOS=0 ; Reset spindle position control
N60 G331 Z-10 K5 S800 ; Tapping down to Z-10, pitch 5mm (right-hand), spindle speed 800 rpm
N70 G332 Z3 K5 ; Retracting to Z3, pitch 5mm, automatic spindle reversal

Dry Run Execution Walkthrough:

dry run: Running this program without a workpiece or tool installed allows the operator to observe the mechanical cycle. In block N10, the linear feedrate mode G94 is set, which is mandatory for rigid tapping. In block N20, the spindle executes SPOS=0, placing it under closed-loop position control. At block N30, the Z-axis feeds downward to -50 mm while the spindle rotates counter-clockwise (corresponding to the negative pitch K-4) at 200 rpm. Once Z-50 is reached, block N40 immediately initiates G332 retraction, causing the spindle to reverse direction and rotate clockwise while feeding the Z-axis back up to coordinate Z3. Block N50 resets the position control. Block N60 begins tapping a second thread, feeding the Z-axis down to -10 mm while the spindle rotates clockwise at 800 rpm (specified by positive pitch K5). Finally, block N70 commands retraction back to Z3, reversing the spindle counter-clockwise.

Error Analysis

SystemAlarm CodeTrigger ConditionFix / Operator Action
Siemens SinumerikAlarm 14092Master spindle is not in position-controlled mode (missing SPOS), spindle lacks encoder, or tapping retraction in MDA mode after power-off is attempted without SPOS=IC(0).Program SPOS before G331 or execute SPOS=IC(0) in MDA mode to recover position control.
Siemens SinumerikAlarm 16715G331 or G332 is active but linear feedrate mode G94 has not been explicitly programmed.Explicitly program G94 in a block preceding the G331 command.
Siemens SinumerikAlarm 16748Programmed spindle speed lies outside the speed range of the active gear stage, and dynamic stage change is disabled.Load the appropriate gear stage in the NC program prior to the G331 block.
Siemens SinumerikAlarm 22024NC/PLC interface signal DB380x DBX2001.6 ("invert M3/M4") is altered during program execution while G331 is active.Prevent PLC signal changes during cutting, or configure MD35035 bit 22 to 1 to suppress the safety check.

Application Note

A sudden toggle of the NC/PLC interface signal DB380x DBX2001.6 during execution immediately triggers Alarm 22024, halting the G331 cycle to prevent a catastrophic tool break in the workpiece. Operators must avoid manual or PLC-driven alterations to this safety signal while cutting is in progress. If a power outage occurs mid-cut, the operator must switch to MDA mode and execute SPOS=IC(0) to enable the spindle's position-controlled mode before attempting a retraction via G332. This recovery procedure prevents the Z-axis from feeding without spindle synchronization, which would strip the cut thread or break the tool.

Related Command Network

  • G84 / G74 (Rigid Tapping): These canned cycles automate tapping on various controls, contrasting with the direct G331/G332 interpolation blocks.
  • CYCLE84 / CYCLE99 (Siemens Threading Cycles): These Sinumerik canned cycles wrap G331/G332 commands in high-level parameters for easier programming.
  • G62 / G63 (Corner Override and Tapping): G63 performs tapping with a compensating chuck, bypassing closed-loop encoder interpolation entirely.
  • SPOS (Spindle Positioning): Positions the spindle and engages closed-loop control, a mandatory prerequisite before invoking a G331 block.
  • G94 (Linear Feedrate): Activates feedrate in millimeters per minute, which must be active for G331/G332 execution.

Conclusion

Successful G331 and G332 rigid tapping relies on proper spindle synchronization and careful configuration of machine parameters. Always ensure G94 feedrate mode and SPOS spindle position control are active before invoking the tapping cycle. Managing safety parameters like MD35035 bit 22 and matching spindle speeds with active gear stages ensures continuous operation and prevents tool damage.

Frequently Asked Questions (FAQ)

Why does G331 trigger Alarm 14092 "wrong axis type" even if a spindle encoder is installed?

This alarm indicates that the spindle has not been placed in position-controlled mode before the G331 cycle starts. To resolve this, program an SPOS command in the block immediately preceding the G331 command, or execute SPOS=IC(0) in MDA mode if recovering from a system power-off.

How does the controller determine the rotation direction for G331 tapping?

Siemens controls determine rotation direction automatically using the mathematical sign of the programmed thread pitch (K, I, or J). Program a positive pitch for right-hand threads (clockwise) and a negative pitch for left-hand threads (counter-clockwise) to eliminate the need for M3 or M4 commands.

What causes Alarm 22024 during tapping and how can it be avoided?

This alarm occurs when the NC/PLC interface safety signal DB380x DBX2001.6 ("invert M3/M4") changes during an active G331 block. To prevent this, ensure the PLC does not toggle safety signals while cutting, or set machine data parameter MD35035 bit 22 to 1 to suppress this safety evaluation.

Still not resolved?

Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • CNC CARE Co-Founder (May 2025 - Present)
  • Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
  • Reis CNC Service Engineer (2003 - 2005)
  • Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)

With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.

Related Articles

Other articles on this topic