TNC 620 Klartext & Q-Parameters
Klartext is Heidenhain’s conversational programming language: instead of G-code words, an NC block reads like a dialog (L X+10 Y+5 R0 F100 M3). The macro layer is built in — no paid option, no G65. Variables are Q parameters, math and logic are FN functions, and reusable routines are LBL subprograms. This reference covers the TNC 620 (NC software 81760x); everything below is taken from the TNC 620 Klartext Programming manual.
Program Structure
A Klartext program is a numbered list of NC blocks in a .H file (DIN/ISO programs use .I). The first block is always BEGIN PGM with the program name and unit of measure, the last is END PGM. Immediately after BEGIN PGM you normally define the workpiece blank with BLK FORM — needed only for graphic simulation (rectangular MIN/MAX points, cylinder, rotationally symmetric contour in a subprogram, or STL files as blank and finished part).
0 BEGIN PGM NEW MM ; program start, name, unit of measure
1 BLK FORM 0.1 Z X+0 Y+0 Z-40 ; spindle axis, MIN point
2 BLK FORM 0.2 X+100 Y+100 Z+0 ; MAX point
3 L X+10 Y+5 R0 F100 M3 ; a positioning block: line, no comp, feed, M3
4 END PGM NEW MM ; program end
Labels, Subprograms & Repeats
Reusable sections are marked with labels: LBL takes a number from 1 to 65535 or a name of up to 32 characters. LBL 0 is reserved — it marks the end of a subprogram and may appear as often as needed; every other label number/name may be set only once per program.
| Technique | Klartext | Behavior |
|---|---|---|
| Subprogram | LBL 5 … LBL 0, called with CALL LBL 5 | Runs to LBL 0, returns to the block after the call. Place subprograms after M2/M30 — otherwise they execute at least once uncalled. A subprogram cannot call itself. CALL LBL 0 is not permitted. |
| Program-section repeat | LBL 6 … CALL LBL 6 REP2 | Repeats the section between the label and the call REP times (up to 65 534). Total executions = REP + 1, because the first pass already ran. |
| External program call | CALL PGM TNC:\ZW35\HERE\PGM1.H | Runs another NC program start to finish, then returns. The called program must not contain M2/M30 (replace with FN 9: IF +0 EQU +0 GOTO LBL 99) and must not call its caller back. Q parameters stay global across PGM CALL. |
| Dynamic call | SEL PGM … CALL SELECTED PGM | Select a program (string parameters allowed), call it later. Check paths first with FN 18 ID10 NR110/NR111 to avoid mid-run aborts. |
Label names and CALL LBL also accept a QS string parameter as the jump target, which makes table-driven macro dispatch possible.
Q-Parameter Types & Ranges
Four variable families exist. Which numbers you may freely use matters — HEIDENHAIN cycles, OEM cycles, and the control itself claim ranges, and overlaps cause real crashes (the manual carries a collision warning on exactly this point).
| Type | Range | Who owns it | Persistence |
|---|---|---|---|
| Q — numeric, effective in all NC programs in memory | |||
Q0–Q99 | 0–99 | Free for the user if no overlap with HEIDENHAIN SL cycles; local inside macros/OEM cycles | Global, volatile |
Q100–Q199 | 100–199 | Control-preassigned values (tool radius Q108, probe results Q15x…) — read, never write | Global, volatile |
Q200–Q1199 | 200–1199 | HEIDENHAIN cycles | Global, volatile |
Q1200–Q1399 | 1200–1399 | OEM (machine manufacturer) cycles | Global, volatile |
Q1400–Q1999 | 1400–1999 | Free for the user — the safe range | Global, volatile |
| QL — numeric, local | |||
QL0–QL499 | 0–499 | Free for the user | Local to one NC program only |
| QR — numeric, retentive (like Fanuc #500s) | |||
QR0–QR99 | 0–99 | Free for the user | Survive power-off; included in backups |
QR100–QR199 | 100–199 | HEIDENHAIN functions/cycles | |
QR200–QR499 | 200–499 | Machine tool builder | |
| QS — strings, up to 255 characters | |||
QS0–QS1999 | same split as Q | 0–99 free (watch SL-cycle overlaps), 100–199 control, 200–1199 HEIDENHAIN, 1200–1399 OEM, 1400–1999 user | Global, volatile |
Numeric values run from −999 999 999 to +999 999 999 (16 input digits, 9 before the decimal point). Values are IEEE 754 doubles — expect round-off when comparing calculated values in jumps. A parameter can also be Undefined (FN 0: Q5 SET UNDEFINED); a positioning move with an undefined Q parameter is simply ignored. Check and edit live values any time with the Q INFO soft key (ranges 100–199 and 1200–1399 are locked in that window).
Assignments, Arithmetic & Formulas
The basic operations are the numbered FN functions; the FORMULA function accepts full infix expressions in one block. Part-family programming is just FN 0 up front: assign the dimensions, use the parameters in place of numbers (FN 0: Q10 = 25 … L X+Q10).
| Function | Example | Meaning |
|---|---|---|
| Basic arithmetic | ||
FN 0 ASSIGN | FN 0: Q5 = +60 | Assign a value (or SET UNDEFINED) |
FN 1–FN 4 | FN 1: Q1 = -Q2 + -5 | Add / subtract / multiply / divide (division by 0 not permitted) |
FN 5 SQUARE ROOT | FN 5: Q20 = SQRT 4 | Root of a non-negative value |
| Trigonometry & geometry | ||
FN 6 / FN 7 | FN 6: Q20 = SIN-Q5 | Sine / cosine of an angle in degrees |
FN 8 LEN | FN 8: Q10 = +5 LEN +4 | Root sum of squares (hypotenuse) |
FN 13 ANGLE | FN 13: Q20 = +25 ANG-Q1 | Angle from opposite/adjacent (arctan), 0–360° |
FN 23 / FN 24 CDATA | FN 23: Q20 = CDATA Q30 | Circle center + radius from 3 (or 4) probed points; results land in the target parameter and the two following it |
| FORMULA operators (one block, infix) | ||
| Arithmetic | Q1 = 5 * 3 + 2 * 10 | + - * /, parentheses; multiplication/division bind first, powers before that, sign/functions first of all; same priority evaluates left→right (powers right→left) |
| Functions | Q25 = ATAN (Q12/Q13) | SQ SQRT SIN COS TAN ASIN ACOS ATAN ^ PI LN LOG EXP NEG INT ABS FRAC SGN % (modulo) |
Gotcha from the manual: INT truncates — it does not round. To round correctly, add 0.5 × the sign first: Q11 = INT (Q1 + 0.5 * SGN Q1).
If/Then Decisions & Jumps (FN 9–12)
Conditions compare a Q parameter with another parameter or a number; when true, execution jumps to a label. Unlike subprograms, jumps need no LBL 0 and honor no return address — they are pure GOTOs. The jump target can be a label number, a label name, or a QS parameter.
| Function | Example | Jumps if… |
|---|---|---|
FN 9 IF EQUAL | FN 9: IF +Q1 EQU +Q3 GOTO LBL “UPCAN25” | values are equal (always-true variant IF+10 EQU+10 = unconditional jump) |
FN 9 IF UNDEFINED / DEFINED | FN 9: IF +Q1 IS UNDEFINED GOTO LBL 10 | parameter is undefined / defined |
FN 10 IF UNEQUAL | FN 10: IF +10 NE -Q5 GOTO LBL 10 | values differ |
FN 11 IF GREATER | FN 11: IF+Q1 GT+10 GOTO LBL QS5 | first > second |
FN 12 IF LESS | FN 12: IF+Q5 LT+0 GOTO LBL “ANYNAME” | first < second |
The manual’s counter idiom — a Q parameter incremented each pass and compared against the target count:
0 BEGIN PGM COUNTER MM
2 Q1 = 0 ; initialize counter
3 Q2 = 3 ; number of passes
5 LBL 99
6 Q1 = Q1 + 1 ; increment
7 FN 12: IF +Q1 LT +Q2 GOTO LBL 99 ; passes 1 and 2
8 FN 9: IF +Q1 EQU +Q2 GOTO LBL 99 ; pass 3
10 END PGM COUNTER MM
String Processing (QS)
QS parameters hold up to 255 characters and feed variable file names, FN 16 logs, and label targets. Declare with DECLARE STRING QS10 = “Workpiece”, then process:
| Function | Example | Result |
|---|---|---|
Concatenate || | QS10 = QS12 || QS13 || QS14 | Chained string |
TOCHAR | QS11 = TOCHAR ( DAT+Q50 DECIMALS3 ) | Number → string, 3 decimals |
SUBSTR | QS13 = SUBSTR ( SRC_QS10 BEG2 LEN4 ) | 4 characters from position 2 (first char = position 0) |
TONUMB | Q82 = TONUMB ( SRC_QS11 ) | String → number (string must be purely numeric) |
INSTR | Q50 = INSTR ( SRC_QS10 SEA_QS13 BEG2 ) | Position of a substring; if not found, total length is returned |
STRLEN | Q52 = STRLEN ( SRC_QS15 ) | Length; −1 if the parameter is undefined |
STRCOMP | Q52 = STRCOMP ( SRC_QS12 SEA_QS14 ) | 0 identical, ±1 alphabetic order |
SYSSTR | QS1 = SYSSTR( ID10010 NR1 ) | System data as string (program path, tool name, date/time formats, NC software version…) |
CFGREAD | Q50 = CFGREAD( KEY_QS11 TAG_QS12 ATR_QS13 ) | Read a machine parameter (key/entity/attribute defined in QS parameters first) |
FN 14: ERROR — Raising Your Own Alarms
FN 14: ERROR interrupts the program (run or simulation) and displays a message; the program must then be restarted. Error numbers 0–999 show machine-manufacturer dialogs; 1000–1199 are HEIDENHAIN-predefined texts — e.g. 1000 “Spindle?”, 1004 “Range exceeded”, 1092 “Tool not defined”. Classic guard clause before a probing macro:
180 FN 14: ERROR = 1000 ; display "Spindle?" and stop
Preassigned Q Parameters Worth Knowing
The control loads Q100–Q199 itself. The daily drivers: Q108 active tool radius (R + DR from table + DR from program — survives power-off), Q114 active tool length, Q109 tool axis (−1 none, 0=X, 1=Y, 2=Z), Q110 spindle state (0=M3, 1=M4, 2/3=M5), Q111 coolant (1=M8), Q113 unit of the main program (0=mm, 1=inch), Q115–Q119 spindle coordinates at the probe trigger. Probe-cycle results live in Q150–Q183 and Q950+ — see the TNC 620 probing-cycles article for the full table.
Worked Example — Ellipse Macro
Straight from the manual: the ellipse is approximated with short line segments (count in Q7), the contour subprogram runs under a datum shift + rotation, and an FN 12 jump loops until the counter reaches the segment count.
0 BEGIN PGM ELLIPSE MM
1 FN 0: Q1 = +50 ; center X
2 FN 0: Q2 = +50 ; center Y
3 FN 0: Q3 = +50 ; semiaxis X
4 FN 0: Q4 = +30 ; semiaxis Y
5 FN 0: Q5 = +0 ; start angle
6 FN 0: Q6 = +360 ; end angle
7 FN 0: Q7 = +40 ; number of segments
8 FN 0: Q8 = +0 ; rotational position
9 FN 0: Q9 = +5 ; milling depth
10 FN 0: Q10 = +100 ; plunge feed
11 FN 0: Q11 = +350 ; milling feed
12 FN 0: Q12 = +2 ; set-up clearance
13 BLK FORM 0.1 Z X+0 Y+0 Z-20
14 BLK FORM 0.2 X+100 Y+100 Z+0
15 TOOL CALL 1 Z S4000
16 L Z+250 R0 FMAX
17 CALL LBL 10 ; call machining
18 L Z+100 R0 FMAX M2
19 LBL 10 ; subprogram: machining
20 CYCL DEF 7.0 DATUM SHIFT ; shift datum to ellipse center
21 CYCL DEF 7.1 X+Q1
22 CYCL DEF 7.2 Y+Q2
23 CYCL DEF 10.0 ROTATION ; account for rotational position
24 CYCL DEF 10.1 ROT+Q8
25 Q35 = (Q6 - Q5) / Q7 ; angle increment
26 Q36 = Q5 ; copy start angle
27 Q37 = 0 ; set counter
28 Q21 = Q3 * COS Q36 ; X of start point
29 Q22 = Q4 * SIN Q36 ; Y of start point
30 L X+Q21 Y+Q22 R0 FMAX M3
31 L Z+Q12 R0 FMAX
32 L Z-Q9 R0 FQ10 ; to working depth
33 LBL 1
34 Q36 = Q36 + Q35 ; update angle
35 Q37 = Q37 + 1 ; update counter
36 Q21 = Q3 * COS Q36
37 Q22 = Q4 * SIN Q36
38 L X+Q21 Y+Q22 R0 FQ11 ; next point
39 FN 12: IF +Q37 LT +Q7 GOTO LBL 1 ; loop until finished
40 CYCL DEF 10.0 ROTATION ; reset rotation
41 CYCL DEF 10.1 ROT+0
42 CYCL DEF 7.0 DATUM SHIFT ; reset datum shift
43 CYCL DEF 7.1 X+0
44 CYCL DEF 7.2 Y+0
45 L Z+Q12 R0 FMAX
46 LBL 0
47 END PGM ELLIPSE MM
DIN/ISO Equivalents (D Functions)
The same control also runs DIN/ISO programs (.I files), where Q-parameter functions become D functions with positional P01/P02/P03 operands: FN 0–13 map to D00–D13 one to one, labels become G98 L, and calls become L n,m (subprogram: L n,0; repeat m times: L n,m). One comparison:
; Klartext ; DIN/ISO
FN 0: Q5 = +60 N40 D00 Q5 P01 +60*
FN 3: Q12 = +Q5 * +7 N41 D03 Q12 P01 +Q5 P02 +7*
FN 12: IF +Q1 LT +Q2 GOTO LBL 99 N42 D12 P01 +Q1 P02 +Q2 P03 99*
LBL 99 N50 G98 L99*
References
- HEIDENHAIN, TNC 620 Klartext Programming User’s Manual, NC software 81760x-16, 01/2022, ID 1096883-29.
- HEIDENHAIN, TNC 620 ISO Programming User’s Manual, NC software 81760x-16, 01/2022, ID 1096887-29.
Have a question or want to contribute?
Contact us with corrections, additions, or topics you'd like covered.
Get in Touch