Skip to content

Building NC Controls

About Building NC Controls

In general, the Machine/Control tab > Control menu features (Word Format, G-Code Processing, Control Settings, and Control Advanced Options), located in the lower portion of the Configuration menu pull-down, are used to define how the NC control on a machine processes machine code data, also known as "G-Code" data.

As delivered from Vericut, Vericut supports processing M and G-Code data in EIA Std RS-274 format, as well as some conversational formats. However, using Vericut's powerful user interface or the C Macro Extension – Application Programming Interface, or CME–API (ref. CME-API in the Vericut Development Tools section, in the Vericut Help Library), you can add support for non-standard codes and formats.

All control-related information is saved in a Control file where it can be coupled with other machines having the same, or similar, NC control characteristics.

The following sections provide a general overview of the control building process, and describe key terms you will find throughout related documentation.

Defining G-Code words and special characters:

The G-Code words and special characters interpreted by the NC control are defined in Vericut using the Word Format window features. Use features on this window to describe the general functionality of the character or word. In the case of words that are expected to be paired with addresses later, such as: G0 - "G" with "0", M3 - "M" with "3", "X" with any number, etc., features on this window set the type and format of the expected values.

See Word Format window section of Vericut Help for additional information.

Grouping words with addresses to perform actions:

Words and a range of addresses are paired, or "grouped" using the G-Code Processing window features. Each group can then be configured to perform one or more actions via configuring them to call Vericut supplied or custom macros. For example to simulate "M0" stopping the NC machine, you would define the group as having the "M" word with "0" for the range of addresses that perform this action, then configure the group to call the "StopProgram" macro.

"Conditional" checks can be made to check for conditions that alter how the word/address is interpreted, such as other codes in the block, current variable values, machine states, etc. For example, "X" with a value is typically assumed to be X-axis motion. However, with "G4" also in the block, the control may need to interpret the "X" word/value as "dwell time".

Groups that perform similar actions are arranged in a class, formerly known as a "super group". Classes assist Vericut with determining the timing of when actions are performed, as described by sections that follow.

As delivered from Vericut, macros are provided to simulate most common machine and control actions. Macro actions can be altered, or new macros created using the C Macro Extension – Application Programming Interface, or CME–API (ref. CME-API in the Vericut Development Tools section, in the Vericut Help Library) to generate a custom CME file for the control.

When called by a word/address group, macros are passed the following pieces of information:

  1. The G-Code word is passed as a character string (e.g. "G", "M", "X", "GOTO")

  2. The value associated with the G-Code word is passed as a numeric value (e.g. 1, 30, 12.345, 1234)

  3. The value associated with the G-Code word is also passed as a character string (e.g. "01", "30", "12.345", "1234")

Two of the above three items can be over-ridden before being passed via the features: Override Value (overrides #2 above) and Override Text (overrides #3 above). Additionally, the "value passed as a value" can be modified via the Override Value text field using a mathematical expression. When doing so, the current value is represented using a dollar sign ("$"). For example, Override Value: $*2, multiplies the current value by 2, then passes modified value to the macro. Not all macros honor the override value or text.

See G-Code Processing window section of Vericut Help for additional information.

Also see Vericut Macros in the Vericut Help Library for more information.

Controlling the timing of simulated actions:

The timing of simulated actions is controlled by the following:

  1. The listed order of word/address classes controls the timing of when corresponding actions are performed.

  2. For all actions associated with groups in a given class, the order in which they appear in the G-Code data block controls the timing of when the actions are simulated.

Control settings:

Features in the Control Settings window provide an easy way to set the typical operation mode of the NC control. Control settings are primarily used to establish default conditions for the control. However, these functions also extend your ability to detail how Vericut interprets specific types of machine codes, such as: circles, cycles, rotary motions, and more.

See Control Settings window section of Vericut Help for additional information.

Advanced control options:

The features in the Advanced Control Options window provide even more NC control capabilities, such as: specify subroutines available in the NC control, perform actions at key processing events (e.g. start of tool path processing, start processing a block, etc.), substitute text strings, and more. Most users do not need these advance features, but when you need them, they are there waiting for you.

See Advanced Control Options window section of Vericut Help for additional information.

"Starter" Control files:

A "starter" set of Control files are included in the library files installed with Vericut ("library" folder in your Vericut installation) and can be used as is, or quickly modified to match the exact requirements of your NC machine control.

See the Library Control Files section of Vericut Help.

Also see the Machine and Control Configuration training sessions, in the Training Sessions section in the Vericut Help Library for more information about building NC Controls.

About Simulating Subroutines

Subroutines, or "subs" for short, can exist within a G-Code NC program file or reside in separate files. Vericut supports processing subs in either location. This section discusses mainly subroutines that reside in external files.

Types of subroutines

Vericut recognizes two types of external subroutines, "control" subroutines and "job" subroutines. Subroutines are handled differently, depending on the subroutine type. Each of these types is described below.

Control subroutines — The concept of a "control" subroutine is a subroutine that would typically reside in the NC control. These subroutines are typically not accessible to NC programmers and do not change from job to job. They are well defined, and thoroughly debugged pieces of software. You are typically not interested in stepping through these subroutines. For example: A G81 drill cycle. Here, you don't want to step through the logic of a G81 drill cycle every time it is called, you just want the drill cycle to be executed.

Within Vericut, any subroutines listed in the Advanced Control Options: Subroutines tab File Names list are "control" subroutines and will behave in this manner. When you single step, the entire subroutine will be executed, and the display within the NC Program panel will not jump into the subroutine.

At times, you might want to step into a control subroutine. Vericut now supports an easy mechanism to do this. If you right-click on the (Step/Subroutine Options) button, 3 new buttons will display. (Step Into Subroutine), (Step Over Subroutine), and (Step to End of Subroutine). The "Step Into Subroutine" button will allow you to step into control subroutines. The "Step to End of Subroutine” button is a convenient way to step to the end of the current subroutine.

💡 Tip: Position the cursor over the buttons and a tip appears to remind you of each button’s function.

📝 NOTE: The cursor within NC Program panel displays that last record that was executed. Therefore if you want to step into a control subroutine, you must position yourself on the line prior to the call to the control subroutine, and then press the "Step Into Subroutine" button.

Use the (Control Advanced Options) icon in the Toolbar, or Machine/Control tab > Control Advanced Options in the Vericut menu ribbon, to display the Advanced Control Options window, then click on the Subroutines tab to review, or modify, the list of "control subroutine" file names that Vericut can access.

Job subroutines — Job subroutines are user written subroutines that may exist after the end of the main program, or in a separate file. When you hit the (Step/Subroutine Options) button, you want to step into these subroutines.

Processing within a job subroutine is user controlled, just like the main NC program file. Each record in the subroutine is processed individually, enabling you to "single step" through each record before the return to the calling program. The subroutine call and all other job subroutine records can be seen in the Info tab > NC Program panel (ref. NC Program panel in the Info tab section of Vericut Help), and may appear in Vericut's Log files.

Job subroutines are displayed in the Project Tree, NC Subroutines branch. See NC Subroutines Branch and Configure NC Subroutines menu in the Project Tree section of Vericut Help for additional information.

📝 NOTE: You should never list a file as both a NC Program and a NC Subroutine.

Processing subroutines

Vericut can access subroutines and execute the commands they contain when configured to do so. For subroutines to be processed correctly, Vericut must be set up to "scan the NC program" for branch locations. Make sure that the Scan NC Program Files feature, on the Project Tree, Configure Setup menu: G-Code tab, is toggled "on" (checked).

When a subroutine call is encountered, Vericut searches the following locations (in the order listed) to find a matching branch location:

  1. Search the remainder of the current NC program file.

  2. If not found, search external subroutines in files listed in the Project Tree, NC Subroutines branch. See NC Subroutines Branch and Configure NC Subroutines menu in the Project Tree section of Vericut Help for additional information.

  3. If not found, search external subroutines in files listed on the Machine/Control tab > Machine Settings window: Subroutines tab.
  4. If still not found, search external subroutines in files listed on the Machine/Control tab > Control Advanced Options: Subroutines tab.

Vericut will branch to the first location found to match that specified in the call. If a matching branch location is not found in the main program or any of the subs, an error message is issued.

One subroutine can call another, known as "nesting" subroutines. Up to 25 levels of calling subs are supported.

Hint: Debug messages can be output about calls made to subs during processing via the Debug Loop Logic feature in the Debug group of the Settings window: G-Code Outputs tab (Project menu > Settings > G-Code Outputs tab).

See Settings window: G-Code Outputs tab section of Vericut Help for more information.

Subroutine development tools

Two subroutine development tools are available to assist in creating "custom" MCD subroutines that can be used with "master" control files, to provide "specialized" functionality, while minimizing the need for many "customized" control files.

CGTECH_MACRO

CGTECH_MACRO "macroname" "text value" value

CGTECH_MACRO is a special keyword which is recognized by Vericut while parsing an NC Program file. This keyword is used to call a macro directly without going through the Word Format or Words/Address logic. Currently, this functionality does not support the "Scan" or "After Motion" options. It is also not supported for CMS macros.

The CGTECH_MACRO keyword does not appear in either the Word Format, or the Word/Address, window. For simplicity sake, it always expects 3 arguments: The macroname, the text value that will be passed to the macro, and the numeric value. The first 2 arguments, macroname and text value, must be enclosed in double quotes. Value can be entered either as a number or as an expression. Each of the arguments is separated by a blank space as shown above.

The CGTECH_MACRO keyword can be combined with macros IfCheck and GotoJump to produce a control independent IF statement. In this case the value must be a logical expression using a logical operator (<, <=, >, >=, ==, or <>).

In the following example, the "GotoJump" will jump to block 3000 if the value of variable 3 is less than or equal to 25.

CGTECH_MACRO "IfCheck" "" #3 <= 25

CGTECH_MACRO "GotoJump" "" 3000

In the following example an indirect variable is used. Assuming that #3 = +5, the "GotoJump" will jump to block 3000 if the value of variable 780 is less than or equal to 25.

CGTECH_MACRO "IfCheck" "" #(((#3 - 1) * 20) + 700) <= 25

CGTECH_MACRO "GotoJump" "" 3000

CGTECH_VAR REAL

CGTECH_VAR REAL reala, realb, realc, ...

CGTECH_VAR is a special keyword which is recognized by Machsim while parsing an MCD file. This keyword provides the ability to define "local" variables in a "custom" MCD subroutine. These variables will be local to the subroutine, and will go away when the subroutine returns to the calling program. The corresponding "word" will be added to the Word list. This word will be removed at reset, and will not be written to the control file. The syntax of the line following the CGTECH_VAR keyword is identical to the Sinumeric 840D DEF format.

Currently Vericut only supports local variables with the CGTECH_VAR keyword. The support of global variables could possibly be added as an enhancement in the future.

CGTech_Define

Similar to CGTech_Var that does Siemens DEF, CGTech_Define does same as Siemens DEFINE. Adding a substitution on the fly in machine initialization file is better that control substitution as it will keep the control as neutral, where the machine initialization file is specific to the machine. No need any more to add dummy “DEFINE” word and assign Siemens DEFINE in Heidenhain or Fanuc control…

For example: CGTech_Define M126 AS CGTech_Macro "RotaryTypeAbsolute" "CAXIS"

The AS is the key word that makes the left string to be substituted by the left string.

See the following sections of Vericut Help for additional information:

Machine Settings window: Subroutines tab and Advanced Control Options window: Subroutines tab section of Vericut Help.

NC Program panel in the Info tab section of Vericut Help.

Settings window: G-Code Outputs tab in the Project tab section of Vericut Help.

Also see the Vericut Macros section in the Vericut Help Library for more information about Vericut macros.