Data Types...........................................................................................................................................11
Echo to a Memory Bit.........................................................................................................................73
Use Stages...........................................................................................................................................73
Communication In/Out Faults.............................................................................................................73
Data Type...........................................................................................................................................133
The PLC or Programmable Logic Controller is responsible for deciding what to do based on
Inputs and responding by controlling the Outputs. The PLC Program is how you tell the PLC
how to react to the Inputs and when to cause Outputs to turn on or off.
This manual is for anyone trying to change or write a PLC program on a Centroid CNC11
system. It assumes a certain level of knowledge and does not explain every basic term that is
used. There are some definitions in Appendix H, but it is intended to clarify where there may
be confusion between CNC11 PLC program meaning and a more general meaning. If you are
unsure of what you are doing, please contact Tech. Support at support@centroidcnc.com and
ask questions.
Always take a report and store it in at least one location in case the program change
needs to be reverted.
The manual explains the components that can be used to make a PLC Program and goes
over the standard parts of PLC programs. There are several appendices including sample
programs, detailed key mappings, compare and contrast differences in CNC10 and CNC11
PLC programs, and list errors associated with the compiler. If you are experienced with
CNC10 PLC programs be sure to read Appendix H about the differences between CNC10
and CNC11.
Conventions Used in this Manual
There are several text conventions used in this manual. The following list explains the most
common ones.
•Code from PLC programs including System Variables and the various data types are in
Consolas font at 10 pt size. An example is SV_PC_VIRTUAL_JOGPANEL_ACTIVE.
•Keyboard Keys are in Arial font at 12 pt. size and bold. An example is Alt.-Q.
•Commands entered in the command line of a prompt window are in Arial font at 12pt.
size in italics and single quotes. The single quotes simply serve to further differentiate
the text that is to be typed, it is not included on the command line. An example of this is
'mpucomp ProgramName.src mpu.plc'.
•On and SET are interchangeable, as are Off and RST.
•System Variable may be written as SV, which is interchangeable and means the same
thing.
•PLC Program and program are used interchangeably and mean the same thing.
•Data Type and type are used interchangeably and mean the same thing.
•When a specific name for a Data Type is helpful it is used, but typically the direct name
is used to remove confusion about what type is being used in a given example.
•Names of Data Types such as Memory Bits and Outputs are capitalized.
•Binary data is written in this document from Most Significant Bit (Msb) to Least
Significant Bit (Lsb) on a Left to Right order when explaining how bits are moving
around. This follows the typical convention in programming. Note that the PLC program
reads and writes pure Binary data from Left to Right as well, but goes from Lsb to Msb.
See BTW and WTB for more information.
Compiling a PLC Program
The source code which you write or change must be converted to something that CNC11 can
understand to actually take effect. This is accomplished by compiling the program. The new
compiler is called mpucomp which is short for MPU11 compiler. The syntax for compiling a
program, in Linux, is 'mpucomp ProgramName.src mpu.plc' whereas in Windows the syntax is
'mpucomp.exe ProgramName.src mpu.plc'. Note that the compiler name is slightly different
and that the name of the file must contain no spaces. The first file is the source code and the
second file is where the compiled code goes. The second file must be named exactly
'mpu.plc' including the fact that it is is all lower case letters. Once the program is compiled
successfully, the system should be powered off completely and powered back on again. The
reason for this is that due to the nature of the InitialStage it only runs once for each power on
of the MPU11.
PLC Program Statistics
The PLC program is constrained by certain factors and limits. The following list enumerates
some of the more important of those. Pushing Alt.-i on the main menu causes the PLC
Diagnostic screen to appear. It shows the state of Inputs, Outputs, Stages, Memory Bits and
Words as well as the Time that is being taken by the PLC program.
•Presently there is a limit of about 80 Inputs and Outputs using a GPIO4D and four
PLC1616ADD boards. DC3IOB systems can achieve a bit more than this. There is a
hard system maximum of 768 Inputs and 768 Outputs in CNC11.
•There are many powerful features that take a long time to execute and thus should be
used sparingly. Usage of them is detailed below and recommendations against using
them are included in the Operators section.
It is helpful when debugging and reading a program to know what type a variable is without
having to constantly search through the multiple uses of a name to get to the definition at the
top of the program. Following is a table of basic suggestions of ways the types can be named
to reduce confusion. Inputs and Outputs are typically named to indicate the purpose rather
than applying an extra label to them. The basic idea is to put something like the code specific
type name at the end of the declaration. Whether you put a underscore between the name
and type or just add the letters in all Caps or just capitalize the first letter is up to you.
TypeExample NameComments
Constants
Input
Output
Memory Bit
Word
Double Word
Floating-point Word
Double-Floating-point Word
Timer
One-Shot
Stage
Fast Stage
PLC to CNC11 System
Variable
AXIS_FLT_CLR_MSG
EstopOk
LubeOut
SpinFault_M
Axis3FiberOk_W
BigCounter_DW
SpindleRangeMultiplier_FW
PreciseNumber_DFW
Fault_Clear_T
SlowFast_PD
InitialStage
CountSomething_FSTG
DoToolCheck
All Caps, end with MSG
Alternatively use M or Mem
Alternatively use W or Word
Alternatively use Timer
PD is Positive Differential,
meaning rising edge
Alternatively use STG
SV_PLC_* System variables
are not named, so the
function is prefixed with an
action word 'Do' or 'Select'
and named for the function it
tells CNC11 to do.
Keyboard Keys
M-Codes
Kb_a
M6
Kb is short for Keyboard
Start with Capital M
While no Stages are required to compile a PLC program, they should be used. The benefits
include allowing debug of small sections of code by turning off other stages, reduced Program
running time by running only certain things all the time, and compartmentalizing code for
easier comprehension.
The compiler is not case sensitive so EstopOK, ESTOPOK, EsToPoK, and estopok are all
references to the same Input. Convention states that capitalization be kept uniform for
variable references, but it is not required by the compiler.
All lines should end after 79 columns to prevent printing issues and ensure readability on
smaller monitors.
Stage names in the program are surrounded on lines above and below with a full width line of
minus signs to designate the start of a stage. Camel-case is used to name Stages and the
same naming should be used in the program. Type the Stage name 20 columns from the left.
Section titles within a stage have a full width line of minus signs, and also include the name of
the section in that line or not as preference dictates. The name should start after 5 minus
signs either way and optionally fill out the rest of the line with minus signs.
Section explanations longer than about 5 lines should have a full width line of minus signs
before and after the section to show it is a block of comments. Also every line between the
two bracketing lines should have a semi-colon to show it is part of the explanation.
Section explanations shorter than about 5 lines should just have a semi-colon in front of each
line with no spaces.
;INP769 - INP784 encompass the MPU11 onboard input connections
;which are generally used for MPG and probing functions.
System Variables with names like SV_STOP should not be redefined to a Memory Bit to avoid
obfuscation.
In the definition section the IS should line up with all others above and below in the section,
not with the entirety of the defines. This increases readability while maximizing comment
space. There should be two spaces between the longest variable name in the section and the
IS keyword. Also, if possible line up the comments after the definition.
Use only spaces in the PLC program, never use tabs unless you can figure out how to
replace tabs with spaces in your editor. It is helpful to show non-printing characters as well to
make sure trailing spaces are not causing extra wrapping of text.
Use only mono-spaced fonts such as Courier, Courier New, and MS Mincho.
The beginning of the actual program and end of the defines should be visibly demarcated with
5 blank lines before and after a title indicating the start of the program.
The names or variables used in the PLC program are defined at the top of the PLC program
only. Any definition after the first IF...THEN statement will cause an error at compile time. Any
label may be used to refer to any of the data types, but there are conventions to make it
easier to determine the type of data assigned to a variable. The syntax for defining a variable
is EstopOk IS INP11 or Lube IS OUT2.
Data Types
The kind of information that a variable can hold is defined at compile time by the data type
when it was declared. All of the types below can be used in a CNC11 PLC program, but are
not required to be in many cases. Typically Words and Floating-point Words have enough
precision to achieve the desired results versus Double Words and Double Floating-point
Words.
Important Note
It is critical to understand when Data Types are updated during the execution of a PLC
program. The execution of a PLC program is based on an Interrupt that breaks time into
increments of 1000/second for Fast Stages and 20/second for Stages. Each of these
increments is referred to as a “pass” of the PLC program. During each pass the entire
program is evaluated and Data Types are changed based on the logic in the PLC program.
A question that quickly emerges when writing these programs is, “If I change the value of a
variable at the top of a program, do I know that it has changed later in the program?” The
answer is, “ It depends.” The reason for this divided up by Data Type. Timers, Inputs and
Outputs are all buffered at the beginning of the program. This means that a snapshot is taken
of the state of them and that image does not change during the pass of the PLC program.
In other words, Timers have the same value at the start of the pass as they do at the end. The
same is true for Inputs and Outputs as far as the real-world physical state is concerned. The
snapshot of the Inputs never change, but the image of the Outputs can be changed on any
line and that brings us to the other category of when things update. Memory Bits, all Words,
One-Shots, both kinds of Stages, System Variables, and the image of the Outputs are
changed immediately and on the next line of the program will be at the value they were SET
to on the previous line.
Another important thing to note is that the PLC Diagnostic screen (Alt. + I) does not show
every transition of every variable. Indeed it is much like an Input in its functionality. The state
of all the Words and Inputs, Outputs and Memory Bits do not change until after a pass of the
PLC program changes. You will not see every state change in a tool change program
because of this. You must set Memory Bits in each Stage that get RST at the end of the whole
process or on the push of an Aux key for debugging to be sure of the path of execution when
there are choices.
Last Modified 2010-10-11 11:21:28 AMPage 11 of 134
It is often easier to remember a name for an error rather than the number associated with it.
Defining a Constant allows for this ease of use. By convention Constants are put before
Variable Definitions, but they can be put anywhere before the first IF statement. Typically,
Constants are used for PLC message numbers, but they can be used for anything. Math is
allowed when defining constants to help avoid mistyping a number. Parentheses are allowed
to force correct math, but only for Integer values. Floating-point numbers cannot have math
done on them or be used to create them. See the Syntax Errors section.
PI IS 3.1415926535897932384626433832795
ASYNC IS 2
SYNC IS 1
MULTIPLIER IS 256
FAULT_MSG IS (SYNC+5*MULTIPLIER)
Input – INP
Inputs are physical switches or buttons that can be either on or off. When defining an Input, it
is written as Limit_Switch IS INP2. Inputs can be compared with Outputs, Memory Bits,
Timers, One-Shots, Stages, Fast-Stages and System Variables that are bits using Logical
Operators, but not Relational Operators. Limit switches, Jog Panel keys and Inverter signals
such as fault or at speed are all examples of inputs. Analog voltage comes into the system,
but it must be read into any of the Word type variables.
Output – OUT
Outputs are physical, real-world outputs such as relay contacts, relay driver signlas, or analog
signals that can be on or off. Analog voltages are converted from Bits in the PLC program to
analog voltage at the header. They can be used to control other relays, lube pumps, spindle
enable, inverter analog speed control, coolant, Jog Panel LEDs, etc. The standard way of
specifying an output is Lube IS OUT2 or AutoCoolantLED IS JPO21. Outputs can be compared
the same way as Inputs.
Memory Bit – MEM
Memory Bits can be on or off and cannot directly affect anything outside the PLC program.
These Bits are often used to make logic easier to read by combining many repetitive checks
or keystrokes into one variable. MEM Bits are also used in debugging to store whether
transient signals have occurred, whether to invert inputs based on parameter 178, etc.
Memory Bits can be compared to other Bit type Variables with Logical Operators, but not
Relational Operators.
Last Modified 2010-10-11 11:21:28 AMPage 12 of 134
Words are Integer numbers that can be used to store error codes, parameter values, and
System Variables that are Word sized themselves. Words are defined like Error_Code IS W10.
Only the first 12 words are currently visible on the PLC Diagnostic screen. They can be
compared with other Word types, System variables that are Integer numbers rather than one
bit, and Timers. Relational Operators are allowed on any Word type variable, but Logical
Operators are not. Doing a Relational comparison produces a result that can be used in a
Logical Operator, however. An example of this is IF (W1 > W2) || MEM1 THEN SET OUT6. This
statement tests whether W1 is greater than W2 first. If that is true or MEM1 is true then the output
is turned on. Words can hold values from -2147483648 to 2147483647.
Double Word – 64-bit – DW
Double Words are Integer numbers just like Words, but can hold values from
-9223372036854775808 to 9223372036854775807. A Double Word is defined like
BigNumberDW IS DW3. In general these are unnecessary and should be avoided because they
take a long time for the PLC executor to process. Double Words are otherwise exactly the
same in usage as Words.
Floating-point Word – 32-bit – FW
Floating-point Words are real numbers that can store fractional values from 2^-149 to 2^129.
It is typically precise enough for any operation in a PLC program. It is defined like
SpindleDACFW IS FW1. Precision problems can occur if comparing very very large and very very
small numbers, but typically this is not a concern. Floating-point Words have the same
comparison ability as Words.
Double-Floating-point Word – 64-bit – DFW
Double-Floating-point Words are real numbers that can store fractional values from 2^-1074
to 2^1022. They are more precise and can compare bigger numbers with smaller compared to
Floating-point Words. In general is is not advised to use this type at all due to significant time
required to do any calculations. The definition of a Double-Floating-point Word is
PreciseNumberDFW IS DFW1. DFWs are compared exactly like Words.
Timer – 32-bit – T
Timers are counters with the special ability to be compared with both Relational and Logical
Operators. This means that you can check IF T1 THEN SET OUT1 to see if the Timer has
reached its set point or IF T1 > 1000 THEN SET OUT2 to see if the Timer has counted past 1
second. Timers are initialized with a 32-bit positive Integer number that is interpreted as the
number of milliseconds to count before evaluating to true when checked with Logical
Operators.
The value is typically stored in the Timer during the InitalStage. To start a Timer counting use
SET T1. To reset the Timer so that it is waiting to count again use RST T1. Note that you do not
Last Modified 2010-10-11 11:21:28 AMPage 13 of 134
need to store a value into a Timer each time it is RST unless you want to change the value to
which it counts.
Timers evaluate to true after reaching the stored time until they are reset. The actual count of
the Timer continues to climb until it gets to about 10 seconds before the max value that
Timers can hold. This means that Timers can be checked to see if they are over a certain
value with Relational Operators.
Timers can count up to 24 days or 2073600000 ms. Be aware that if you are trying to time
something longer than that you will need to come up with a scheme for keeping track of time
greater than 24 days. A simple option for counting days is to set the Timer to 1 day worth of
ms (24 hrs. * 60 min. * 60 s = 86400000 ms). When the Timer expires, increment a Word day
counter and then RST and SET the Timer to begin counting again. See Application Examples for
how to setup a Timer for counting days. The following example sets the Timer to one second
then SETs the Timer if MEM1 is closed. When T1 counts to 1000, an Output is turned on and
the Timer is RST. If the Memory Bit is set next time through the PLC program the Timer will be
SET again. The first time the Timer value has counted past 10 a Memory Bit will be turned on.
T1 = 1000 ;Set the value that the timer counts up to 1 second
IF MEM1 THEN SET T1 ;start the Timer counting
IF T1 THEN RST OUT2, RST T1 ;if 1 second has elapsed turn off the output and reset the
;timer so it can be started again.
IF T1 > 10 THEN SET MEM50 ;if the timer has counted past 10 ms set MEM50
One-Shot – PD
One-Shots or Positive Differentials are used to detect the first rising edge of an event
occuring. A One-Shot can only be turned on and off using a Coil. Because of this a One-Shot
should only ever be SET/RST on one line of the PLC Program. It can be checked anywhere, but
not SET/RST. Once the PD has been SET by the IF test, the conditional section must evaluate to
false and thus RST the PD before it can be used again. This means that you cannot hold a
button down and cause the One-Shot to trigger more than once. Using this in combination
with Debounce allows safer detection of key presses to prevent multiple actions when only
one is intended. One-Shots are often used on Jog Panel keys and M-Codes. One-Shots may
not be desired in certain circumstances such as the Override +/- buttons for Spindle Speed.
Typically one wants to hold down the button and have the Override value change as long as
the button is held down. An example definition and usage of a One-Shot follows.
KeyPressPD IS PD1 ;define the One-Shot
IF JPI1 THEN (KeyPressPD) ;if Jog Panel Input 1 is pushed, set the One-Shot
If KeyPressPD THEN SET MEM300 ;if the One-Shot is set, turn on a memory bit
Stage – STG
Stages are useful in many ways. First, they are used to break up different sections of the
program to allow easier debugging and testing. Conventional programming dictates that there
is at least an InitialStage and a MainStage in any PLC program, but Stages are not required to
Last Modified 2010-10-11 11:21:28 AMPage 14 of 134
be explicitly used at all. Turning a Stage on and off is just like the process for Outputs.
IF 1==1 THEN SET STG1;Turn on a Stage all the time
IF M6 THEN SET ATC_Main_Stage To turn a Stage on when a tool change is called
When a Stage is RST the PLC executor does nothing with the logic inside the Stage. This
means that whatever Variables are SET or RST when the Stage itself is RST maintain that state
unless they are modified somewhere else in the program.
Warning: No checks are made against resetting any stages. It is possible to RST every stage
and have nothing executed in the PLC program. This requires a system power off and reboot.
The InitialStage is often used to setup any timers used and the state of tools for ATC
machines. At the end of the InitialStage a JMP should be called to the MainStage. The
InitialStage should never be SET again. To troubleshoot a problem, Stages could be turned
off to narrow down the problem section. Also, Stages are usually used to break up the steps
of a tool change sequence and various M-Codes so that they are not executed or checked
every time through the PLC program and for debugging. Stages are executed at the standard
rate of PLC program execution which is 50 times per second.
Warning: Typically Coils should not be used in Stages that are turned on and off, especially if
you come from a CNC10 PLC programming background. This is because typical coil behavior
will not occur if a Stage is off. This means that One-Shots should also not be used in Stages
that may be turned off. Odd effects can occur with One-Shots in Stages if you do not know
what to expect. If, for example, a One-Shot is used to RST a Stage, the One-Shot will not be
reset the next time through the PLC program, but will instead wait for the next time the Stage
is SET and the Coiled One-Shot is scanned over. This will, instead of setting the One-Shot as
might normally be expected, cause the One-Shot to be RST finally and require the One-Shot to
be triggered again in the next PLC Program pass, if the Stage is still SET.
Timer counting is not affected by a Stage being RST. This means that if you SET a Timer in a
Stage and then RST the Stage the Timer still counts and can be checked outside of the Stage
and the expiration of the Timer will be accurate.
If you want to use a One-Shot to exit a stage, say from a button push, then you should put the
One-Shot in coils again to make sure it is turned off on the line that resets the Stage. The
following example illustrates the concept. With this example, if the Jog Panel key is pressed
when the Stage is executed, the Stage will always be reset on the first pass through.
;------------
STG1
;------------
IF JPI1 THEN (PD1);push a Jog Panel button to trigger a One-Shot
IF PD1 THEN (PD1), RST STG1 ;accessing the PD again causes it to get RST, Stage is RST
Fast Stage – FSTG
Fast Stages behave exactly like Stages except that they are executed at up to 1000 times per
second. These should be used only when extremely precise timing is necessary.
Last Modified 2010-10-11 11:21:28 AMPage 15 of 134
Warning: Fast Stages do not interrupt the operation of normal speed stages, so if the normal
PLC program takes longer than 1 ms to execute completely, then the Fast Stages will not
execute at the stated rate. Make sure that the standard timings are below 1 ms to get the
fastest execution time. The average time can be found in the PLC Diagnostic screen.
CNC11 to MPU11 System Variable – SV_*
These are System Variables that are SET or RST by CNC11. There are both Word and Bit type
SVs. Both CNC11 and the PLC program can read these System Variables. Convention states
that they should be typed in all caps. For a complete list of System Variables and their uses
see Appendix D.
PLC to CNC11 System Variable – SV_*
These are System Variables that are SET or RST by the PLC Program. There are both Word
and Bit type SVs. Both CNC11 and the PLC program can read these System Variables.
Convention states that they should be typed in all caps. For a complete list of System
Variables and explanation of usage see Appendix D.
Keywords
Keywords are reserved words in the PLC programming language that cannot be used except
for the defined purpose. Often attempting to use the keyword in an undefined way will cause
the program to fail compilation. In example code they will always be capitalized by convention
and should not be confused with constant defined variables or System Variables.
Defining variables – IS
This keyword is used to setup labels for all the data types. It is only used in the definition
section at the top of the program. It is not used in the actual PLC program that gets executed.
When the program is compiled all the labels are replaced with what they refer to from the
definition section of the PLC program. For example the E-stop Input is defined like:
EStopOK IS INP11.
IS is used on every data type to define a name for that variable. There is also a built in
functionality for defining constant data to have a name. Math can be done in the definition and
previous definitions of constants can be used as long as the entire assignment is in
parentheses. An example is:
DEFINED_CONSTANT IS (1+2+5*7)
SECOND_CONST IS (DEFINED_CONSTANT*10)
Conditional Statement – IF/THEN
The Conditional Statement is used for every line of the PLC Program that can be executed
and is synonymous with a rung in ladder logic. The first IF/THEN in a Program defines the start
of the PLC program and the end of the Variable Definitions. The part of the line between the
Last Modified 2010-10-11 11:21:28 AMPage 16 of 134
IF and the THEN must evaluate to a true or false, 1 or 0. If it cannot be resolved to either value,
then an error is thrown at compile time. This means that Words must be checked with
Relational Operators and a Word itself cannot be the test for truth. IF W1 > 10 THEN (OUT2) is a
valid test whereas IF W1 THEN (OUT2) is not. There can be as many conditions on the truth of a
Conditional Test as you need. They are all separated by Logical Operators such as OR(||)
and AND(&&).
There is no ELSE Keyword, but the functionality can be achieved by copying the previous test
and putting parentheses around it with a NOT symbol in front of it.
The following table defines what can be done in the test part of the Conditional Statement.
While the statements are legal it does not mean that they are typically used. For example,
typically Stages are not checked in IF/THEN statements.
Data TypeUsage
Input
Output
Memory Bit
Stage
Fast Stage
Word
Double Word
Floating-point Word
Double-Floating-point Word
SV bit
SV Word
One-Shot
Timer
Print Message – MSG
IF INP50 THEN (OUT50)
IF OUT50 THEN (MEM50)
IF MEM40 THEN SET STG2
IF STG2 THEN (OUT4)
IF FSTG1 THEN (OUT1)
IF W1 > 156 THEN (OUT30)
IF DW2 > 4000000000000 THEN (MEM300)
IF FW1 > 5.432 THEN SET OUT3
IF DFW1 > 8900.983201293 THEN (OUT80)
IF SV_ENABLE_AXIS_1 THEN (MEM70)
IF SV_PC_CYCLONE_STATUS_2 == 4 THEN (MEM65)
IF PD2 THEN SET OUT7
IF T1 THEN SET OUT 5
IF T1 > 4000 THEN SET OUT 6
Printing a message is useful when the user needs to know about status changes. It is often
used in ATC PLC programs to indicate what part of the tool change process is being
executed. Error reporting is the other key usage of the PLC messaging functionality. There
are two types of messages that can be used with the PLC Message functionality,
Synchronous and Asynchronous. Printing synchronous messages is done in its own Stage
that is SET only when a message needs to be printed. This Stage should be the last Stage in
the PLC program. Asynchronous messages are usually printed right inline with the rest of the
code. Synchronous messages are displayed only when the SV_STOP System Variable is SET
and Asynchronous messages are printed immediately. There is not a practical limit to the
number of messages that can be defined for usage.
Last Modified 2010-10-11 11:21:28 AMPage 17 of 134
The command to send a message is IF 1==1 THEN MSG W1 where W1 stores a correctly setup
message value. A Word variable must be used with the MSG command.
Only one message can be displayed per pass of the PLC program. This explicitly does not
mean that one each Async and Sync message can be displayed per pass. There is no queue
of messages that get buffered and sent out eventually. If a new message is sent, it overwrites
the previous one. Effectively, the last MSG command in the program is what is displayed on
screen, if it has changed.
Worth noting is the fact that once a particular Synchronous or Asynchronous message has
been sent, a different message number must be sent of the same type (Sync or Async) before
that original message can be sent again. For example, if you send a Lube Fault Synchronous
message, when that clears you must send another different Synchronous message before the
Lube Fault message can be displayed again. This means that if the Lube Fault message is
displayed and then the fault is cleared, but no new message is sent, if Lube Fault occurs
again, the PLC program will be in the fault state, but there will be no message displayed. It is
very important to avoid this case as it will look as though there is no error, but CNC11 will not
start a job due to SV_STOP being SET. It can be debugged by putting the Word variable in the
first twelve words so that they are displayed on the first PLC Diagnostic screen.
CNC11 takes the value sent via the MSG command and looks in the plcmsg.txt file for the
selected message and prints it to the screen. The method of formatting this value is to start
with a 1 or 2 for Synchronous or Asynchronous respectively and then add the message
number times 256. An example table is shown below. The Word Value column in the following
table is what should be stored in the Word to be sent out with the MSG command.
Message NumberTypeWord ValueNotes
1Synchronous2571 + 1*256
2Asynchronous5142 + 2*256
25Synchronous64011 + 25*256
50Asynchronous128022 + 50*256
It is easiest and less error prone to write the message number once by defining a Constant to
store to a word before messaging it out. Below are the defines used in both Asynchronous
and Synchronous messages for the example program.
INP13_GREEN_MSG IS (2 + 1*256) ;258
INP13_RED_MSG IS (2 + 2*256) ;514
INP14_GREEN_MSG IS (1 + 3*256) ;769
NO_SYNC_MSG IS (1 + 99*256) ;25345
NO_ASYNC_MSG IS (2 + 100*256) ;25602
EStopOk IS INP11
Async_I IS INP13
Last Modified 2010-10-11 11:21:28 AMPage 18 of 134
;if the message has been cleared, reset this stage to allow Async messages
IF Sync_W == NO_SYNC_MSG && Sync_Cleared_M THEN RST SetError
The sample plcmsg.txt file use for the above example is:
1 9001 Input 13 Green
2 9002 Input 13 Red
3 9003 Input 14 Green
99 9099 No SYNC Message
100 9010 No ASYNC Message
plcmsg.txt
The plcmsg.txt file contains a list of all the messages that the PLC can send to CNC11. This
facility is used to notify the user of status changes and fault conditions. The typical messages
should not be overwritten by new custom messages, rather new numbers should be added.
The format for each line of the plcmsg.txt file is as follows.
MessageNumber MessageLogNumber Message
There are three fields separated by one space each that must be setup for a line to be valid
and usable. If the line is not formed correctly, you will not know it until the message is trying to
display. The MessageNumber field is exactly the same number as the Message Number in
the above table. The MessageLogNumber causes the printed message to be put in the
msglog.txt file so that problems can be diagnosed by Tech. Support. The 9xxx series
messages are reserved for PLC program usage. Make sure the Log Level is set to 4 in
parameter 140 to ensure the messages are logged. Message is the useful text that will be
printed along with the MessageLogNumber. It should contain a pithy message that informs
the user about the change that occurred. All text to the end of the line is printed so no
comments are allowed in this file. The standard plcmsg.txt file is listed below.
1 9001 PLC Execution Fault
5 9005 Axis 1 Communication In Fault
6 9006 Axis 2 Communication In Fault
7 9007 Axis 3 Communication In Fault
8 9008 Axis 4 Communication In Fault
Last Modified 2010-10-11 11:21:28 AMPage 20 of 134
9 9009 Axis 5 Communication In Fault
10 9010 Axis 6 Communication In Fault
11 9011 Axis 7 Communication In Fault
12 9012 Axis 8 Communication In Fault
13 9013 Axis 1 Communication Out Fault
14 9014 Axis 2 Communication Out Fault
15 9015 Axis 3 Communication Out Fault
16 9016 Axis 4 Communication Out Fault
17 9017 Axis 5 Communication Out Fault
18 9018 Axis 6 Communication Out Fault
19 9019 Axis 7 Communication Out Fault
20 9020 Axis 8 Communication Out Fault
21 9021 Axis Faults Cleared
22 9022 PLC Communication In Fault (Fiber 3)
23 9023 PLC Communication Out Fault (Fiber 1)
24 9024 PLC Faults Cleared
34 9034 FAULT! REMOVE PROBE FROM SPINDLE!!!
35 9035 KEYBOARD JOGGING DISABLED
36 9036 LUBE FAULT
37 9037 PROBE TRIPPED WHILE JOGGING
38 9038 SPECIFIED SPIN SPEED < MIN SPIN SPEED
39 9039 Software Ready Fault
50 9050 Auto Coolant Mode
51 9051 Manual Coolant Mode
99 9099 Message Cleared
100 9100 BAD MESSAGE VALUE
System Variables – SV_...
System Variable names cannot be used verbatim as constant value labels, variable names, or
as the beginning of either. Removing the underscores from the name, for example, gets
around this problem. Attempting to do so will cause the program to fail at compile time.
Data Type Name
All of the names of Data Types used in the PLC program are not allowed to be used as
constant value labels or variable names. This means that INP1 is invalid as is just INP.
Attempting to do so will cause the program to fail at compile time.
Indexes – Data Type[Data Type or Constant]
Using the Index ability is useful when writing generic programs that allow users to set an Input
or Output that they want a function to occur at in parameters. It is very important to check for
Index Out of Range errors if this functionality is used. The default value for the PLC Program
parameters is 0.0 and all Data types start at 1, so an Index Out of Range error would occur
right away. This cannot be used with System Variables. In the following example Parameter
171 is checked to make sure it is within a certain range, then an Output number is set based
on the information it finds.
p171_W IS W1
Last Modified 2010-10-11 11:21:28 AMPage 21 of 134
;make sure the parameter is in range, if not default value is used
IF ( p171_W <= 0) || ( p171_W >= 10) THEN LubeOut_W = 2
IF !(( p171_W <= 0) || ( p171_W >= 10)) THEN LubeOut_W = p171_W
;set output based on parameter
IF SV_PROGRAM_RUNNING || SV_MDI_MODE THEN (OUT[LubeOut_W])
Range Selection – '..'
This functionality allows setting or resetting of Bit type Variables including System Variables.
Two dots are placed a space apart from the beginning variable and ending variable. All
variables between and including the two book-end variables are either SET or RST, regardless
of whether they are being used for anything else or if they have a label. This can be useful in
error conditions if you want to turn off all Outputs or Stages. Usage is as follows.
IF JPI1 THEN (PD1)
IF PD1 THEN RST OUT1 .. Out80
IF JPI2 THEN (PD2)
IF PD2 THEN SET OUT80 .. OUT1
DUMP
The DUMP command causes CNC11 to print the values stored in all of the first 64 Words,
Double Words, Floating-point Words, and Double-Floating-point Words to debug_dump0.txt in
the cncm or cnct directory. DUMP should only be used sparingly and then only when
debugging the initial implementation of a PLC program because of the cost of writing data to a
file on the hard disk. This is useful for making sure Floating-point variables are correct. An
example of using this is as follows.
IF JPI1 THEN (PD1)
IF PD1 THEN DUMP
Operators
The operators in a PLC program are used to compare data, to set one piece of data equal to
another, invert the data, etc. There are both unary and binary operators in CNC11. The unary
operators only require one variable or piece of data to operate. An example of this is inverting
a memory bit like this !MEM1 or turning a Memory Bit on like SET MEM1. A binary operator
requires two pieces of data that are the same type. Examples of using a binary operator are
W1 >= W2 and W3=W4. There are no Bitwise Operators at present. This means that bit masking
cannot be done by ANDing or ORing constant values with a Word. It can be done by setting
Last Modified 2010-10-11 11:21:28 AMPage 22 of 134
and resetting bits and shifting as well. The following operators are all valid in a CNC11 PLC
program.
Assignment – =
The equals sign is used to set a Word or Timer on the left of the equals sign to a Word, Timer
or numerical value on the right of the equals sign. Some examples are listed below.
IF 1==1 THEN W1 = 10 ;Word1 is set to an integer value of 10
IF 1==1 THEN T1 = W1 ;Timer1 is also set to an integer value of 10 representing 10 ms
IF 1==1 THEN FW1 = 2.5 ;Floating-point Word1 is set to 2.5
Set – SET
SET turns on any of the Bit variables. The bit value is set to 1 and evaluates to true when
checked. That is to say that any of the Outputs, Memory Bits, Timers, Stages, Fast-Stages
and System Variables that are bits can have this keyword used on them. One-Shots cannot
be SET. An example of using this is IF 1==1 then SET MEM1.
Data Types that can be used with SETExample of using SET
Memory Bits
Outputs
Inputs
Timers
Stages
Fast Stages
One-Shots
IF 1==1 THEN SET MEM2
IF 1==1 THEN SET OUT2
IF 1==1 THEN SET INP2
IF 1==1 THEN SET T2
IF 1==1 THEN SET STG2
IF 1==1 THEN SET FSTG2
IF 1==1 THEN SET PD2
Reset – RST
Reset turns off any of the Bit variables. The bit value is set to 0 and evaluates to false when
checked. That is to say that any of the Outputs, Memory Bits, Timers, Stages, Fast-Stages
and System Variables that are bits can have this keyword used on them. One-Shots cannot
be RST. An example of using this is IF 1==1 then RST MEM2.
Last Modified 2010-10-11 11:21:28 AMPage 23 of 134
Data Types that can be used with RSTExample of using RST
Memory Bits
Outputs
Inputs
Timers
Stages
Fast Stages
One-Shots
IF 1==1 THEN RST MEM2
IF 1==1 THEN RST OUT2
IF 1==1 THEN RST INP2
IF 1==1 THEN RST T2
IF 1==1 THEN RST STG2
IF 1==1 THEN RST FSTG2
IF 1==1 THEN RST PD2
Output Coil – ()
Output Coils are used to SET or RST any bit output based on the conditions before the THEN. If
the test in the IF is true the output is SET, whereas if the test is false then the output is RST. The
use of parenthesis does not constitute Output Coils unless they are used to the right of THEN
on any program line. Output Coils cannot be used on Words. Be careful when using Coils
because they can cause logical problems in your program. Do not put a variable in Coils on
one line and then try to SET or RST it somewhere else in the program as well because it will
change while moving through the PLC program and may have surprising results. If you are
going to use a variable in Coils, all of the logic to turn it on or off must be on the same line to
avoid trouble. Coils cannot be used on Timer Data types to start them counting because they
are generally guaranteed to be turned off again on the very next pass of the PLC program.
Some examples are shown below to illustrate some Coil concepts.
;basic Coil usage
IF 1==1 THEN (OUT1) ;always turn on OUT1
IF MEM1 THEN (OUT2); SET OUT2 if MEM1 is SET and RST OUT2 if MEM1 is RST
;potentially problematic Coil usage
IF MEM1 || INP5 THEN (OUT4) ;OUT4 is guaranteed to be SET or RST by this line
IF MEM3 THEN SET OUT4 ;OUT4 may be SET by this line if MEM3 is SET
IF INP10 THEN RST OUT4 ;OUT4 may be RST by this line if INP10 is SET
;better usage of Coil
IF (MEM1 || INP5) || MEM3 && !INP10 THEN (OUT4) ;all logic combined
Jump – JMP
Jump RSTs the current Stage and SETs another one. See Stages for the effects of turning on
or off a stage. Execution does not jump around in the PLC program as in Assembler, but
typically the stages are written one after the other so in essence it will move to that one. A
sample usage of Jump is IF 1==1 THEN JMP STG3. If a JMP is called such that the current Stage
Last Modified 2010-10-11 11:21:28 AMPage 24 of 134
is the stage being jumped to, then the Stage will still be set next time through the PLC
program. Jump can only be used on Stage variables. It is not advised to JMP out of the
MainStage, whereas it should be done out of the InitialStage. If you jump out of the MainStage
and no other stages are set, you must exit CNC11 and reboot the MPU11.
;typical usage
InitialStage
IF 1==1 THEN JMP MainStage ;InitialStage is RST and MainStage is SET.
Basic Math Operators – *, \, +, -, %
These are the basic four math functions, multiplication, division, addition and subtraction plus
the Modulus operator. They are all binary operators. These operators are allowed to be used
on Word types only. The modulus operator, %, is used to find the remainder of the division of
two numbers.
Note that the calculation is done and then changed to the appropriate type when the value is
assigned to a variable. Assignment of floating-point values to Integer Words results in the
decimal point value being truncated. This means that IF 1==1 THEN W1 = 2.5*1 will result in W1
being set to 2. The following examples illustrate usage of some of the operators.
;multiplication
IF 1==1 THEN W1 = 15*2; W1 is set to 30
IF 1==1 THEN FW1 = 0.5*SV_MPU11_ABS_POS_0; FW1 = half of current encoder counts for axis 1
;division
IF 1==1 THEN W2 = 128 / 2; W1 is set to 64
;Modulus
IF 1==1 THEN W3 = 15 % 2; W3 is set to 1 because 15/2 = 7R1
IF 1==1 THEN W4 = 128 % 15; W4 is set to 8 because 128/15 = 8R8
Relational Operators – <, >, <=, >=, !=, ==
Relational Operators are only valid when comparing Words, Word type System Variables and
Timers. Bit type variables cannot be compared with these operators. A relational operator
compares two variables of the same type and results in a 1 or 0 as the output.
Be aware that checking Timers with Relational Operators does not indicate anything about
whether the Timer has expired or not. It merely compares against the current count of ms
since the Timer was Set.
Less Than or < checks to see if the variable on the left is less than the value on the right to
evaluate to true.
Less Than Or Equal or <= checks to see if the variable to the left is less than or equal to the
variable on the right to evaluate to true.
Greater Than or > checks to see of the value on the left is greater than the value on the right
to evaluate to true.
Last Modified 2010-10-11 11:21:28 AMPage 25 of 134
Greater Than Or Equal checks to see if the value on the left is greater than or equal to the
value on the right to evaluate to true.
Not Equal or != checks to see if two variables are not exactly equal to evaluate to true. Note
that Floating-point != checks will most likely fail on calculated values due to rounding error. >=
or <= should be used instead to check Floating-point numbers.
Is Exactly Equal To or == checks to see if two variables are exactly equal to each other to
evaluate to true. The same warning applies to == as != about Floating-point numbers.
The following examples show how a sample PLC program line looks with a Relational
Operator on it.
IF 1==1 THEN W1 = 10, W2 = 10
IF W1 > W2 THEN (OUT1);Out1 is RST because W1 is not greater than W2
IF W1 == W2 THEN (OUT2) ;Out2 is SET because W1 is equal to W2
Logical Operators – !,&&, ||, XOR or ^
Logical Operators are used to compare or change the state of Bit type variables including
System Variables.
&& is the operator for AND. This means that both sides of the operator must be true to have
the statement evaluate to true. The following truth table shows all the options for evaluating a
binary expression.
Left SideRight SideResult
000
010
100
111
|| is the operator for OR. This means that only one side of the operator needs to be true for
the statement to evaluate to true.
Left SideRight SideResult
000
011
101
111
XOR or ^ are the operators for Exclusive OR. This means that one of the sides of the operator
must be true and the other false to have the statement evaluate to true.
Last Modified 2010-10-11 11:21:28 AMPage 26 of 134
The ! is a unary operator for NOT that inverts the state of a bit whether it is true or false.
Bit ValueResult
01
10
Logical Operators cannot be used on Word Type variables. The results of multiple Relational
checks can be combined with Logical checks for more complex statements, however. All of
the following lines are valid PLC code. Often it increases readability to use parentheses
around conditions to ensure correct interpretations.
IF MEM1 && INP2 THEN (OUT1)
IF (W1 > W2) || !MEM4 THEN (OUT5)
IF !MEM1 && INP2 || STG1 || FSTG1 && OUT3 XOR PD1 && T3 XOR SV_PC_POWER_AXIS_1 THEN (OUT6)
Convert to Word – BTW
BTW takes a range of Inputs, Outputs or Memory Bits and does a binary to decimal
conversion, storing the result in a Word. The default number of bits is 8, but a value of 1 to 32
is allowed. The first Bit is treated as the Least Significant Bit and the next bit is the next
highest number of Input, Output, Memory Bit. For example MEM1 to MEM8 are set, from lowest to
highest, as 0110 0100 where 0 is red and 1 is green. When BTW is executed the number is
converted as 2+4+32 = 38 decimal. Note that the number of bits specified is a count number
to use rather than a specific Bit number to convert up to and including. This means, starting at
Bit 0, how many of the bits should be converted. The following example will setup the bits as
the example above in code.
;setup the binary information
IF 1==1 THEN RST MEM1, SET MEM2, SET MEM3, RST MEM4
, RST MEM5, SET MEM6, RST MEM7, RST MEM8
;evaluate the Memory Bits as a Binary number and convert it to Decimal, storing in W1
IF 1==1 THEN BTW W1 MEM1
Convert to Binary – WTB
WTB converts a Word type variable to Binary and writes to Outputs or Memory Bits. By
default the lowest 8-bits of Binary are written. The lowest bit goes into the first bit and so on
Last Modified 2010-10-11 11:21:28 AMPage 27 of 134
up to the highest Bit. An Integer number from 1-32 can be specified to print from 1 to 32 of the
Binary bits to either Memory or Output locations.
Note that the number of bits specified is a count number to use rather than a specific Bit
number to convert up to and including. This means, starting at Bit 0, how many of the bits
should be converted.
Note that the Binary bits will write to the next consecutive bits regardless of any other
meaning in the PLC program. If you do a default WTB in a Memory section that only has 5
free bits, three of them will change something you likely do not want to change.
For example the Word W1 has a value of 12345 in decimal notation and 11000000111001 in
Binary notation. A standard WTB W1 MEM1 will print 00111001 with the Least Significant Bit
written to MEM1 and the Most Significant Bit written to MEM8 as seen on PLC Diagnostics. In the
first example the default WTB is used and 8 bits will be written out. In the second example 12
bits will be written to OUT17 to OUT28.
Data Types that can be used with WTBExample using WTB
Memory Bits
Outputs
IF 1==1 THEN WTB W5 MEM10
IF 1==1 THEN WTB W5 OUT17 12
Convert to Binary Coded Decimal – BCD
BCD is used primarily for interfacing with external devices that need information in Binary
Coded Decimal format. BCD is different than Binary in that each number in a decimal number
is converted to a 4-bit binary number.
This means that to represent the decimal number 125 in BCD the number must be broken up
into the ones, tens and hundreds positions and each of those numbers is converted to a
Binary number. The Binary numbers for 1, 2, and 5 are 0001 0010 0101 which is the BCD
version of 125.
The following table shows the conversion for the Decimal and BCD values. To use this feature
on outputs, four outputs must be used for each place in decimal that the external device will
be looking for. In the case of an ATC with 24 tools two sets of four outputs must be used to
represent all possible numbers. An example of using the BCD command is: IF 1==1 THEN BCD
W2. The Word can then be sent to the correct Outputs with the WTB command.
Note that the largest Decimal value that can be converted is 8 digits because only 32-bit
Integer Words can be used for the BCD command. This gives 32-bits divided by 4 bits gives 8
decimal places. This means that the BCD of a number greater than 99,999,999 is invalid and
undefined. For reference, the bits higher than 8 places are truncated and cannot be
recovered.
Last Modified 2010-10-11 11:21:28 AMPage 28 of 134
BIN converts a Word value that is in BCD format to standard Binary format. When the Word is
displayed on the PLC Diagnostic Screen it is shown as a Decimal number. The WTB command
can be used to then print the Binary version of the number to Memory Bits or Outputs if
desired. A simple use case of the BIN command is IF 1==1 THEN BIN W1.
Note that there is no checking on the BCD number to determine if it is a valid BCD
number. There are many invalid BCD numbers in each group of four digits, which could be
checked in a PLC program. In every group any BCD number greater than 1001 or 9 is invalid
because in decimal notation each place can only hold 0-9. For example a BCD number 57004
is completely invalid because in Binary it is 1101 1110 1010 1100 all of which are above 1001.
One way to test the BCD number is outlined below.
;read the 4 bits in from inputs for one BCD number
IF 1==1 THEN BTW W1 INP1 4
;create a copy of the word
IF 1==1 THEN W2 = W1
;convert the BCD number to Binary
IF 1==1 THEN BIN W2
;convert the now Binary number back to BCD
IF 1==1 THEN BCD W2
;check to see if they are the same BCD again
IF W2 != W1 THEN SET BCD_Fault_MEM, AsyncW = 258, MSG AsyncW
Set or Reset a Bit in a Word – BITSET / BITRST
When manipulating binary data it is often desirable to SET or RST only certain bits in the data.
Last Modified 2010-10-11 11:21:28 AMPage 29 of 134
BITSET and BITRST can by used on Words or Word Type System Variables. Depending on
the command used, the specified bit from 0-31 will be changed in the specified Word. Some
System Variables that are Integer Word values are actually 16 to 32 different Binary Bits that
can be checked, for example SV_PC_CYCLONE_STATUS_1. Note that the Bit number range is
different than the one used in WTB and BTW. The Bit number is the actual Bit that is checked.
Because Bit numbering starts at zero, when you reference a Bit by number you are checking
the “Bit number + 1” Bit.
IF 1==1 THEN BITSET SV_PLC_DEBOUNCE_1 5 ;Turn on Bit 6 in the first Debounce SV
IF 1==1 THEN BITRST W2 20 ;Turn off Bit 21 in Word 2
Check if a Bit is Set in a Word – BITTST
BITTST checks the specified bit in the specified Word or System Variable and SETs a Memory
Bit if true and RSTs the Memory Bit if it is false. The range of bits that can be tested is 0-31.
Note that the Bit number range is different than the one used in WTB and BTW. The Bit
number is the actual Bit that is checked. Because Bit numbering starts at zero, when you
reference a Bit by number you are checking the “Bit number + 1” Bit. In the example below
Word number one, Bit 17 is checked and the state of it is copied to Memory Bit one.
IF 1==1 THEN BITTST W1 16 MEM1
Left / Right Shift Bits in a Word – LSHIFT/RSHIFT
Left and Right Shift are used on Words to move bits to the left or right. Right Shift is a Logical
Shift rather than an Arithmetic Shift. This means that, as data is shifted, upper bit positions will
always be filled with zero.
A pictorial example of shifting is in the following table with the same commands shown in
code afterwards. The left shifting adds zeroes to the right-hand side to bump the number to
the left first. The decimal value is 3735928559 originally and then after the left shift it
becomes 4009754624. Finally, the right shift adds zeroes to the left-hand side to bump the
number to the right and generate a decimal 61184. Notice that this acts as a mask and
removes all except the second 8-bits.
OperationBinary 32-bit Word value
Original Value1101 1110 1010 1101 1011 1110 1110 1111
the PLC program. That being said, they should not be used except when it cannot in any way
be done in G-Code because of the significant time requirement to calculate any of the Trig.
Functions.
The values sent into the Trigonometric Functions must be in Radians, not Degrees. If you do
SIN(30) the answer you will get is approximately -0.98803162, which is obviously not the
SIN(30 degrees) = 0.5. To convert a degree value to Radians, multiply by PI and divide by
180 degrees. It is best to setup a constant in the InitialStage to avoid excessive computation
and significantly reduce typographical errors. All of the valid Trig. Functions are used in the
following program.
The following list shows what the results are from the above calculations. You can follow
along on your PC with the calculator as long as you enter the first three values in Radians.
PLC Dump Start
FW1: 0.52359879 FW2: 1.04719758
FW3: 0.78539819 FW4: 0.50000000
FW5: 0.49999997 FW6: 1.00000012
Last Modified 2010-10-11 11:21:28 AMPage 32 of 134
The square root of a number is a different number that, when multiplied by itself results in the
given number. Numbers that have the square root taken of them should be stored into a
Floating-point Word or Double-Floating-point Word because they will most likely be nonInteger numbers. SQRT results can be stored into a Word, but the non-Integer portion will be
truncated. This operation should rarely be used due to the time intensive nature of the
operation.
An example of using the SQRT function follows.
IntSqrt_W IS W1
Sqrt_FW IS FW1
;take the sqare root of 2 and store to a Floating-point Word
IF 1==1 THEN Sqrt_FW = SQRT (2) ;returns 1.41421354
;take the sqare root of 17 and store to a Word
IF 1==1 THEN IntSqrt_W = SQRT(17) ;returns 4.12310562, but 4 stored into the Word
Raise Number to a Power – POW
Raising a number to a power means multiplying the number by itself some number of times.
The POW command takes two arguments, the first being the number to raise and the second
being the number of times to multiply the first by itself. Both numbers can be floating-point
values. If the second number is relatively small, it is usually faster to just multiply the number
out, for example 2*2*2 instead of 23. The following example shows how to use the POW
command.
pow_FW IS FW1
pow2_FW IS FW2
;raise 2 to the 3rd power
IF 1==1 THEN pow_FW = POW(2, 3) ;returns 8.00000000
;raise 2 to the 3.5th power
IF 1==1 THEN pow2_FW = POW(2, 3.5) ;returns 11.31370831
;raise 300 to the 1/8th power
IF 1==1 THEN pow3_FW = POW(300, 0.125) ;returns 2.04004693
Last Modified 2010-10-11 11:21:28 AMPage 33 of 134
A PLC program is laid out with all definitions at the top of the program until the first IF
statement is used. From then on no more definitions are allowed and will generate an error at
compile time. When the PLC program is executed it runs from top to bottom and executes
every line except under certain circumstances, specifically Stages. Top to bottom execution
can lead to logic errors where something is SET in one part of the program and then reset
somewhere else. Wherever possible all conditions that could change an output should be
gathered together.
The basic functionality described in this chapter is based on the basic DC3IOB PLC program.
The PLC program needs to have certain sections to achieve a minimum of real-world
functionality as outlined in this chapter. The PLC program should always check all of the
connections between the MPU11, the PLC board including miniPLC boards and the drive
board. In order for a Jog Panel or Keyboard Jogging to work they must be written into the
PLC program.
Definitions are used to make reading the program easier and as such, the names used for the
definitions should reflect the function and polarity when tripped, on or Green in PLC
Diagnostics. This means that if a variable is Normally Closed it is named something like
XminusLimitOk. The logic to check it becomes IF !XMinusLimitOk THEN SET MEM9. If the variable
is Normally Open, the naming should be inverted. For a Normally Open Lube Fault input the
logic to check it becomes IF LubeFault THEN SET MEM90.
At a minimum a WatchDogStage, InitialStage and MainStage should be used in every PLC
program. The basic PLC program has many more stages for things like spindle control, Lube
timers, Checking System Variables, etc. The InitialStage is used to setup any timers and
default states. The MainStage is set in the InitialStage which then resets itself and is never SET
again while CNC11 is running. This means that the InitialStage will only run once for each
time the CNC software starts. Exiting CNC11 and restarting it causes the InitialStage to run
again.
Defining Variables
Any variable is defined by having the label set to a valid data type using the keyword IS.
Further examples can be seen for each data type under Data Types.
Initial-Condition Setup
The on/off state of various modes of operation such as Auto/Manual Coolant, Fast/Slow
Jogging, etc. must be set by the PLC program because everything defaults to off. It is
desirable to do this without having to push the buttons to set the states the first time because
being off means something as much as being on. For example, if the Fast/Slow Jog mode is
not actively set, it defaults to Fast Jog. The convention is to use a Memory Bit called
OnAtPowerUp. It is SET in the InitialStage and RST at the end of the MainStage. This means that
Last Modified 2010-10-11 11:21:28 AMPage 34 of 134
all setup should be done inside the MainStage or before the MainStage executes. This
influences the location of the MainStage in a program if setup is done in other Stages with this
Memory Bit because if you RST it at the end of the MainStage and reference it after the
MainStage, it will be false and not everything will be setup as desired. Typical things that
should be setup with this variable are the Spindle Override percentage, Auto/Manual Spindle
Mode, Spindle Direction, Auto/Manual Coolant Mode, Incremental/Continuous Jogging,
Incremental Jog Distance Multiplier and Fast/Slow Jog Mode. An example of setting the
Spindle Mode follows.
;--Set spindle to auto mode on startup
;--explanation
;IF (Jog-Panel-Key AND Not-In-Auto-Spindle-Mode) OR First-time-through-the-Program
; Then turn on Auto-Spindle-Mode
;--actual code
IF (SpinAutoManPD && !SpinAutoModeLED) || OnAtPowerUp
THEN SET SpinAutoModeLED
Internal PLC Fault and Software Running Checking
Just before the InitialStage there should be a Stage that checks for catastrophic PLC
problems and also CNC11 to be running. Problems currently consist of dividing by zero,
invalid op-code and index out of bounds. If any of these errors occurs the PLC executor
immediately stops executing the program and starts over again at the beginning. This is why it
is important to check these errors in the first Stage before any division or Index usage occurs.
PLC Fault Status
The procedure is to see if any of the three errors are set and if they are, read the related
System Variables to Words and use the PLC messaging functionality to tell the user. Note that
to generate the invalid op-code error the compiled PLC program must be changed at the
hexadecimal level, so it is a very hard error to generate. No sample is given for this case as it
involves manipulating the compiled program. A sample program follows that only checks for
the three errors. To get either of the divide by zero or index out of bounds errors comment in
either of the sections in the MainStage. Note that only the first error to occur will be generated
due to the nature of these errors.
Software Ready
The SV_PC_SOFTWARE_READY Bit is checked to see if CNC11 is running. This is mostly used if
CNC11 crashes to prevent motion, too changes, etc. SV_STOP is set which will cause E-Stop be
activated. When the software starts again, E-Stop must be cycled and then motion can be
commanded again. SV_STOP is SET and the InitialStage is run whenever the software starts up
again.
Last Modified 2010-10-11 11:21:28 AMPage 35 of 134
This is a significant part of the PLC program and as such is not transcribed from the basic
program.
Nearly all Jog Panel functions that can be caused by key presses require Keyboard Jogging
to be SET in Parameter 170 bit 0 and RST in Parameter 148 bit 1. The exceptions are Escape
and Rapid Override.
There are some keys that require the Keyboard Jog Panel to be on screen as well as have
Keyboard Jogging enabled. These functions are primarily limited to Jogging.
Axis Enable
Enabling an axis so it can be commanded to move is, in a typical PLC program, just copying
one SV to another as shown below. This gives control to the PLC program so that if other
conditions need to be checked before allowing an axis to be enabled, they can be
implemented here. While this is all that is strictly required to enable the axis for motion, the
Fiber Checking section must be included as well the make sure the connections between the
MPU11 and drives are good.
IF (SV_PC_POWER_AXIS_1) THEN (SV_ENABLE_AXIS_1)
IF (SV_PC_POWER_AXIS_2) THEN (SV_ENABLE_AXIS_2)
IF (SV_PC_POWER_AXIS_3) THEN (SV_ENABLE_AXIS_3)
IF (SV_PC_POWER_AXIS_4) THEN (SV_ENABLE_AXIS_4)
IF (SV_PC_POWER_AXIS_5) THEN (SV_ENABLE_AXIS_5)
IF (SV_PC_POWER_AXIS_6) THEN (SV_ENABLE_AXIS_6)
IF (SV_PC_POWER_AXIS_7) THEN (SV_ENABLE_AXIS_7)
IF (SV_PC_POWER_AXIS_8) THEN (SV_ENABLE_AXIS_8)
Fiber/Wire Connection Checking
There are two kinds of communication used on MPU11 systems. The DriveBus is used for
communication related to motor control and can be either fibers 4 and 5 or the Drive
Communication wiring for expanding the number axes that can be controlled. The PLCBus is
on fibers 1 and 3 and is used for controlling I/O. If the Buses are being used, the connections
must be checked to ensure communication problems are not clouding troubleshooting.
Checking the connections only needs to be done a few times a second to be effective. This
means having a stage that is set by a Timer to read the information. Both of the following
sections use the same logic to check for errors, but the first checks both connection methods
and the second only checks the PLCBus. The third section needs to be added if an expansion
board is added to the PLC.
Last Modified 2010-10-11 11:21:28 AMPage 37 of 134
Presently the Optic4 and DC3IOB have DriveBus Fiber connections. The Optic4, DC3IOB
and ALLIN1DC have Drive Communication In and/or Out Wire connections. The ALLIN1DC
has an MPU11 on-board which means there are no visible Fiber connections, but the Drive
and PLCBuses are still used and should be checked. If a system using 3rd party drives is used
with more than four axes, the Optic4 must be used in conjunction with the GPIO4D and the
DriveBus Fiber Checking must be done as well.
IF SV_PLC_BUS_ONLINE && PLCBus_Oe_M && !PLCBusExtDevEn_M
THEN ErrorCode_W = PLC_OUTFLT, SET SetErrorStage, SET PLCFault_M
;clear PLC errors
IF PLCFault_M && SV_PLC_BUS_ONLINE && PLCBusExtDevEn_M && !EstopOk
THEN RST PLCFault_M, ErrorCode_W = PLC_FLT_CLR,
SET SetErrorStage, SET PLCBus_Oe_M
IF true_M THEN RST CheckCycloneStatusStage Axis1FiberOk_M
PLCBus Checking only
The GPIO4D communicates to the MPU11 only over the PLCBus. If a system only has a
GPIO4D then only the PLCBus should be checked. This section details the PLC Fiber
checking only. The errors are checked for and set in the AxesEnableStage.
This section should be added to any PLC program that uses the PLCADD1616 or
ADD4AD4DA expansion boards. Specifically the checking should be added to the
CheckCycloneStatusStage. Only the MiniPLCBus Online bits are checked in this section, but
they should be added to the original Stage. Only the Expansion headers that are used should
be checked. There is no equivalent to the SV_Axis_Valid_1 - _7 System Variables. Looking in
the mpu_info.txt file will show what expansion boards are plugged in to the headers.
;add to Constant Defines
MINI_PLC_1_FLT_MSG IS (1 + 256*60); 15361
;add to CheckCycloneStatusStage
;check the first Expansion board
IF 1==1 THEN BITTST SV_PC_MINI_PLC_ONLINE 0 ADD1616ok1_M
IF !ADD1616ok1_M && PLCBus_Oe_M THEN
ErrorCode_W = MINI_PLC_1_FLT_MSG, SET SetErrorStage, SET PLCFault_M
LubeTimers
There are two options for setting up automatic lubing in the basic PLC program. The first type
is used for Lube pumps with no timer internally. This means that the PLC program must turn
the output on and off to power the Lube pump correctly. The second type is for Lube pumps
with internal timers.
; METHOD 2 (SS != 0) For lube pumps that do not have internal timers.
;
; When using this method P179 should be set so the lube turns on
; every MMM minutes for SS seconds.
;
; Example 1.
; To set the lube pump power to come on for 5 seconds
; every 10 minutes, set P179 = 1005.
; MMMSS
; Example 2.
; To set the lube pump power to come on for 30 seconds
; every 2 hours, set P179 = 12030
; MMMSS
;
; This method will accumulate time while a program is running until
; it reaches MMM minutes, at which time it will apply power
; for SS seconds (unless E-stop is engaged) and then start over. It is
; possible with frequent use of E-stop that a lube cycle is cut short.
;
IF SV_PROGRAM_RUNNING THEN LubeM_T = LubeM_W, SET LubeM_T
IF !SV_PROGRAM_RUNNING THEN (StopRunning_PD)
IF StopRunning_PD THEN LubeAccumTime_W = LubeAccumTime_W + LubeM_T, RST LubeM_T
IF LubeM_T || (LubeAccumTime_W + LubeM_T > LubeM_W) THEN
SET Lube, LubeS_T = LubeS_W, SET LubeS_T, RST LubeM_T, LubeAccumTime_W = 0
IF LubeS_T || !EStopOk THEN RST Lube, RST LubeS_T
Feedrate Override
Feedrate Override allows changing the master feedrate or commanded velocity if it is
enabled. The basic feedrate override starts by reading the Feedrate potentiometer then
scaling it to 0% to 200% from 0 to 256. The program then determines whether the Feedrate
Last Modified 2010-10-11 11:21:28 AMPage 42 of 134
knob or the keyboard feedrate keys should be applied to CNC11. The maximum value is
limited by parameter 39. Parameter 78 allows the feedrate value to be adjusted down if the
spindle speed does not keep up with the command so CNC11 gets to see if it wants to modify
the Feedrate Override. Finally the PLC program has one last chance to change the new value
coming back from CNC11, though typically it should not.
There is now a feature that allows using keyboard and Knob override at the same time. By
default the Knob is used, but if the Feedrate Override keyboard keys are used, then the
Feedrate override displayed is based on the Keyboard value and not the Knob value. When
the Knob is turned again more than 3%, however that value is displayed.
Spindle Functionality
Spindle DAC Output
Precise spindle speed is controlled through an inverter by sending an analog signal from the
PLC to tell the inverter what speed to go at. The inverter must be calibrated to the analog
signal with a tachometer or spindle encoder. This section only details setting up the PLC side
of inverter control. Spindle Digital to Analog output or DAC is set by the PLC Program based
on the commanded Spindle Speed from the 'S' command in G-Code, the Spindle Override
value and the Spindle Gear Ratio. The DAC Spindle Speed command won't be seen by
MPU11 until the DoSpindleStart (SV_PLC_FUNCTION_37) goes from off to on or DoSpindleStop
(SV_PLC_FUNCTION_38) goes from on to off. This means that the Spindle Start Key cannot be
held down at boot and have the spindle start as the software starts. This is a good thing. Both
or either one of the Start or Stop can be used to control turning the Spindle on and off. Keep
in mind that every time the Start or Stop changes state in the program, the DAC output will be
updated, either turning on or off. This means that in most cases you should choose one of the
two variables to use, rather than both, to avoid confusion.
The Spindle Analog Output bits are mapped to different places on different PLCs. The
following table outlines the MPU11 board and the outputs for the Spindle Analog.
PLCSpindle DAC Outputs
ALLIN1DC241-252
DC3IOB17-28
GPIO4D305-316
Spindle Gear Ranges
The basic PLC programs have two ranges defined. Low Range and High Range. The High
Range multiplier is taken from Parameter 33 and Low Range is taken from Parameter 65.
The example code is for a DC3IOB PLC program. The Inputs and Outputs for each of the
standard PLC programs is detailed in Appendix E.
Last Modified 2010-10-11 11:21:28 AMPage 43 of 134
The MPG or Manual Pulse Generator can be used to supplement Jog buttons. This section is
used to enable the MPG mode control in CNC11 for the standard Centroid CNC11 MPG. This
includes provisions for up to 4 axis in the basic PLC program with three step amounts. Note
that when the MPG is active, with the way this is programmed, jogging will not work. It can be
written into the PLC program that when a Jog Key is pushed to turn off MPG mode
temporarily. Windup mode is used to make sure that the motor moves all of the commanded
steps that the MPG sent. This is not desirable in x100 mode because turning the MPG fast
enough will result in motion well after the MPG has stopped turning.
Coolant refers to the Flood and Mist control. Automatic coolant does not allow turning on the
outputs unless the M7/M8 macros are used. Pushing the key to turn off Automatic coolant will
then allow manual only control where a button must be pushed to turn on/off the coolant.
There is some minimal protection built into the default PLC program to try and protect against
crashing a probe. If the Mechanical probe trips while jogging, a probe fault is triggered.
Jogging is not allowed in the direction that was being commanded when the probe tripped
until the probe is cleared.
This chapter covers optional sections of the PLC will go into detail about setting up the
Debounce registers and inverting Inputs. There are several new features in CNC11 PLC
programs, namely Input debounce and Input inversion. There is a standard value of 1.5 ms of
debounce applied to all applicable PLC inputs and 18 ms debounce for the jog panel. No
inputs are inverted by default. The PLC program can have debounce applied in excess of the
standard value for a particularly noisy input.
Debounce or Invert Inputs
When a physical Input goes from on to off or vice-versa the PLC may see multiple transitions
as the input turns on and off very quickly. Debounce is used to make sure that the Input is
really on or really off. Once the Input is seen as on or off for the specified time, it is considered
to be in that state and reported to the PLC program.
The PLCbus Inputs are Debounced at 1.5 ms by default, which is typically a decent value.
Sometimes a switch is extra noisy and require more time to settle into a state. When that
happens the debounce System Variables need to be adjusted. Debounce can be set for the
first 240 PLCbus physical Inputs, 112 Jog Panel Inputs and 32 MPU11 Local I/O. They are all
done with different System Variables, but the procedure is the same. The new Debounce
values must be set every time the MPU11 boots, so a good place to do this is in the
InitialStage.
The Debounce procedure scans at a certain rate, which determines the speed that an Input
can be Debounced. The following chart lays out the scan rate of each of the Input types with
Debounce. Keep in mind that the number of consecutive states of an Input required is
determined by dividing the desired Debounce time by the scan rate. For example to get 1.5
ms of Debounce on a standard Input requires 0.0015/0.0000625 = 24 scans. For reference 1
ms (millisecond) = 0.001 s and 1 μs (microsecond) = 0.000001 s.
Note that there are two different updates rates for the PLC Inputs depending on where the
Input is located. The Inputs directly on-board the DC3IOB and GPIO4D, for example are
updated at 16kHz, whereas the Inputs on the PLCADD1616 are updated at 4kHz. However,
the scan time for debounce (62.5μs) is the same for all PLC and and PLC expansion devices.
This means that even though the expansion devices update 4000 times per second they are
checked at 16000 times per second. Therefore 16000/4000 = 4 times the number of scans
must be done on an expansion board. Instead of doing 24 scans for 1.5 ms of debounce 96
scans must be done.
The minimum Debounce Time is 0 which equates to the base Scan Rate and the maximum
Debounce Time of 32768 equates to 2.048 s for PLC and MPU11 Local Inputs and 24.576 s.
Always use Debounce Time 2 or greater when making a custom time because
Debounce Time 1 is used by most Inputs by default and Debounce Time 0 is always 0
and cannot be modified.
Last Modified 2010-10-11 11:21:28 AMPage 48 of 134
The default values for all of the Debounce Inputs is listed below.
Default Debounce
Setting Value
Default Debounce
Time Value
Default Debounce
Time (ms)
PLC Inputs1241.5
Jog Panel Inputs12418
MPU11 Local I/O1*241.5
*Input 770 for the DSP Probe Defaults to 0. Do not change this value.
Each group of System Variables is broken up into two sections. The majority of the System
Variables are used for Debounce Setting to apply to the Inputs and the last few are for setting
up the Debounce Time. This means that there is not a separately named SV for the time and
selecting what Input is used, just a different number. The following table illustrates which
System Variables are for Inputs and which are for setting up the time.
System Variable RangeFunction
SV_PLC_DEBOUNCE_1 to _60
SV_PLC_DEBOUNCE_61 to _64
SV_JOG_LINK_DEBOUNCE_1 to _28
SV_JOG_LINK_DEBOUNCE_29 to _32
SV_LOCAL_DEBOUNCE_1 to _9
SV_LOCAL_DEBOUNCE_10 to _13
Select Debounce time to use for each Input
Choose number of scans to Debounce
Select Debounce time to use for each Input
Choose number of scans to Debounce
Select Debounce time to use for each Input
Choose number of scans to Debounce
For each of the three types of Debounced Input there are seven different times that can be
used in total. This means that any Input can have one of seven different times applied to it for
Debounce.
Each of the System Variables to setup Inputs are broken up into four 8 bit sections devoted to
one Input each. The layout for SV_PLC_DEBOUNCE_1 is illustrated in the following table, but all of
the System Variables for setting up Inputs are divided the same way.
Last Modified 2010-10-11 11:21:28 AMPage 49 of 134
Each of the 8-bit Input Setting Bytes is laid out according to the following table.
Input Setting Bit NumberFunction
0Debounce Time Select 1-7 in binary
1
1 = Time 1
...
2
111 = Time 7
3reserved
4reserved
5reserved
6Invert Input
7Force Input On
In order to figure out which Debounce System Variable to use, divide the Input number by four
and add one. PLC Input 211 is on 211 / 4 = 52.75 plus one gives 53.75 for SV_PLC_DEBOUNCE_53.
The fractional component tells which of the four input bytes in the System Variable should be
set to get the correct Input. In the example above 0.75 is ¾ which points to Byte 3 out of 4 or
bits 16-24.
Setting up the Debounce Time System Variables is more strait forward because there are only
four System Variables that can be setup for each Input type. Each of the System Variables is
split into two 16-bit values with the lowest one in each category being unused. That is why
only Debounce times from 1 to 7 are allowed to be customized. Debounce Time 0 is always
set to 0 and cannot be modified. The following table illustrates the seven available Debounce
Times by System Variable.
Debounce Time Sys. Vars.Debounce Time
SV_PLC_DEBOUNCE_61
0 – 15 always set to 0
16 – 31 Debounce Time 1
SV_PLC_DEBOUNCE_62
0 – 15 Debounce Time 2
16 – 31 Debounce Time 3
SV_PLC_DEBOUNCE_63
0 – 15 Debounce Time 4
16 – 31 Debounce Time 5
SV_PLC_DEBOUNCE_64
Last Modified 2010-10-11 11:21:28 AMPage 50 of 134
There are several ways to setup the Debounce values. One option is to calculate out the bit
values in decimal for all 32-bits and add them all up. Another option is to create each 8-bits for
the Debounce Time or Debounce Setting in a temp Word and Left Shift the value up to the
correct place in the Word then add it to the Debounce System Variable. As an example the
following program reads sets up INP6 with a debounce time of 13 ms and inverts the input.
The values are recorded here in binary to show the bits changing. Note that these bits are
written left to right and Msb to Lsb whereas WTB writes bits Lsb to Msb left to right.
Example Input Debounce Setup Program
;Orignal INP6 Debounce Setting Word Value
;0000 0001 0000 0001 0000 0001 0000 0001
;Desired Debounce Setting bits for INP6
;0000 0000 0000 0000 0000 0101 0000 0000
;modified Debounce Setting Word with new bits added in
;0000 0001 0000 0001 0000 0101 0000 0001
;Original Debounce Time Word Value
;0000 0000 0001 1000 0000 0000 0001 1000
;Debounce Time after removing the 16 bits that will be replaced
;0000 0000 0000 0000 0000 0000 0001 1000
;Temp Debounce Time Word with new value shifted into place
;0000 0000 1101 0000 0000 0000 0000 0000
;Final Debounce Time Word with new time value
;0000 0000 1101 0000 0000 0000 0001 1000
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
;Program: debounce.src
;Purpose: Example Debounce Setup for INP6
; Set Time 5 for 13 ms., Invert Input
;Date: 20-APR-2010
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
;--Variable Defines
Debounce_2_Bits_M IS MEM1 ;display the bits from the Word
Debounce_63_Bits_M IS MEM35 ;display the new bits for the Word
Bit0_M IS MEM73 ; Deb Time Select Bit 0
Last Modified 2010-10-11 11:21:28 AMPage 51 of 134
IF 1==1 THEN Final_Deb_Time_W = Temp_Deb_Time_W + Shift_Deb_Time_W
;save the values back to the SV
IF 1==1 THEN SV_PLC_DEBOUNCE_2 = Final_Deb_W
IF 1==1 THEN SV_PLC_DEBOUNCE_63 = Final_Deb_Time_W
IF 1==1 THEN RST InitialStage, SET MainStage
;============
MainStage
;============
;write out bits of final Word settings for verification
IF 1==1 THEN WTB Final_Deb_W Debounce_2_Bits_M 32
, WTB Final_Deb_Time_W Debounce_63_Bits_M 32
Setting Inputs High or Low for Testing
The Debounce registers that store the settings for the Inputs can also be used to invert, at the
hardware level, the state of the input. This means that a Normally Closed Input can be turned
into a Normally Open Input.
Note that on the DC3IOB Inputs 1-6 and 11 are acted on at the hardware level before the
Force and Invert bits are looked at. This means that Normally Open Limits and E-Stop still
cannot be used.
There is also the ability to Force an Input to be SET. This should really never be used outside
of debugging on the bench due to the possibility of masking an input from indicating an error
has occurred. Inputs can be Forced off or RST by setting both the Invert and Force on bits.
Looking at the Table above that explains the layout of the Setting Bytes shows that Bit 7 and 6
are used for Forcing the Input and Inverting the Input respectively. Time 1 should always be
set if no custom Debounce time is going to be used.
In the following example the same input as above is going to just be Forced On and Inverted,
effectively forcing the input off all the time. This can be verified in PLC Diagnostics by toggling
INP6 and seeing that it does not change.
Last Modified 2010-10-11 11:21:28 AMPage 54 of 134
There are many ways that a program can be changed so that it does not function as intended.
Always start at the top of the list of errors because fixing earlier problems may fix repeat
errors later on. For example if you fail to define a variable that is used throughout the
program, every reference to that variable will generate an error.
If the compiler hangs or doesn't generate any output after ten seconds it is stuck on
something and will not compile the program most likely. Press Ctrl.+c to cancel compilation
and undo the last changes if the problem just started occuring. If you think the changes are
valid double check the usage and then send the file before and after to Tech. Support.
There is a limit of about 1000 characters per line that the compiler can digest so do not go
above that limit. Typically you should stick to 80 characters so that the document can be
printed and not cause the printout to look different than on your monitor.
The easiest to fix are compiler related syntax or expression errors. The first to sections details
what potential errors mean.
Warnings
Already Defined
This message does not cause compilation to fail, but you should address this problem
because using two different variables to do two different things will cause very hard to detect
logical errors.
Direct PLC Reference
This Warning occurs when you test or use a specific data type directly by name. An example
is using MEM1 instead of defining Test_M IS MEM1 and using Test_M in the program.
General Errors
These errors specify problems with the program that are more serious than an undefined
variable. They are not related to the code in the Program, but the way that the compiler was
called.
Malformed Command Line
This error means the the attempt to compile the program failed because no source file was
specified.
Last Modified 2010-10-11 11:21:28 AMPage 58 of 134
An invalid switch was used on the command line. Presently there are two options for
switches. Neither of them should be used except for testing and debugging the compiler itself.
The output is not usable as a PLC Program. The options are -i for outputting a CSV version of
the program to be used as an include file and -d is for verbose debugging of what the
compiler does with each token in the program. This may be used when there is a suspected
problem with the compiler.
Error Opening File
The specified source file was not found in the directory that mpucomp was called from. There
are two ways to compile the program. The easiest is to open a command prompt and change
directories to the folder where the source file is located. Then you can issue the command
'mpucomp(.exe) source.src mpu.plc'. On Windows you must have mpucomp.exe in the same
folder as the source file unless you add c:\cncm\bin to your PATH. In Linux this has been
done for you so mpucomp does not need to be in the same folder as the source file. The
other way of compiling a program is to call mpucomp and give the absolute path to the source
file and/or destination file. For example, the source file is in /cncroot/c and the command line
indicates the current folder is /cncroot. To compile the source file and get the PLC program to
the correct folder 'mpucomp /cncroot/c/source.src /cncroot/c/cncm/mpu.plc' must be
executed.
Syntax Errors
These are errors related to specific lines in the PLC program. Usually the offending line and
column number is listed along with the specific error. Sometimes the row is one farther down
the program than it should be so look around the area specified.
Compilation Failed
This message occurs when there are problems in the source file. It is displayed as the last
message after other error messages. This message will not appear if there are too many
errors.
Too Many Errors
This message is displayed when more than 25 errors occur at compile time. This can easily
happen if you forget to define a Label and use it often in the program.
Undefined Label
This message occurs when a valid variable name is used without it being defined in the
definition section of the PLC program.
Last Modified 2010-10-11 11:21:28 AMPage 59 of 134
[THEN, Word Type, Stage, Output, Parenthesis] expected
This message is generated when something is expected, but is not found. A Parenthesis is
expected on the right if you put on one the left of a variable or expression.
IF INP1) THEN SET OUT1
End Of File Expected
This message can be generated many different ways, but the meaning is that a line was not
written correctly. It can be caused because the IF at the start of a line was not used after the
first IF statement in the program.
[Data Type] Out of Bounds
This message can occur on any Data Type when using the Indexing ability in the compiler.
The error is generated when you make a constant reference to a Data Type number that
cannot be accessed. For example if you try IF 1==1 THEN SET OUT[500000000] you will get this
error. It is possible to fool the compiler and index out of range. See Internal PLC Fault
Checking for how to detect this occurring and why it is so catastrophic. This error will not be
caught if you type If 1==1 THEN SET OUT[W1+W2] and set W1 and W2 to 250000000 each.
Invalid Action
This error occurs when doing something that is not allowed. This includes trying to store a
value into a Bit data type or a Constant define and failing to put a start location for a Range.
CONST1 IS 1 ;constant value
IF 1==1 THEN CONST1 = 10 ;cannot re-assign constant values
IF 1==1 THEN MEM1 = 10 ;cannot store Word values into Bits
IF 1==1 THEN .. OUT20 ;must include starting point for Range
IF 1==1 THEN SET W1 ;SET cannot be applied to Words
Rung Expected IF
The Keyword IF was not found after a valid STG reference.
STG2
1==1 THEN (OUT1)
Rung Expected THEN
The Keyword THEN is missing from the line specified.
IF 1==1 SET OUT1
Last Modified 2010-10-11 11:21:28 AMPage 60 of 134
If you call the JMP command and do not specify what Stage to Jump to, this message is
displayed.
System Variable is Read-Only
Attempting to modify a Read-only System Variable will result in this message displayed. The
Read-only variables are ones that CNC11 has write control of here.
MSG Expected Word Reference
This error occurs when you try to use the MSG command with no Word variable or with an
invalid data type. If no data type is specified, then the error will actually show up on the next
line of the program and not show the MSG reference at all in most cases. This occurs
because the compiler does not assume that a line feed is the end of a command. For
example the first IF statement spanning two lines in the following code will compile whereas
the second on only one line will not.
IF 1==1 THEN MSG
W1
IF 1==1 THEN MSG INP1
SMSG Expected String Reference
The SMGS functionality expects a string value and anything else causes this error. A string is
defined as text between double quotes.
IF 1==1 THEN SMSG W1 ;not a string
BCD/BIN Expected Word Reference
If you fail to put a Word type variable right after the BCD and BIN command this error occurs.
IF 1==1 THEN BIN MEM1 32
BCD/BIN Cannot Use Bracketed Reference
Indexes are not allowed on Words when doing the BCD or BIN commands.
IF 1==1 THEN BCD W[10]
WTB Expected Word Reference
If you fail to put a Word type variable right after the WTB command this error occurs.
IF 1==1 THEN WTB MEM1 32
Last Modified 2010-10-11 11:21:28 AMPage 61 of 134
If the Memory or Output location is not specified, this error occurs.
IF 1==1 THEN WTB W1 33
WTB Number of Bits Must be 1-32
When using the WTB command you can specify a number of bits to write. That value must be
from 1 to 32. The incorrect value is shown after the error.
IF 1==1 THEN WTB W1 MEM1 33
BTW Expected Word Reference
If you fail to put a Word type variable right after the BTW command this error occurs.
IF 1==1 THEN BTW MEM1 32
BTW Expected INP/OUT/MEM Reference
If the Input, Memory or Output location is not specified, this error occurs.
IF 1==1 THEN WTB W1 33
BTW Number of Bits Must be 1-32
When using the BTW command you can specify a number of bits to write. That value must be
from 1 to 32. The incorrect value is shown after the error.
IF 1==1 THEN BTW W1 MEM1 33
BITSET/RST Bit Must be 0-31
When using the BITSET or BITRST commands you must specify the bit number to SET or RST.
That value must be from 0 to 31. The incorrect value is shown after the error.
IF 1==1 THEN BITSET W1 43
BITSET/RST Expected an Integer Value
Bits can only be changed by positive Constant Integer numbers so using a floating-point
number, negative or Word value to try and change one will fail.
IF 1==1 THEN BITRST W1 1.5
IF 1==1 THEN BITSET W1 W2
IF 1==1 THEN BITSET W1 -10
BITSET/RST Word Indexing Not Allowed
Using the Index ability is not allowed when doing a BITSET/RST command.
Last Modified 2010-10-11 11:21:28 AMPage 62 of 134
If you fail to put a Word type variable right after the BITSET or BITRST command this error
occurs.
IF 1==1 THEN BITSET MEM1 4
BITTST MEM Indexing Not Allowed
Using the Index ability is not allowed when doing a BITTST command.
IF 1==1 THEN BITTST W2 2 MEM[5+1]
BITTST Expected MEM
The last of three arguments to a BITTST must point to a Memory Bit and it was not found or
the wrong type was specified.
if 1==1 then BITTST w1 2 OUT1
BITTST Expected Word Reference
If you fail to put a Word type variable right after the BITTST command this error occurs.
IF 1==1 THEN BITTST INP1 5 MEM1
BITTST Bit Must be 0-31
When using BITTST you must specify the bit number to check in the Word. That value must
be from 0 to 31. The incorrect value is shown after the error.
IF 1==1 THEN BITTST W1 43 MEM1
BITTST Expected Integer Value
Bits can only be changed by positive Constant Integer numbers so using a floating-point
number, negative or Word value to try and change one will fail.
IF 1==1 THEN BITTST W1 1.5 MEM1
IF 1==1 THEN BITTST W1 W2 MEM1
IF 1==1 THEN BITTST W1 -10 MEM1
BITTST Word Indexing Not Allowed
Using the Index ability is not allowed when doing a BITTST command.
IF 1==1 THEN BITTST W[2+5] 2
Last Modified 2010-10-11 11:21:28 AMPage 63 of 134
When using the LSHIFT/RSHIFT commands you must specify the number of bits to shift. That
value must be from 0 to 31. The incorrect value is shown after the error.
IF 1==1 THEN LSHIFT W1 99
LSHIFT/RSHIFT Expected Integer Value
Bits can only be changed by positive Constant Integer numbers so using a floating-point
number, negative or Word value to try and change one will fail.
IF 1==1 THEN LSHIFT W1 1.5
IF 1==1 THEN LSHIFT W1 W2
IF 1==1 THEN LSHIFT W1 -10
LSHIFT/RSHIFT Word Indexing Not Allowed
Using the Index ability is not allowed when doing a LSHIFT/RSHIFT command.
IF 1==1 THEN LSHIFT W[10+2] 2
LSHIFT/RSHIFT Expected Word Reference
If you fail to put a Word type variable right after the LSHIFT/RSHIFT command this error
occurs.
IF 1==1 THEN LSHIFT MEM1 4
Constant Integer Expression Label Not Found
If you reference a constant when defining other constants, but the referenced constant does
not exist yet you will get this message. The following example will generate this error.
CONST2 IS 2*CONST3
Constant Integer Expression Expected Right Parenthesis
This error is generated when a left parenthesis is used to declare a constant, but the right
parenthesis is left off.
CONST1 IS (10+2
Constant Integer Factor Expected
Constant math can only be done on Integer values. Putting a Floating-point value in a
constant define that does math will give this error.
CONST1 IS (10+2.2)
Last Modified 2010-10-11 11:21:28 AMPage 64 of 134
Constant Integer Expression Label Does Not Reference an Integer
If you create a Constant that stores a floating-point value and then use it in the declaration of
an Integer Constant you will get this message.
CONST1 IS 11.2
CONST2 IS (CONST1/2)
Constant Integer Expression Label not Found
This error only occurs when a previous Constant expression definition is invalid and it is
referenced by another Constant expression definition.
CONST1 IS (11.2) ;invalid because of parentheses, only constant numbers allowed
CONST2 IS (CONST1/2);invalid CONST1 causes another error.
Relational Operator Expected
A comparison of data types that need a Relational Operator used on them to evaluate to true
or false is needed rather than the used operator.
IF W1 = W2 THEN SET OUT1 ;assignment not allowed before THEN
IF !W2 THEN SET OUT2 ;Logical Operator not allowed on Words
System Variable Bits Cannot be Used With '..'
The Range selector cannot be used on any System Variables.
IF 1==1 THEN SET SV_ENABLE_AXIS_1 .. SV_ENABLE_AXIS_8
Range Extension Expected OUT/MEM/STG/FSTG/T
When specifying a Range, the end of the Range was not specified. This error will be shown
on the next line after the error actually occurs. One of the listed types must be used to finish
the Range. It must be the same type that is on the left of the Range select.
IF 1==1 THEN SET OUT1 ..
Range Error. End is Before Start
The Range selectors were specified out of order. They must be used from lower to high bits.
IF 1==1 THEN SET OUT10 .. OUT1
SET/RST Expected OUT/MEM/STG/FSTG/T/Modifiable SV
This message is generated when you try to SET or RST something that the action cannot be
applied to or nothing is supplied. Inputs, One-Shots, Words, and Word type System Variables
are all examples of things that cannot be SET or RST.
IF 1==1 THEN SET
Last Modified 2010-10-11 11:21:28 AMPage 65 of 134
This error occurs when trying to use Coils on Data Types that cannot be SET/RST. This includes
Word types and Timers. There is no point turning on a Timer to check that only lasts one pass
of the PLC program. Words can have bits in them SET and RST using BITSET and BITRST.
IF INP1 THEN (T2)
Expected Right Bracket
This message occurs when a left bracket is used and a right one is not found.
if 1==1 then set out[10+3
if 1==1 then set out[10+3)]
Expected Left Bracket
This error occurs because a variable that can use Indexing had a space after the variable
name and no bracket was found. The compiler then expects to see a Left Bracket. You may
not be doing an Index reference at all, but merely had a space where there should not be one.
IF 1==1 THE SET OUT 10]
IF 1==1 THEN BTW W 3] 10
Bad Definition
The attempt at defining a variable is not written correctly. Brackets and negative numbers are
not allowed. Constant defines are used for messaging mostly.
Const is [10] ; brackets cannot be used in the definition section of a PLC program
Number Expected Right Parenthesis
A right Parenthesis was expected in a math calculation in the Program.
IF 1==1 THEN W1 = (10 + 50
Numerical Factor Expected Right Parenthesis
Any command such as ABS, SIN, etc. is listed and then the calculation to be done is in
parentheses afterwards. If the parenthesis on the right is missing, this error occurs.
if 1==1 then W1 = abs (10*5
Numerical Factor Expected Left Parenthesis
Any command such as ABS, SIN, etc. is listed and then the calculation to be done is in
Last Modified 2010-10-11 11:21:28 AMPage 66 of 134
These examples strive to give examples of using some of the various PLC functionality that
isn't used in a standard PLC program. The examples are not meant to be useful in what is
accomplished, but rather in how it is accomplished.
Toggle an Output Every Second
Pseudo-code
In InitialStage Second_On_T = 1000, Second_Off_T = 1000, SET Second_Off_T
IF Second_On_T THEN RST Second_On_T, SET Second_Off_T, RST OUT1
IF Second_Off_T THEN RST Second_Off_T, SET Second_On_T, SET OUT1
Aux Key Jogging
Pseudo-code
IF Aux2 THEN Y+_Jog
IF Aux8 THEN Y-_Jog
IF Aux4 THEN X-_Jog
IF Aux6 THEN X+_Jog
IF Aux3 THEN Z+_Jog
IF Aux9 THEN Z-_Jog
IF Aux1 THEN W+_Jog
IF Aux7 THEN W-_Jog
Aux Key Override of M-Code
Pseudo-code
IF M-Code && (CNC_PROG_RUNNING || AUX14) THEN SET M-Code_Stage
Wait One Second Before Jogging on Key Press
Pseudo-code
IF !(all jog keys) THEN RST Jog_T
IF any jog key THEN SET Jog_T
IF Jog_T THEN DO Ax#_Jog
Interpret Enter Key as Cycle Start in MDI*
*Note that Centroid does not recommend doing this. It is merely an example of what is
Last Modified 2010-10-11 11:21:28 AMPage 68 of 134
possible as far as customizing the User experience. Often, after typing a command in MDI it is
natural to hit Enter to try to run the line, but that merely causes a prompt to push Cycle Start
to appear. With this change that will not happen. This functionality should only be allowed
when in MDI to prevent unexpected motion.
Pseudo-code
IF MDI_MODE && AllowKBJog && Kb_Enter_Key THEN Cycle_Start
Count Machine On Time
Use a Timer to count one day and then increment a word. Update P171 every 30 min. to keep
track of the value. Read the value of P170 in the Initial stage and increment values to it.
Last Modified 2010-10-11 11:21:28 AMPage 69 of 134
Pick an unused M94/M95 bit and assign it the name of the custom M-Code. Create an
mfuncXXX.mac file that has the same number as the assigned M-Code. Put whatever you
want in the M-Code and if the PLC program needs to do something, put code in to check for
MXXX being SET or RST.
Using One M94/M95 Bit and a Parameter
In the custom M-Code SET the bit with M94 and G10 a parameter in the 171-177 range to a
different binary value for each M-Code. Use 1, 2, 4, 8, 16, 32, etc. so that you can use BITTST.
Alternatively, you can just use decimal numbers and check Parameter == 1, ==2, ==3, etc.
Customizing Standard M-Codes
In the basic MPU11 PLC programs there are four “customized” M-Codes by default. They are
for Spindle directions and Coolant. The reason that they are considered custom is that rather
than using the built in CNC11 functionality, files were created to extend the original
functionality. Now there is a message printed on screen that halts execution if an auto spindle
or coolant function is called and prompts the user to put the control in auto mode. This can be
done for many of the M-Codes to expand the usability of or modify the given feature. The
following example shows how the M3 and M4 M-Codes were changed.
Automatic Spindle On/Off – M3/M4
When a default M3 is commanded the Spindle should start spinning in the clockwise direction.
If the control is in manual spindle mode though, the spindle will not turn on and program
execution will continue like everything is fine. This is bad, so a warning should be given to the
user and execution paused. The same holds true for Automatic Coolant which is why the
custom M7 and M8 are needed.
;------;M3 macro
; Displays message to select auto spindle mode if it is not SET
;------;if searching or backplotting a program, skip the macro
IF #4202 || #4201 THEN GOTO 200
M95 /2 ; turn off CCW spindle
M94 /1 ;turn on CW spindle
;if AutoSpindle i.e. OUT1058 (a.k.a. JPO2) is set, exit the Macro
IF #61058 THEN GOTO 200
G4 P.1
#140 = 1.5
N100
Last Modified 2010-10-11 11:21:28 AMPage 70 of 134
; If not in AutoSpindle Mode display a message and wait
IF !#61058 THEN M225 #140 "Please Select Auto Spindle To Continue!"
G4 P.5
IF !#61058 THEN GOTO 100
N200
Last Modified 2010-10-11 11:21:28 AMPage 71 of 134
This chapter contains some suggestions for debugging problems in your PLC program.
Write Down and Think Through Changes to the Program
Before making any changes to a PLC Program you should always take a report. Write out as
specifically as possible the exact functionality that is to be implemented. This potentially
includes timeouts, fault conditions, interactions with other Inputs and Outputs, messages that
will need to be shown to the User, etc.
PLC Diagnostic Screen
When at the main screen, push Alt.-i to cause the PLC Diagnostic screen to appear. It
appears over running jobs so it should not be left on all the time, especially if there are user
prompts in the program. The red and green dots represent Inputs, Outputs, Memory and
Stage Bits. Red means the Bit is off or open and Green means the Bit is closed or on. This is
true in all cases for the Bits. Keep in mind that setting the Invert or Force Debounce bits will
change the way the Inputs are reported to the PLC program and thus the PLC Diagnostic
screen.
The screen shows the state of Bits 80 at a time for the entire range available for that Bit type
and 12 Words per page. All 1312 available Inputs and Outputs are shown as are all 1024
Memory Bits and 256 Stages. Presently the 44 Words that are sent up to CNC11 are shown
as well. This means that all the Jog Panel buttons and LEDs as well as Spindle DAC outputs
can be seen without mirroring them to the 1 to 80 range. This is true as of CNC11 3.0 rev84
beta release.
Future improvements include adding FW, DW, DFW, FSTG, and Timer display to the screen.
PLC Bit-State Dump
When the PLC Diagnostic screen is showing, pushing the Ctrl.- i key combination will cause
the state of all the Bit variables to be stored to a file called plcstate.txt. This file is overwritten
every time the operation is performed. This feature will be implemented in the future.
DUMP
Use the DUMP PLC command to print all of the values of the first 64 Word type variables to
disk. This can be called at any time to check status words or ATC bin position in a certain
stage. Make sure to call this infrequently because it does take quite a long time to write to
disk compared to the time to execute the PLC program once.
Last Modified 2010-10-11 11:21:28 AMPage 72 of 134
Transient signals that are on and then quickly off may not show up reliably on the PLC
Diagnostic screen long enough to see because the display only updates 30 times/second. In
this case, to verify that the bit is changing at all you can SET a Memory Bit if the Bit in question
ever gets SET or RST. It is a good idea to incorporate the ability to RST these diagnostic Bits into
an unused Aux Key so that you do not have to power off the system to RST them.
Use Stages
Group new features into a Stage so that it can be turned on and off to check for problems.
Use more stages for more complex features to narrow down where you need to troubleshoot.
Communication In/Out Faults
DriveBus
These faults occur when the communication on the DriveBus is disrupted. The DriveBus goes
out on fibers 4 and 5 from the MPU11 and across the Drive Communication In/Out wire
connections on the ALLIN1DC, Optic4 and DC3IOB. If any of these connections exist and are
checked in the PLC program correctly, they will help diagnose connection problems.
PLCBus
The PLCBus also should be checked in the PLC program to make sure that communication is
in a good state. There should be checks for the Fibers 1 and 3 and miniPLCBus connections
if expansion boards are used.
Last Modified 2010-10-11 11:21:28 AMPage 73 of 134
This is the basic PLC program using an ALLIN1DC drive and PLC.
;------------------------------------------------------------------------------; File: allin1dc-basic.src
; Programmer: Scott Pratt, Keith Dennison
; Date: 7 April 2010
; Purpose: PLC for MPU11 and allin1dc + keyboard jog
; Requires: Requires CNC11 R83+
;
; $Id: allin1dc-basic.src 431 2010-08-23 14:06:41Z drew $
;
;NOTE Changes to keyboard jogging bmp needed. See MEM400+
; "Invalid key" messages will need to be supressed
; Mpu11 based systems have the ability to invert, force and/or select a custom
; debounce time on PLC inputs 1-240 using SV_PLC_DEBOUNCE_1-SV_PLC_DEBOUNCE_64.
; Jog Panel inputs are modified in the same manner using SV_JOG_LINK_DEBOUNCE_1
; -SV_JOG_LINK_DEBOUNCE_64. See system variable section for more information.
; The Mpu11 board includes connections for several types of auxillary I/O.
; 4 digital "high speed" inputs (INP769-772) typically used for probe/TT1
; related functions,, 3 auxillary digital inputs (INP784-786), 11 Digital inputs
; used for MPG increment and axis selection and 2 auxillary digital outputs
; (Out770-771).
; ALLIN1DC Physical I/O: While each ALLIN1DC that is installed reserves (maps)
; 32 inputs and 32 Outputs, only 16 inputs and 9 outputs are accessible through
; hardware.
; Digital Inputs: The ALLIN1DC provides 16 inputs, 10 of which are available for
; general purpose use. The first 6 inputs (1-6) are dedicated for limit switch
; use and must be either wired to a NC limit switch or defeated. All 16 inputs
; can be configured (in banks of 4) for 5, 12 or 24VDC operation in either a
; sourcing or sinking configuration.
; Analog input: The ALLIN1DC provides a single 12 bit analog input which is
; mapped to inputs 241-252. LSB = 241. This input can be configured for the
; following input:
; Outputs: The ALLIN1DC has 9 relay contact closure outputs. Outputs 1-7 are
; are SPST type relays while Outputs 8 & 9 are SPDT type relays.
; Analog outputs: The 12 bit 0-10VDC analog output on the ALLIN1DC is mapped to
; outputs 241-252. NOTE: The spindle speed command that comes down from the PC
; (SV_PC_DAC_SPINDLE_SPEED) is a 16 bit integer value from 0-65535 that must be
; converted to a 12 bit value from 0-4095 by the PLC. The PLC handles gear ranges
; by looking at the state of inputs and reading parameters (or hard coded values)
; to determine the ratio needed for adjusting the spindle speed display system
; variable
AXIS1_INFLT IS 1282;(2+256*5) Fiber to MPU11 has a problem
AXIS2_INFLT IS 1538;(2+256*6)
AXIS3_INFLT IS 1794;(2+256*7)
AXIS4_INFLT IS 2050;(2+256*8)
AXIS5_INFLT IS 2306;(2+256*9)
AXIS6_INFLT IS 2562;(2+256*10)
AXIS7_INFLT IS 2818;(2+256*11)
AXIS8_INFLT IS 3074;(2+256*12)
AXIS1_OUTFLT IS 3330;(2+256*13) Fiber to axis drive has a problem
AXIS2_OUTFLT IS 3586;(2+256*14)
AXIS3_OUTFLT IS 3842;(2+256*15)
AXIS4_OUTFLT IS 4098;(2+256*16)
AXIS5_OUTFLT IS 4354;(2+256*17)
AXIS6_OUTFLT IS 4610;(2+256*18)
AXIS7_OUTFLT IS 4866;(2+256*19)
AXIS8_OUTFLT IS 5122;(2+256*20)
AXIS_FLT_CLR IS 5378;(2+256*21)
PLC_INFLT IS 5634;(2+256*22)
PLC_OUTFLT IS 5890;(2+256*23)
PLC_FLT_CLR IS 6146;(2+256*24)
SPINDLE_FAULT IS 7681;(1+256*30)
PROBE_FAULT_MSG IS 8705;(1+256*34)
KB_JOG_MSG IS 8962;(2+256*35)
LUBE_FAULT_MSG IS 9217;(1+256*36)
LUBE_WARNING_MSG IS LUBE_FAULT_MSG+1
PROBE_JOG_FAULT_MSG IS 9473;(1+256*37)
MIN_SPEED_MSG IS 9730;(2+256*38)
SOFTWARE_EXIT_MSG IS 1+256*39
MSG_CLEARED_MSG IS 25345;(1+256*99)
Last Modified 2010-10-11 11:21:28 AMPage 75 of 134
;---------------------------------------------------------------; INPUT DEFINITIONS
; Closed = 1 (green) Open = 0 (red)
;---------------------------------------------------------------Ax1_MinusLimitOk IS INP1
Ax1_PlusLimitOk IS INP2
Ax2_MinusLimitOk IS INP3
Ax2_PlusLimitOk IS INP4
Ax3_MinusLimitOk IS INP5
Ax3_PlusLimitOk IS INP6
;spare IS INP7
;spare IS INP8
LubeOk IS INP9 ;Lube is "ok" when input is closed
SpindleInverterOk IS INP10 ;Inverter is "ok" when input is closed
EStopOk IS INP11
SpinLowRange IS INP12
;spare IS INP13
;spare IS INP14
;spare IS INP15
;spare IS INP16
;Inputs 17-32 are unvailable
;If a PLC expansion board (PLCADD1616) is used, the additional inputs will
;begin at input 33.
;---------------------------------------------------------------; INP769 - INP784 encompass the MPU11 onboard input connections
; which are generally used for MPG and probing functions.
;---------------------------------------------------------------MechnicalProbe IS INP769
DSPProbe IS INP770
ProbeDetect IS INP771
ProbeAux IS INP772
MPG_Inc_X_1 IS INP773
MPG_Inc_X_10 IS INP774
MPG_Inc_X_100 IS INP775
MPG_AXIS_1 IS INP776
MPG_AXIS_2 IS INP777
MPG_AXIS_3 IS INP778
MPG_AXIS_4 IS INP779
MPG_AXIS_5 IS INP780
MPG_AXIS_6 IS INP781
MPG_AXIS_7 IS INP782
MPG_AXIS_8 IS INP783
;---------------------------------------------------------------; Jog panel keys are referenced as JPI1 through JPI256. Alternatively,
; jog panel inputs can also be referenced as INP833-INP1088.
;---------------------------------------------------------------; Definitions follow JOGBOARD layout top to bottom, left to right
SpinOverPlusKey IS JPI1 ; Row 1 Column 1
SpinAutoManKey IS JPI2 ; Row 1 Column 2
Last Modified 2010-10-11 11:21:28 AMPage 76 of 134
ToolCheckKey IS JPI48 ; Row 10 Column 3
FeedHoldKey IS JPI49 ; Row 10 Column 4
CycleStartKey IS JPI50 ; Row 10 Column 5
;---------------------------------------------------------------; Feedrate Override Knob
;---------------------------------------------------------------JpFeedOrKnobBit0 IS JPI193
JpFeedOrKnobBit1 IS JPI194
JpFeedOrKnobBit2 IS JPI195
JpFeedOrKnobBit3 IS JPI196
JpFeedOrKnobBit4 IS JPI197
JpFeedOrKnobBit5 IS JPI198
JpFeedOrKnobBit6 IS JPI199
JpFeedOrKnobBit7 IS JPI200
JpFeedOrKnobBit8 IS JPI201 ; Current jog panels send first 8 bits
JpFeedOrKnobBit9 IS JPI202 ; unused
JpFeedOrKnobBit10 IS JPI203 ; unused
JpFeedOrKnobBit11 IS JPI204 ; unused
JpFeedOrKnobBit12 IS JPI205 ; unused
JpFeedOrKnobBit13 IS JPI206 ; unused
JpFeedOrKnobBit14 IS JPI207 ; unused
JpFeedOrKnobBit15 IS JPI208 ; unused
;---------------------------------------------------------------; ALLIN1DC PLC Output Definitions
; Logic 1 = OUTPUT ON (Green), 0 = OUTPUT OFF (Red)
;---------------------------------------------------------------NoFaultOut IS OUT1 ;SPST Type
Lube IS OUT2 ;SPST Type
Flood IS OUT3 ;SPST Type
Mist IS OUT4 ;SPST Type
InverterResetOut IS OUT5 ;SPST Type
Clamp IS OUT6 ;SPST Type - M10 On, M11 Off & Aux7
SpindleEnableOut IS OUT7 ;SPST Type
SpindleDirectionOut IS OUT8 ;SPDT Type
; IS OUT9 ;SPDT Type
;Outputs 10-32 are unavailable
; These bits control the actual analog hardware output on the ALLIN1DC.
; Output = 12bit (0-4095) 0-10VDC.
SpinAnalogOutBit0 IS OUT241
SpinAnalogOutBit1 IS OUT242
SpinAnalogOutBit2 IS OUT243
SpinAnalogOutBit3 IS OUT244
SpinAnalogOutBit4 IS OUT245
SpinAnalogOutBit5 IS OUT246
SpinAnalogOutBit6 IS OUT247
SpinAnalogOutBit7 IS OUT248
SpinAnalogOutBit8 IS OUT249
Last Modified 2010-10-11 11:21:28 AMPage 78 of 134
Ax4MinusJogLED IS JPO41 ; Row 9 Column 1
UnusedR9C2LED IS JPO42 ; Row 9 Column 2
Ax2MinusJogLED IS JPO43 ; Row 9 Column 3
UnusedR9C4LED IS JPO44 ; Row 9 Column 4
Ax3MinusJogLED IS JPO45 ; Row 9 Column 5
CycleCancelLED IS JPO46 ; Row 10 Column 1
SingleBlockLED IS JPO47 ; Row 10 Column 2
; FOR JOGBRD REV??????, the LED outputs do not match Key inputs
; The PLC program should activate all three of these when
; it wants to turn on FeedHoldLED so that future hardware changes
; to put them in the same order as their corresponding inputs will work.
ToolCheckLED IS JPO50 ; Row 10 Column 3
FeedHoldLED IS JPO48 ; Row 10 Column 4
CycleStartLED IS JPO49 ; Row 10 Column 5
;---------------------------------------------------------------; Memory Bit Definitions
;---------------------------------------------------------------PLCExecutorFault_M IS MEM1
SoftwareReady_M IS MEM2
MPGManOffFlag_M IS MEM3
MasterEnable_M IS MEM5
DriveComFltIn_M IS MEM6
DriveComFltOut_M IS MEM7
PLCBus_Oe_M IS MEM8
ErrClr_M IS MEM9
PLCBus_Online_M IS MEM10
Ax1PlusJogDisabled_M IS MEM11
Ax1MinusJogDisabled_M IS MEM12
Ax2PlusJogDisabled_M IS MEM13
Ax2MinusJogDisabled_M IS MEM14
LubeFault_M IS MEM49
PLCFault_M IS MEM50
AxisFault_M IS MEM51
PLCBusExtDevEn_M IS MEM52
ProbeFault_M IS MEM53
JogProbeFault_M IS MEM54
Spindle_Fault_M IS MEM55
KbJpActive_M IS MEM60 ; aka SV_PC_VIRTUAL_JOGPANEL_ACTIVE
Axis1FiberOk_M IS MEM70
Axis2FiberOk_M IS MEM71
Axis3FiberOk_M IS MEM72
Axis4FiberOk_M IS MEM73
Axis5FiberOk_M IS MEM74
Axis6FiberOk_M IS MEM75
Axis7FiberOk_M IS MEM76
Axis8FiberOk_M IS MEM77
ProbeMsgSent_M IS MEM78
true IS MEM81
SpinLowRange_M IS MEM82
SpinHighRange_M IS MEM85
SpindlePause_M IS MEM86
Last Modified 2010-10-11 11:21:28 AMPage 80 of 134
DisableKbInput_M IS MEM102 ;If 1, disable kb jogging
AllowKbInput_M IS MEM103 ;If 1, allow kb jogging
JogOverOnly_M IS MEM105
KbOverOnly_M IS MEM106
UsingFeedrateKnob_M IS MEM117
WaitingForSleepTimer_M IS MEM118
X1_M IS MEM119
X10_M IS MEM120
X100_M IS MEM121
OnAtPowerUp_M IS MEM200
InvLubeOk_M IS MEM300 ; P178 Bit 0 (1) ; add 1 to parm 178 if
; lubeOk is NO
InvSpinInverterOk_M IS MEM301 ; P178 Bit 1 (2) ; Add 2 to parm 178 if
; InvSpinInverterOk_M is NO
KbCycleStart_M IS MEM400 ; "alt" + "s"
KbCycleCancel_M IS MEM401 ; escape
KbToolCheck_M IS MEM402 ; "Ctrl" + "t"
KbTogSingleBlock_M IS MEM403 ; "Ctrl" + "b"
KbIncreaseJogInc_M IS MEM404 ; "Insert"
KbDecreaseJogInc_M IS MEM405 ; "Delete"
KbIncFeedOver_M IS MEM406 ; "ctrl" + "keyboard "+" ("=")
KbDecFeedOver_M IS MEM407 ; "ctrl" + "keyboard "-"
KbFeedOver100_M IS MEM450 ; "ctrl" + "\"
KbTogIncContJog_M IS MEM408 ; "ctrl" + "i"
KbTogFastSlowJog_M IS MEM409 ; "ctrl" + "f"
KbJogAx1Plus_M IS MEM411 ; right arrow + KbJpActive_M
KbJogAx1Minus_M IS MEM412 ; left arrow + KbJpActive_M
KbJogAx2Plus_M IS MEM413 ; up arrow + KbJpActive_M
KbJogAx2Minus_M IS MEM414 ; down arrow + KbJpActive_M
KbJogAx3Plus_M IS MEM415 ; page up + KbJpActive_M
KbJogAx3Minus_M IS MEM416 ; page down + KbJpActive_M
KbJogAx4Plus_M IS MEM417 ; "home"+ KbJpActive_M
KbJogAx4Minus_M IS MEM418 ; "end" + KbJpActive_M
KbAux1Key_M IS MEM419 ; "ctrl" + "F1"
KbAux2Key_M IS MEM420 ; "ctrl" + "F2"
KbAux3Key_M IS MEM421 ; "ctrl" + "F3"
KbAux4Key_M IS MEM422 ; "ctrl" + "F4"
KbAux5Key_M IS MEM423 ; "ctrl" + "F5"
KbAux6Key_M IS MEM424 ; "ctrl" + "F6"
KbAux7Key_M IS MEM425 ; "ctrl" + "F7"
KbAux8Key_M IS MEM426 ; "ctrl" + "F8"
KbAux9Key_M IS MEM427 ; "ctrl" + "F9"
KbAux10Key_M IS MEM428 ; "ctrl" + "F10"
KbAux11Key_M IS MEM429 ; "ctrl" + "F11"
KbAux12Key_M IS MEM430 ; "ctrl" + "F12"
KbTogRapidOver_M IS MEM431 ; "ctrl" + "r"
KbTogSpinAutoMan_M IS MEM432 ; "ctrl" + "a"
KbSpinCW_M IS MEM433 ; "ctrl" + "c"
KbSpinCCW_M IS MEM434 ; "ctrl" + "w"
KbSpinStart_M IS MEM435 ; "ctrl" + "s"
KbSpinStop_M IS MEM436 ; "ctrl" + "q"
Last Modified 2010-10-11 11:21:28 AMPage 81 of 134
KbFloodOnOff_M IS MEM437 ; "ctrl" + "n"
KbMistOnOff_M IS MEM451 ; "ctrl" + "k"
KbTogCoolAutoMan_M IS MEM438 ; "ctrl" + "m"
KbFeedHold_M IS MEM439 ; space bar
KbIncSpinOver_M IS MEM440 ; "ctrl" + ">" (.)
KbDecSpinOver_M IS MEM441 ; "ctrl" + "<" (,)
KbSpinOver100_M IS MEM442 ; "ctrl" + "?" (/)
;----------------------------------------------------------------------------; ---------SYSTEM VARIABLES-------;
; For a complete list of System Variables and their functions, please see the
; MPU11 PLC manual.
;-----------------------------------------------------------------------------
; MPU11 based systems provide the PLC with the ability to read/write to a
; limited number of "System Variables". While the use of System Variables
; greatly expands PLC functionality, it comes with additional reponsibility on
; the part of the PLC programmer. Functionality that was once implemented as
; default behavior such as jogging, spindle speed, feedrate override, spindle
; gear ranges etc... is now implemented through System Variables in the PLC
; program. It is now the sole responsibilty of the PLC program to provide a
; method to jog an axis, override the spindle speed or feedrates or even map a
; jog panel keypress to a specific function. Pressing a jog key or Aux key
; won't DO anything unless the PLC assigns an action to the keypress. All jog
; panel functions MUST be explicitly implemented in the PLC program.
; ----IMPORTANT---; Menu navigation in the CNC software requires that the escape key or Cycle
; Cancel key is used to back out of menus and screens. You must use the PLC
; program to map a jog panel key and/or a keyboard key to the Cycle Cancel
; System Variable (SV_PLC_FUNCTION_1 has been declared as "DoCycleCancel")
; in order to use the control. For example:
; The following lines map the escape key and Jog Panel Cycle Cancel key to
; produce a Cycle Cancel event:
; 1. Map escape keypress event to identifier to describe what key was pressed.
; Kb_Escape IS SV_PC_Keyboard_Key_1
; 2. Map MEM bit to identifier that describes what the keypress is used for.
; KbCycleCancel_M IS MEM401
; 3. Logic to "set" KbCycleCancel_M anytime the escape key is pressed.
; if Kb_Escape THEN(KbCycleCancel_M)
; 4. Logic to cancel job if the escape key or cycle cancle key is pressed.
; IF (CycleCancelKey || KbCycleCancel_M) && SV_PROGRAM_RUNNING THEN
; (DoCycleCancel) THEN (DoCycleCancel)
; Some of the information made available to the PLC through System Variables:
; 1. Encoder positions: SV_MPU11_ABS_POS_1 - SV_MPU11_ABS_POS_7
; 2. Parameter values: SV_MACHINE_PARAMETER_1 - SV_MACHINE_PARAMETER_999
; 3. Spindle Speed command from PC: SV_PC_DAC_SPINDLE_SPEED
; 4. PC Keyboard Keypress: SV_PC_FUNCTION_1 - SV_PC_FUNCTION_127
; 5. ...
Last Modified 2010-10-11 11:21:28 AMPage 82 of 134
; Some of the functionality controlled by the PLC through System Variables:
; 1. Axis jogging: SV_PLC_FUNCTION_12 - SV_PLC_FUNCTION_23
; 2. "Final" Spindle speed reported to PC: SV_PLC_SPINDLE_SPEED -provides nearly
; unlimited gear ranges
; 3. Feedrate (through override knob): SV_PLC_FeedrateKnob_W
; 4. Custom debounce, invert/force inputs: SV_PLC_DEBOUNCE_1-SV_PLC_DEBOUNCE_64
; 5. ...
;----------------------------------------------------------------------------; PLC Input manipulation - SV_PLC_DEBOUNCE_1 - SV_PLC_DEBOUNCE_64
; The System Variables in this section are used to modify the characteristics
; of PLC inputs 1-240. Each input can be inverted, forced or assigned a custom
; debounce time.
;-----------------------------Debounce Times---------------------------------; SV_PLC_DEBOUNCE_61 - SV_PLC_DEBOUNCE_64 are used to define up to seven custom
; debounce times which can be selected for each input.
; The 32 bit integer System Variables SV_PLC_DEBOUNCE_61 - SV_PLC_DEBOUNCE_64,
; are broken up into 8, 16 bit words, only 7 of which are used. The first word,
; the 16 MSB of SV_PLC_DEBOUNCE_61 is unused. Each 16 bit word can be used to
; store a debounce time of between 0-32767 (the MSB of each word is unused).
; Debounce times are in increments of 62.5 usecs which provides debounce times
; of up to ~2 secs.
;------------------------Configuring Input Behavior--------------------------; Each System Variable from SV_PLC_DEBOUNCE_1 - SV_PLC_DEBOUNCE_60 is a 32 bit
; integer word broken up into 4 bit words to control the behavior of 4 inputs.
; Inputs 1-4 are configured using SV_PLC_DEBOUNCE_1, inputs 5-8 are handled
; using SV_PLC_DEBOUNCE_2 and so on to SV_PLC_DEBOUNCE_60 which controls inputs
; 237-240
; As mentioned above, each 32 bit word defines the charactersitics for 4 inputs.
; SV_PLC_DEBOUNCE_1 defines the characteristics of INP1, INP2, INP3 & INP4 and
; so on through SV_PLC_DEBOUNCE_60 which handles INP237, INP238, INP239&INP240.
; The behavior of an input is set as follows:
; Five new operators have been introduced to simplify bit operations:
; BitSet, BitRst, BitTst, LShift & Rshift. Below we will use bitset to
Last Modified 2010-10-11 11:21:28 AMPage 83 of 134
; invert an input. This is convenient to use when a device is normally
; open and the logic is written for a normally closed device. Inverting
; the input allows to reuse the existing logic rather than rewrite it.
; bitset and bitrst can not operate directly on SV_PLC_DEBOUNCE_# system
; variables, they can only operate on W32 variables. In order to use bitset and
; bitrst to manipulate the debounce variables you'll have to perform all
; operations on a w32 first:
; Declare a W32:
; Inputs_9_12_W IS W1
; use bitst or bitrst
; if 1 == 1 THEN bitset Inputs_9_12_W 14 ;invert INP10 (bit14)
; Set Debounce system variable = to W32 variable
; if 1 == 1 THEN SV_PLC_DEBOUNCE_3 = Inputs_9_12_W
; Each 8 bit word from above
; MSB 7 6 5 4 3 2 1 0 LSB
; Force Invert Spare Spare Spare Debounce Select (7)
; selects 1 of 7
; debounce times
; (zero is invalid)
; Force (bit 7): Set this bit to force the input to a 1* (closed)
; Ivert (bit 6): Set this to invert an input
; Spare(bit5-3): Not used
; Debounce(bit 0-2): Selects one of the 7 preset debounce times defined in
; SV_PLC_DEBOUNCE_61 - SV_PLC_DEBOUNCE_64
;
; *If you wish to force an input to 0, set the both invert AND force bits
; for the input.
;----------------------------------------------------------------------------; PLC Jog Panel input manipulation - The System Variables in this section are
; used to modify the characteristics of the Jog Panel keys. The jog panel keys
; can be configured in the same manner as the PLC inputs and use debounce times
; as selected/set in SV_PLC_DEBOUNCE_61 - SV_PLC_DEBOUNCE_64.
;-----------------------------------------------------------------------------
;---------------------------------------------------------------; System variables: Jog Panel Functions
;---------------------------------------------------------------; Jog panel functions
;Invalid IS SV_PLC_FUNCTION_0
DoCycleCancel IS SV_PLC_FUNCTION_1
DoCycleStart IS SV_PLC_FUNCTION_2
Last Modified 2010-10-11 11:21:28 AMPage 84 of 134
DoToolCheck IS SV_PLC_FUNCTION_3
SelectSingleBlock IS SV_PLC_FUNCTION_4
SelectX1JogInc IS SV_PLC_FUNCTION_5
SelectX10JogInc IS SV_PLC_FUNCTION_6
SelectX100JogInc IS SV_PLC_FUNCTION_7
SelectUserJogInc IS SV_PLC_FUNCTION_8
SelectIncContJog IS SV_PLC_FUNCTION_9
SelectFastSlowJog IS SV_PLC_FUNCTION_10
SelectMpgMode IS SV_PLC_FUNCTION_11
DoAx1PlusJog IS SV_PLC_FUNCTION_12
DoAx1MinusJog IS SV_PLC_FUNCTION_13
DoAx2PlusJog IS SV_PLC_FUNCTION_14
DoAx2MinusJog IS SV_PLC_FUNCTION_15
DoAx3PlusJog IS SV_PLC_FUNCTION_16
DoAx3MinusJog IS SV_PLC_FUNCTION_17
DoAx4PlusJog IS SV_PLC_FUNCTION_18
DoAx4MinusJog IS SV_PLC_FUNCTION_19
DoAx5PlusJog IS SV_PLC_FUNCTION_20
DoAx5MinusJog IS SV_PLC_FUNCTION_21
DoAx6PlusJog IS SV_PLC_FUNCTION_22
DoAx6MinusJog IS SV_PLC_FUNCTION_23
DoAux1Key IS SV_PLC_FUNCTION_24
DoAux2Key IS SV_PLC_FUNCTION_25
DoAux3Key IS SV_PLC_FUNCTION_26
DoAux4Key IS SV_PLC_FUNCTION_27
DoAux5Key IS SV_PLC_FUNCTION_28
DoAux6Key IS SV_PLC_FUNCTION_29
DoAux7Key IS SV_PLC_FUNCTION_30
DoAux8Key IS SV_PLC_FUNCTION_31
DoAux9Key IS SV_PLC_FUNCTION_32
DoAux10Key IS SV_PLC_FUNCTION_33
SelectRapidOverride IS SV_PLC_FUNCTION_34
SelectManAutoSpindle IS SV_PLC_FUNCTION_35
DoSpindleStart IS SV_PLC_FUNCTION_37
DoSpindleStop IS SV_PLC_FUNCTION_38
DoAux11Key IS SV_PLC_FUNCTION_39
DoAux12Key IS SV_PLC_FUNCTION_40
;SelectCoolantMan IS SV_PLC_FUNCTION_41 ;deprecated
;SelectCoolantAuto IS SV_PLC_FUNCTION_42 ;deprecated
SelectCoolantFlood IS SV_PLC_FUNCTION_43
SelectCoolantMist IS SV_PLC_FUNCTION_44
DoFeedHold IS SV_PLC_FUNCTION_45
SelectSpindleCCW IS SV_PLC_FUNCTION_98
SelectSpindleCW IS SV_PLC_FUNCTION_99
SelectCoolAutoMan is SV_PLC_FUNCTION_104
DoIncreaseSpindleOr IS SV_PLC_FUNCTION_106
DoDecreaseSpindleOr IS SV_PLC_FUNCTION_107
SelectSpinOr100 IS SV_PLC_FUNCTION_108
;---------------------------------------------------------------; System variables: Keyboard jogging functions
;---------------------------------------------------------------;-------------------------------------------------------------------------------
Last Modified 2010-10-11 11:21:28 AMPage 85 of 134
; Keyboard Jogging Keys - The System Variables in this section inform the PLC
; that a PC keyboard keypress has occured. Keep in mind that some key presses
; only come down while the keyboard jogging screen is enabled (alt-j) and that
; NONE of these keys not perform ANY default actions unless programmed to do so.
; The assignments provided below are for reference only. For an example of
; mapping a keyboard key press to an MPU11 action, see the logic assigned to
; KbCycleStart_M or KbCycleCancel_M.
;
;Note:
; Keypresses are sent down as individual keys. It is the resposibility of
; the PLC programmer to insure that a keypress is only acted on at the
; appropriate times.
; The "SV_PC_VIRTUAL_JOGPANEL_ACTIVE" system variable can be used to prevent
; a keypress form being acted on unless the keyboard jog screen is being
; displayed. NOTE The above,29 character sys variable is mapped to
; KbJpActive_M (MEM80) to make it a "little" shorter......
;------------------------------------------------------------------------------Kb_a IS SV_PC_KEYBOARD_KEY_60
Kb_b IS SV_PC_KEYBOARD_KEY_79
Kb_c IS SV_PC_KEYBOARD_KEY_77
Kb_d IS SV_PC_KEYBOARD_KEY_62
Kb_e IS SV_PC_KEYBOARD_KEY_41
Kb_f IS SV_PC_KEYBOARD_KEY_63
Kb_g IS SV_PC_KEYBOARD_KEY_64
Kb_h IS SV_PC_KEYBOARD_KEY_65
Kb_i IS SV_PC_KEYBOARD_KEY_46
Kb_j IS SV_PC_KEYBOARD_KEY_66
Kb_k IS SV_PC_KEYBOARD_KEY_67
Kb_l IS SV_PC_KEYBOARD_KEY_68
Kb_m IS SV_PC_KEYBOARD_KEY_81
Kb_n IS SV_PC_KEYBOARD_KEY_80
Kb_o IS SV_PC_KEYBOARD_KEY_47
Kb_p IS SV_PC_KEYBOARD_KEY_48
Kb_q IS SV_PC_KEYBOARD_KEY_39
Kb_r IS SV_PC_KEYBOARD_KEY_42
Kb_s IS SV_PC_KEYBOARD_KEY_61
Kb_t IS SV_PC_KEYBOARD_KEY_43
Kb_u IS SV_PC_KEYBOARD_KEY_45
Kb_v IS SV_PC_KEYBOARD_KEY_78
Kb_w IS SV_PC_KEYBOARD_KEY_40
Kb_x IS SV_PC_KEYBOARD_KEY_76
Kb_y IS SV_PC_KEYBOARD_KEY_44
Kb_z IS SV_PC_KEYBOARD_KEY_75
Kb_spacebar IS SV_PC_KEYBOARD_KEY_95
Kb_L_Shift IS SV_PC_KEYBOARD_KEY_74
Kb_R_Shift IS SV_PC_KEYBOARD_KEY_85
Kb_L_Alt IS SV_PC_KEYBOARD_KEY_94
Kb_R_Alt IS SV_PC_KEYBOARD_KEY_96
Kb_L_Ctrl IS SV_PC_KEYBOARD_KEY_92
Kb_R_Ctrl IS SV_PC_KEYBOARD_KEY_99
Kb_Ins IS SV_PC_KEYBOARD_KEY_31
Kb_Home IS SV_PC_KEYBOARD_KEY_32
Kb_End IS SV_PC_KEYBOARD_KEY_53
Kb_PgDown IS SV_PC_KEYBOARD_KEY_54
Last Modified 2010-10-11 11:21:28 AMPage 86 of 134
Kb_PgUp IS SV_PC_KEYBOARD_KEY_33
Kb_Del IS SV_PC_KEYBOARD_KEY_52
Kb_Back IS SV_PC_KEYBOARD_KEY_30
Kb_Tab IS SV_PC_KEYBOARD_KEY_38
Kb_Up IS SV_PC_KEYBOARD_KEY_87
Kb_Down IS SV_PC_KEYBOARD_KEY_101
Kb_Left IS SV_PC_KEYBOARD_KEY_100
Kb_Right IS SV_PC_KEYBOARD_KEY_102
Kb_Escape IS SV_PC_KEYBOARD_KEY_1 ;Performs Cycle Cancel
Kb_F1 IS SV_PC_KEYBOARD_KEY_2
Kb_F2 IS SV_PC_KEYBOARD_KEY_3
Kb_F3 IS SV_PC_KEYBOARD_KEY_4
Kb_F4 IS SV_PC_KEYBOARD_KEY_5
Kb_F5 IS SV_PC_KEYBOARD_KEY_6
Kb_F6 IS SV_PC_KEYBOARD_KEY_7
Kb_F7 IS SV_PC_KEYBOARD_KEY_8
Kb_F8 IS SV_PC_KEYBOARD_KEY_9
Kb_F9 IS SV_PC_KEYBOARD_KEY_10
Kb_F10 IS SV_PC_KEYBOARD_KEY_11
Kb_F11 IS SV_PC_KEYBOARD_KEY_12
Kb_F12 IS SV_PC_KEYBOARD_KEY_13
Kb_Prt_Scrn IS SV_PC_KEYBOARD_KEY_14
Kb_Scrl_Lck IS SV_PC_KEYBOARD_KEY_15
Kb_Break IS SV_PC_KEYBOARD_KEY_16
Kb_Num_Lock IS SV_PC_KEYBOARD_KEY_34
Kb_1 IS SV_PC_KEYBOARD_KEY_18
Kb_2 IS SV_PC_KEYBOARD_KEY_19
Kb_3 IS SV_PC_KEYBOARD_KEY_20
Kb_4 IS SV_PC_KEYBOARD_KEY_21
Kb_5 IS SV_PC_KEYBOARD_KEY_22
Kb_6 IS SV_PC_KEYBOARD_KEY_23
Kb_7 IS SV_PC_KEYBOARD_KEY_24
Kb_8 IS SV_PC_KEYBOARD_KEY_25
Kb_9 IS SV_PC_KEYBOARD_KEY_26
Kb_0 IS SV_PC_KEYBOARD_KEY_27
Kb_10_Key_Div IS SV_PC_KEYBOARD_KEY_35
Kb_10_Key_Mlt IS SV_PC_KEYBOARD_KEY_36
Kb_10_Key_Sub IS SV_PC_KEYBOARD_KEY_37
Kb_10_Key_0 IS SV_PC_KEYBOARD_KEY_103
Kb_10_Key_1 IS SV_PC_KEYBOARD_KEY_88
Kb_10_Key_2 IS SV_PC_KEYBOARD_KEY_89
Kb_10_Key_3 IS SV_PC_KEYBOARD_KEY_90
Kb_10_Key_4 IS SV_PC_KEYBOARD_KEY_71
Kb_10_Key_5 IS SV_PC_KEYBOARD_KEY_72
Kb_10_Key_6 IS SV_PC_KEYBOARD_KEY_73
Kb_10_Key_7 IS SV_PC_KEYBOARD_KEY_55
Kb_10_Key_8 IS SV_PC_KEYBOARD_KEY_56
Kb_10_Key_9 IS SV_PC_KEYBOARD_KEY_57
Kb_10_Key_Dec_Pt IS SV_PC_KEYBOARD_KEY_104
Kb_10_Key_Plus IS SV_PC_KEYBOARD_KEY_58
Kb_Num_Enter IS SV_PC_KEYBOARD_KEY_91
Kb_L_Sq_Bracket IS SV_PC_KEYBOARD_KEY_49
Kb_R_Sq_Bracket IS SV_PC_KEYBOARD_KEY_50
Kb_Hypen IS SV_PC_KEYBOARD_KEY_28
Last Modified 2010-10-11 11:21:28 AMPage 87 of 134
Kb_Equals IS SV_PC_KEYBOARD_KEY_29
Kb_Comma IS SV_PC_KEYBOARD_KEY_82
Kb_Period IS SV_PC_KEYBOARD_KEY_83
Kb_Slash IS SV_PC_KEYBOARD_KEY_84
Kb_Backslash IS SV_PC_KEYBOARD_KEY_86
;---------------------------------------------------------------; M functions - The System Variables in this section inform the
; PLC that an M function has been requested.
;---------------------------------------------------------------M3 IS SV_M94_M95_1 ;(Spindle CW)
M4 IS SV_M94_M95_2 ;(Spindle CCW)
M8 IS SV_M94_M95_3 ;(Flood On)
M10 IS SV_M94_M95_4 ; Clamp
M7 IS SV_M94_M95_5 ;(Mist)
; IS SV_M94_M95_6 ;
; IS SV_M94_M95_7 ;
; IS SV_M94_M95_8 ;
; IS SV_M94_M95_9 ;
; IS SV_M94_M95_10;
; IS SV_M94_M95_11;
; IS SV_M94_M95_12;
; IS SV_M94_M95_13;
; IS SV_M94_M95_14;
; IS SV_M94_M95_15;
; IS SV_M94_M95_16;
;---------------------------------------------------------------; Word Definitions (int32)
;---------------------------------------------------------------ErrorCode_W IS W1
TwelveBitSpeed_W IS W2
LubeAccumTime_W IS W3
KbOverride_W IS W4
FeedrateKnob_W IS W5
CycloneStatus_W IS W6
FinalFeedOverride_W IS W7
PLC_Fault_W IS W8
PLCFaultAddr_W IS W9
Last_FeedrateKnob_W IS W10
AsyncMsg_W IS W11
P148Value_W IS W12
Lube_W IS W21
LubeM_W IS W22
LubeS_W IS W23
Inputs_9_12_W IS W28
P170Value_W IS W30
P178Value_W IS W31
SpinSpeedCommand_W IS W32
;---------------------------------------; Word Definitions cont. (f32)
;----------------------------------------
Last Modified 2010-10-11 11:21:28 AMPage 88 of 134
SpinRangeAdjust IS FW1
RPMPerBit_FW IS FW2
CfgMinSpeed_FW IS FW3
CfgMaxSpeed_FW IS FW4
TwelveBitSpeed_FW IS FW5
;-----------------------------------; One Shot Definitions
;-----------------------------------IncrContPD IS PD1
SlowFastPD IS PD2
MpgPD IS PD3
SingleBlockPD IS PD4
FeedHoldPD IS PD5
SpinAutoManPD IS PD6
SpindlePlusPD IS PD7
SpinOverMinusPD IS PD8
SpinOver100PD IS PD9
SpinStartPD IS PD10
SpinStopPD IS PD11
SpinCWPD IS PD12
SpinCCWPD IS PD13
F9PD IS PD14
x1JogPD IS PD15
x10JogPD IS PD16
x100JogPD IS PD17
Aux11KeyPD IS PD18
RapidOverPD IS PD19
CoolantAutoManualPD IS PD21
CoolantFloodPD IS PD22
CoolantMistPD IS PD23
ToolCheckPD IS PD24
JogProbeFaultPD IS PD25
RigidTapPD IS PD26
PCSpindleStartStopPD IS PD30
PCSpindleManualPD IS PD31
PCSpindleCWPD IS PD32
PCSpindleCCWPD IS PD33
StopRunning_PD IS PD35
SoftwareReadyPD IS PD36
;---------------------------------------------------------------; Timer Definitions
;---------------------------------------------------------------; 1000 = 1 second for all timers.
;
MsgClear_T IS T1
SleepTimer IS T2
CycloneStatusTimer IS T3
InitializeTimer IS T4
LubeM_T IS T13
LubeS_T IS T14
;---------------------------------------------------------------WatchDogStage IS STG1
InitialStage IS STG2
JOG_PANEL IS STG3
MainStage IS STG4
AxesEnableStage IS STG5
SpindleStage IS STG6
MPG_Stage IS STG7
CheckCycloneStatus IS STG8
LoadCNC11Parameters IS STG9
KeyboardEvents IS STG10
LubeUsePumpTimers IS STG13
LubeUsePLCTimers IS STG14
SetError IS STG50
BadError IS STG51
;---------------------------------------------------------------; Program Start
;----------------------------------------------------------------
; Handle PLC executor faults. The only way to reset a PLC executor fault
; is to reboot the MPU11.
if SV_PLC_FAULT_STATUS != 0 THEN
PLC_Fault_W = SV_PLC_FAULT_STATUS,
PLCFaultAddr_W = SV_PLC_FAULT_ADDRESS,
ErrorCode_W = PLC_EXECUTOR_FLT_MSG, MSG ErrorCode_W,
SET PLCExecutorFault_M, RST SetError, SET SV_STOP
; Handle software exit.
if !SV_PC_SOFTWARE_READY && (SV_PLC_FAULT_STATUS == 0) THEN
SET SoftwareReady_M,
SET SV_STOP,
ErrorCode_W = SOFTWARE_EXIT_MSG
if SV_PC_SOFTWARE_READY && (SV_PLC_FAULT_STATUS == 0) THEN (SoftwareReadyPD)
if SoftwareReadyPD && !SoftwareReady_M || !true THEN SET InitialStage
if SoftwareReadyPD && SoftwareReady_M THEN RST SoftwareReady_M
;--------------------------------------------------------------- InitialStage
;---------------------------------------------------------------IF 1==1 THEN SET true,
SET OnAtPowerUp_M,
SET AxesEnableStage,
SET MainStage,
SET JOG_PANEL,
SET LoadCNC11Parameters,
SET MPG_Stage,
Last Modified 2010-10-11 11:21:28 AMPage 90 of 134
; There are two methods of control for the lube pump and they are set by CNC11
; Machine Parameter 179, where the value is between 0 - 65535 and is formatted
; as MMMSS where MMM is a time in minutes and SS is a time in seconds.
;
; METHOD 1 (SS == 0) For lube pumps with internal timers.
; METHOD 2 (SS != 0) For lube pumps with no timers (controlled soley by PLC).
;
; Load lube pump times from P179 and convert to milliseconds.
IF true THEN Lube_W = SV_MACHINE_PARAMETER_179,
LubeM_W = (Lube_W / 100) * 60000,
LubeS_W = (Lube_W % 100) * 1000
; Set the apprpriate stage according to method of control
IF LubeS_W == 0 THEN SET LubeUsePumpTimers, RST LubeUsePLCTimers
IF LubeS_W != 0 THEN SET LubeUsePLCTimers, RST LubeUsePumpTimers
if true THEN P148Value_W = SV_MACHINE_PARAMETER_148,
P170Value_W = SV_MACHINE_PARAMETER_170,
P178Value_W = SV_MACHINE_PARAMETER_178
If true THEN BitTst P148Value_W 1 DisableKbInput_M
if true && !DisableKbInput_M THEN BitTst P170Value_W 0 AllowKbInput_M
If true THEN BitTst P170Value_W 1 JogOverOnly_M
If true THEN BitTst P170Value_W 2 KbOverOnly_M
if JogOverOnly_M && KbOverOnly_M THEN rst KbOverOnly_M
If true THEN BitTst P178Value_W 0 InvLubeOk_M
If true THEN BitTst P178Value_W 1 InvSpinInverterOk_M
; METHOD 1 (SS == 0) For lube pumps with internal timers.
;
; When using this method, P179 should be set such that MMM is a
; value that is greater than the cycle time set on the internal timers and
Last Modified 2010-10-11 11:21:28 AMPage 91 of 134
; SS should be set to zero. How much greater MMM needs to be depends on the
; accuracy of the lube pump timers, but it is better to be on the long side
; to ensure proper operation.
;
; Example 1. The internal lube cycle interval is set to 60 minutes.
; Set P179 = 7500. In this example, as long as the accuracy
; of the lube timer interval causes the lube to turn on
; within 75 minutes, it will work. Note that the amount of time
; that lube is output is usually set with another timer control
; on the lube pump and it does not factor into the setting of P179.
;
; It should be noted that lube pumps with internal timers may differ on how
; they operate.
;
; (a) For pumps that lube immediately when power is applied and then start timing
; until the next cycle, it is possible to run out of lube quickly on short job
; runs if, after the program has been run, lube power is removed.
;
; (b) For pumps that do not lube until it has been turned on for the interval time,
; it is possible that lube never gets applied if, after the short program has been run,
; lube power is removed.
;
; A short program or job run is defined as a job that finishes before
; the interval setting (60 minutes in the above example).
;
; For the above mentioned reasons, we want the power to be applied for at least
; the amount of time set by the inteval timer, noting that if the user decides
; to engage the E-stop to remove power after short jobs, then they risk the
; above mentioned problems accoding to the type of pump.
;
; On the start of SV_PROGRAM_RUNNING, the lube pump turns on.
; The lube pump is turned off when a program has NOT been
; running continuously for MMM minutes or E-stop is engaged.
; The reason the lube pump is turned off after a program has NOT been
; running for MMM minutes is to prevent lubing when the user leaves for the
; weekend, leaving the machine on and E-stop disengaged.
IF SV_PROGRAM_RUNNING THEN SET Lube, RST LubeM_T
IF !SV_PROGRAM_RUNNING THEN LubeM_T = LubeM_W, SET LubeM_T
IF LubeM_T || !EStopOk THEN RST Lube
;----------------------------------------------------------------------------- LubeUsePLCTimers
;-----------------------------------------------------------------------------;
; METHOD 2 (SS != 0) For lube pumps that do not have internal timers.
;
; When using this method P179 should be set so the lube turns on
; every MMM minutes for SS seconds.
;
; Example 1.
; To set the lube pump power to come on for 5 seconds
; every 10 minutes, set P179 = 1005.
; MMMSS
Last Modified 2010-10-11 11:21:28 AMPage 92 of 134
; Example 2.
; To set the lube pump power to come on for 30 seconds
; every 2 hours, set P179 = 12030
; MMMSS
;
; This method will accumulate time while a program is running until
; it reaches MMM minutes, at which time it will apply power
; for SS seconds (unless E-stop is engaged) and then start over. It is
; possible with frequent use of E-stop that a lube cycle is cut short.
;
IF SV_PROGRAM_RUNNING THEN LubeM_T = LubeM_W, SET LubeM_T
IF !SV_PROGRAM_RUNNING THEN (StopRunning_PD)
IF StopRunning_PD THEN LubeAccumTime_W = LubeAccumTime_W + LubeM_T, RST LubeM_T
IF LubeM_T || (LubeAccumTime_W + LubeM_T > LubeM_W) THEN
SET Lube, LubeS_T = LubeS_W, SET LubeS_T, RST LubeM_T, LubeAccumTime_W = 0
IF LubeS_T || !EStopOk THEN RST Lube, RST LubeS_T
;--------------------------------------------------------------- KeyboardEvents
;---------------------------------------------------------------; This stage handles functions that are required for menu navigation
; by CNC11, require multiple keypresses and/or need to be interlocked
; with SV_PC_VIRTUAL_JOGPANEL_ACTIVE and/or AllowKbInput_M. Regarding
; "AllowKbInput_M": This PLC program reads a bit from a system parameter,
; in this case bit 0 of SV_MACHINE_PARAMETER_170, and sets "AllowKbInput_M"
; if the bit is a "0". If the operator wishes to allow keyboard input
; to trigger PLC events, they must set parameter 170 to a "1"
; (or any odd number for that matter). It should be mentioned that
; the programmer will not want to interlock all keyboard keys with
; SV_PC_VIRTUAL_JOGPANEL_ACTIVE and/or AllowKbInput_M. For example:
; The "escape" key must be echoed by the PLC to CNC11 to aid in menu
; navigation. NOTE: For backward comaptibility with CNC10, setting bit 1
; of SV_MACHINE_PARAMETER_148 OR clearing bit 0 of SV_MACHINE_PARAMETER_170
; will disable keyboard jogging.
;-------------------------Not interlocked-----------------------; The for cycle cancel has been moved to the main stage.
; It is commented out below but remains for referrence
;Cycle Cancel
;if Kb_Escape THEN (KbCycleCancel_M)
;Rapidoverride: Ctrl-r
if Kb_r && (Kb_L_Ctrl || Kb_R_Ctrl) THEN (KbTogRapidOver_M)
;----------------Interlocked with AllowKbInput_M------------------;KbCycle Start: alt-s
if Kb_s && (Kb_R_Alt || Kb_L_Alt) && AllowKbInput_M then (KbCycleStart_M)
;KbToolCheck_M: Ctrl-t
if Kb_t && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M then (KbToolCheck_M)
;KbTogSingleBlock_M: ctrl-b
if Kb_b && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M then (KbTogSingleBlock_M)
Last Modified 2010-10-11 11:21:28 AMPage 93 of 134
;KbAux5Key_M: "ctrl" + "F5"
if Kb_F5 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux5Key_M)
;KbAux6Key_M: "ctrl" + "F6"
if Kb_F6 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux6Key_M)
;KbAux7Key_M: "ctrl" + "F7"
if Kb_F7 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux7Key_M)
;KbAux8Key_M: "ctrl" + "F8"
if Kb_F8 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux8Key_M)
;KbAux9Key_M: "ctrl" + "F9"
if Kb_F9 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux9Key_M)
;KbAux10Key_M: "ctrl" + "F10"
if Kb_F10 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux10Key_M)
;KbAux11Key_M: "ctrl" + "F11"
if Kb_F11 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux11Key_M)
;KbAux12Key_M: "ctrl" + "F12"
if Kb_F12 && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbAux12Key_M)
;KbIncFeedOver_M: "ctrl" + "keyboard +" (actually "=")
if Kb_Equals && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M THEN (KbIncFeedOver_M)
;KbDecFeedOver_M: "ctrl" + "keyboard -"
if Kb_Hypen && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M then (KbDecFeedOver_M)
;KbFeedOver100_M: "ctrl" + "keyboard \"
if Kb_Backslash && (Kb_L_Ctrl || Kb_R_Ctrl) && AllowKbInput_M then (KbFeedOver100_M)
;--------Interlocked with AllowKbInput_M && KbJpActive_M-----------
;KbIncreaseJogInc_M: "insert"
if Kb_Ins && AllowKbInput_M && KbJpActive_M
then (KbIncreaseJogInc_M)
if KbIncreaseJogInc_M && x1JogLED && !X1_M && !X10_M && !X100_M
then set X10_M
if KbIncreaseJogInc_M && x10JogLED && !X1_M && !X10_M && !X100_M
then set X100_M
;KbDecreaseJogInc_M: "delete"
if Kb_Del && AllowKbInput_M && KbJpActive_M
then (KbDecreaseJogInc_M)
if KbDecreaseJogInc_M && x10JogLED && !X1_M && !X10_M && !X100_M
then set X1_M
if KbDecreaseJogInc_M && x100JogLED && !X1_M && !X10_M && !X100_M
then set X10_M
;KbJogAx1Plus_M: Right arrow
Last Modified 2010-10-11 11:21:28 AMPage 95 of 134
if Kb_Left && AllowKbInput_M && KbJpActive_M THEN (KbJogAx1Plus_M)
;KbJogAx1Minus_M: Right arrow
if Kb_Right && AllowKbInput_M && KbJpActive_M THEN (KbJogAx1Minus_M)
;KbJogAx2Plus_M: Up arrow
if Kb_Up && AllowKbInput_M && KbJpActive_M THEN (KbJogAx2Plus_M)
;KbJogAx1Minus_M: Down arrow
if Kb_Down && AllowKbInput_M && KbJpActive_M THEN (KbJogAx2Minus_M)
;KbJogAx3Plus_M: Page up
if Kb_PgUp && AllowKbInput_M && KbJpActive_M THEN (KbJogAx3Plus_M)
;KbJogAx3Minus_M: Page Down
if Kb_PgDown && AllowKbInput_M && KbJpActive_M THEN (KbJogAx3Minus_M)
;KbAx4PlusJog: "home"
if Kb_Home && AllowKbInput_M && KbJpActive_M
then (KbJogAx4Plus_M)
;KbAx4MinusJog: "end"
if Kb_End && AllowKbInput_M && KbJpActive_M
then (KbJogAx4Minus_M)
if true THEN rst KeyboardEvents
;--------------------------------------------------------------- MPG_Stage
;---------------------------------------------------------------; MPG Functions
; Turn on/off Jog Panel MPG LED & on the MPG
IF MPGKey then (MpgPD)
IF MpgPD && MPGLED then set MPGManOffFlag_M
IF !SV_MPG_1_ENABLED || (MpgPD && !MPGLED) then RST MPGManOffFlag_M
IF (MpgPD && !MPGLED) || (SV_MPG_1_ENABLED && !MPGManOffFlag_M) &&
!SV_PROGRAM_RUNNING THEN SET MPG_LED_OUT, SET MPGLED
IF (!SV_MPG_1_ENABLED || (MpgPD && MPGLED))
|| SV_PROGRAM_RUNNING THEN RST MPG_LED_OUT, RST MPGLED
;x1, x10, x100 functions
;--------------------------X1----------------------------------IF x1JogKey THEN (x1JogPD)
IF x1JogPD || OnAtPowerUp_M || X1_M || (MPG_Inc_X_1 && MPGLED)
THEN SET x1JogLED, RST x10JogLED, RST x100JogLED
;--------------------------X10---------------------------------IF x10JogKey THEN (x10JogPD)
IF x10JogPD || X10_M || (MPG_Inc_X_10 && MPGLED)
Last Modified 2010-10-11 11:21:28 AMPage 96 of 134
;--------------------------X100--------------------------------IF x100JogKey THEN (x100JogPD)
IF x100JogPD || X100_M || (MPG_Inc_X_100 && MPGLED)
THEN RST x1JogLED, RST x10JogLED, SET x100JogLED
if !KbIncreaseJogInc_M && !KbDecreaseJogInc_M then rst X1_M, rst X10_M,
rst X100_M
; Select axis to move
IF MPG_AXIS_1 THEN SV_MPG_1_AXIS_SELECT = 1
IF MPG_AXIS_2 THEN SV_MPG_1_AXIS_SELECT = 2
IF MPG_AXIS_3 THEN SV_MPG_1_AXIS_SELECT = 3
IF MPG_AXIS_4 THEN SV_MPG_1_AXIS_SELECT = 4
; Select MPG 1 Multiplier
IF (MPG_Inc_X_100) THEN SV_MPG_1_MULTIPLIER = 100
IF (MPG_Inc_X_10) THEN SV_MPG_1_MULTIPLIER = 10
IF (MPG_Inc_X_1) THEN SV_MPG_1_MULTIPLIER = 1
; Disable "Windup" mode IF x100 selected
IF (!MPG_Inc_X_100) THEN (SV_MPG_1_WINDUP_MODE)
;--------------------------------------------------------------- JOG_PANEL
;---------------------------------------------------------------; Select Incremental or Continuous Jog Mode
IF IncrContKey || KbTogIncContJog_M THEN (IncrContPD)
IF (IncrContPD && !IncrContLED) || OnAtPowerUp_M THEN SET IncrContLED
IF (IncrContPD && IncrContLED) THEN RST IncrContLED
; Select Fast or Slow Jog Mode
IF FastSlowKey || KbTogFastSlowJog_M THEN (SlowFastPD)
IF (SlowFastPD && !FastSlowLED) || OnAtPowerUp_M || MechnicalProbe
THEN SET FastSlowLED
IF (SlowFastPD && FastSlowLED) THEN RST FastSlowLED
;--------------------------------------; Single Block Mode
;--------------------------------------IF SingleBlockKey || KbTogSingleBlock_M THEN (SingleBlockPD)
IF SingleBlockPD && !SingleBlockLED && !SV_PROGRAM_RUNNING
THEN SET SingleBlockLED
IF SingleBlockPD && SingleBlockLED THEN RST SingleBlockLED
IF SingleBlockLED THEN (SelectSingleBlock)
Last Modified 2010-10-11 11:21:28 AMPage 97 of 134
;--------------------------------------; Toolcheck
;--------------------------------------IF (ToolCheckKey || KbToolCheck_M) && EstopOk THEN (ToolCheckPD)
IF ToolCheckPD THEN (DoToolCheck)
;--------------------------------------; Feed Hold Mode
;--------------------------------------IF (FeedHoldKey || KbFeedHold_M) && SV_PROGRAM_RUNNING THEN (FeedHoldPD)
IF FeedHoldPD && !FeedHoldLED THEN SET FeedHoldLED
IF FeedHoldPD && FeedHoldLED && !SV_PROGRAM_RUNNING && !SV_MDI_MODE
THEN RST FeedHoldLED
IF FeedHoldLED && (DoCycleStart || DoCycleCancel || ToolCheckPD)
THEN RST FeedHoldLED
IF FeedHoldLED THEN SET DoFeedHold
IF !FeedHoldLED THEN RST DoFeedHold
;--------------------------------------; Feedrate Override Section
;--------------------------------------;------------------------------------------------------------------------; Feedrate override works as follows:
;
; 1. The PLC reads the 8 bit value of the FeedrateKnob_W directly (0-255)
; 2. The PLC scales this value to a 0-200 value (0-200%) by dividing by
; the knob value by 127.5 and then multiplying the result by 100
; 3. If keyboard joggin is not disabled (it is enabled by default), the PLC
; determines whether the operator is using the keyboard override or
; the FeedrateKnob_W to override the feedrate by watching which was changed
; most recently. The most recently changed value is saved as
; "FinalFeedOverride_W"
; 4. Parameter 39 in (From the "params" scrren in CNC11 software) stores
; a value which allows which the PLC program can use to limit the amount
; of override applied to the programmed feedrate. This value is specified
; as a percentage.
; 5. The PLC limits the override percentage by reading parameter 39 and, if
; the feedrate override percentage as read from the knob is greater than
; parameter 39, it sets the FinalFeedOverride_W value to the value of
; parameter 39.
; 6. Once the override percentage has been determined and limited (if needed)
; The PLC send this value up to the CNC11 software by setting
; SV_PLC_FeedrateKnob_W = FinalFeedOverride_W
; 7. CNC11 reads SV_PLC_FEEDRATE_KNOB, factors in it's on own override based
; on parameter 78 (see operators manual for more info on parm 78) and then
; returns an override value to the PLC in the system variable
; SV_PC_FEEDRATE_PERCENTAGE
; 8. The PLC reads SV_PC_FEEDRATE_PERCENTAGE and (typically) echoes the system
; variable to SV_PLC_FEEDRATE_OVERRIDE which the MPU11 uses as the final
; determination of the feedrate override percentage.
;----------------------------------------------------------------------; 1. The PLC reads the 8 bit value of the FeedrateKnob_W directly (0-255)
; NOTE: BTW = Bit To Word
Last Modified 2010-10-11 11:21:28 AMPage 98 of 134
; BTW reads the specified number of bits (if none is specified it defaults to 8)
; starting from a bit location and writes them to a word with the starting bit
; location being written to the LSB of the word used. Below, BTW reads the bit
; values from JpFeedOrKnobBit0 to JpFeedOrKnobBit7 and writes them into to the
; word "FeedrateKnob_W" which sets FeedrateKnob_W to a value of 0-255
;----------------------------------------------------------------------IF true THEN FeedrateKnob_W = 0
if true THEN BTW FeedrateKnob_W JpFeedOrKnobBit0 8
;----------------------------------------------------------------------; 2. Scale this value to a 0-200 value (0-200%)
;----------------------------------------------------------------------IF true THEN FeedrateKnob_W = (FeedrateKnob_W/127.5)*100
;----------------------------------------------------------------------; 3. Determine whether to us FeedrateKnob_W or KbOverride_W
;----------------------------------------------------------------------; This section determines when to use the feedrate override value sent down
; by the jogpanel (FeedrateKnob_W) or the feedrate override as determined
; by the PLC monitoring the keyboard override keys (KbOverride_W).
;------------------------------------------------------------------------------; At powerup, default feedrate override is jog panel (FeedrateKnob_W)
; To use both keyboard or jogpanel overrides set p170 to 0 (default)
; To use jogpanel override only set p170 to 2
; To use keyboard only set p170 to 4
;------------------------------------------------------------------------------IF OnAtPowerUp_M && KbOverOnly_M || KbFeedOver100_M THEN KbOverride_W = 100
IF OnAtPowerUp_M && !KbOverOnly_M THEN set UsingFeedrateKnob_M,
KbOverride_W = FeedrateKnob_W, Last_FeedrateKnob_W = FeedrateKnob_W
;----------------Calculate keyboard feedrate override--------------------------; SleepTimer is used to limit the KbOverride_W update rate to 20% per sec
;------------------------------------------------------------------------------if AllowKbInput_M && KbIncFeedOver_M && !WaitingForSleepTimer_M
THEN KbOverride_W = KbOverride_W + 1, rst UsingFeedrateKnob_M,
set WaitingForSleepTimer_M, SleepTimer = 50, set SleepTimer
if AllowKbInput_M && KbDecFeedOver_M && !WaitingForSleepTimer_M
THEN KbOverride_W = KbOverride_W - 1, rst UsingFeedrateKnob_M,
set WaitingForSleepTimer_M, SleepTimer = 50, set SleepTimer
if SleepTimer THEN rst WaitingForSleepTimer_M, rst SleepTimer
;------------Switch to FeedrateKnob_W if it changes more 3%---------------------; Once it has changed by more than 3%, it will update as normal (1% increments)
; until it sees another KbOverride_W command at which point it will take
; another 3% change to re-activate the FeedrateKnob_W
if (abs(Last_FeedrateKnob_W - FeedrateKnob_W) >= 3) || UsingFeedrateKnob_M
THEN FinalFeedOverride_W = FeedrateKnob_W, KbOverride_W = FeedrateKnob_W,
Last_FeedrateKnob_W = FeedrateKnob_W, set UsingFeedrateKnob_M
;Limit keyboard override to parm 39. Allowing the FeedrateKnob_W to go past
Last Modified 2010-10-11 11:21:28 AMPage 99 of 134
;parm 39, but keeping the KbOverride_W limited keeps the "dead space"
;down and allows the PLC to respond to changes in the FeedrateKnob_W even if
;above 120. Overall override is still limited later but this gives better
;response in changing between KbOverride_W & the FeedrateKnob_W
if KbOverride_W > SV_MACHINE_PARAMETER_39
THEN KbOverride_W = SV_MACHINE_PARAMETER_39
if !UsingFeedrateKnob_M && !JogOverOnly_M
THEN FinalFeedOverride_W = KbOverride_W
;----------------------------------------------------------------------; 4 & 5. Limit override percentage to value set in Parameter 39
;----------------------------------------------------------------------;------------------Limit final override percentage to parm 39------------------if FinalFeedOverride_W > SV_MACHINE_PARAMETER_39
THEN FinalFeedOverride_W = SV_MACHINE_PARAMETER_39
if FinalFeedOverride_W < 0 THEN FinalFeedOverride_W = 0
;----------------------------------------------------------------------; 6. Send override percentage to CNC11
;----------------------------------------------------------------------;----------------Send override to PC for modification if needed----------------if true THEN SV_PLC_Feedrate_Knob = FinalFeedOverride_W
;----------------------------------------------------------------------; 7. Copy the feedrate override sent from the PC to the MPU11.
;----------------------------------------------------------------------;-------------------------------------------------------------------------; Normally a number from 0.0-2.0, no limitations although V will not exceed
; Vmax. A negative number in here would be extremely bad.
;-------------------------------------------------------------------------IF true THEN SV_PLC_FEEDRATE_OVERRIDE = SV_PC_FEEDRATE_PERCENTAGE/100.0
;--------------------------------------------------------; MPU11 Jog Panel Functions
;--------------------------------------------------------IF KB_F9 then (F9PD)
IF KbTogRapidOver_M || (F9PD && SV_PROGRAM_RUNNING) THEN (RapidOverPD)
IF RapidOverPD^ SelectRapidOverride THEN (SelectRapidOverride)
IF OnAtPowerUp_M THEN SET SelectRapidOverride
IF (CycleCancelKey || KbCycleCancel_M) && SV_PROGRAM_RUNNING THEN (DoCycleCancel)
IF (CycleStartKey || KbCycleStart_M) THEN (DoCycleStart)
IF (Ax1PlusJogKey || KbJogAx1Plus_M) && !Ax1PlusJogDisabled_M &&
!(IncrContLED && FinalFeedOverride_W == 0) THEN (DoAx1PlusJog)
IF (Ax1MinusJogKey || KbJogAx1Minus_M) && !Ax1MinusJogDisabled_M &&
!(IncrContLED && FinalFeedOverride_W == 0) THEN (DoAx1MinusJog)
IF (Ax2PlusJogKey || KbJogAx2Plus_M) && !Ax2PlusJogDisabled_M &&
!(IncrContLED && FinalFeedOverride_W == 0) THEN (DoAx2PlusJog)
IF (Ax2MinusJogKey || KbJogAx2Minus_M) && !Ax2MinusJogDisabled_M &&
Last Modified 2010-10-11 11:21:28 AMPage 100 of 134