plc

D_DDS_MC.pdf ..... variables to their initial values before going on to executing the rest ..... the PLC stops the execution and shows the Watch-Dog error E68.
674KB taille 143 téléchargements 316 vues
DDS-MC SYSTEM Manual Version. 0002 (ing)

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

Titel Type of documentation Internal code (Code) Denominación (Model) Version (Version) Software Electronic document

Headquarters

DDS-MC System PLC and MC languages description. 04754010 MAN DDS-MC (IN) 0002 Versión 04.01 D_DDS_MC.pdf

FAGOR AUTOMATION S.COOP. Bº San Andrés s/n, Apdo. 144 E-20500 ARRASATE-MONDRAGON www.fagorautomation.mcc.es [email protected] Service Dept. Telephone 34-943-771118

The information described in this manual may be subject to changes due to technical modifications.FAGOR AUTOMATION, S. Coop. reserves the right to change the contents of this manual without prior notice.

Evolution

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

Version

Items

0002

First version

Y R A IN M I L E R P

Selection

RELATED DOCUMENTATION

Description Installation an setup

Servo Drive System Code: 04754001

Fagor Motors and Drives Ordering Handbook

Sistema de Regulación Code: 04754000

This is your document.

Quick Reference

Sistema DDS-MC Code: 04754010

Fagor Modular Drives and Motors Quick Reference Code: 14460010

DDS-MC System Code: 04754011

Y R A IN M I L E R P

Fagor Compact Drives and Motors Quick Reference Code: 14460012

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

GENERAL INDEX page

1. 1.1 1.2 1.3

Introduction to the programmable logic controller (PLC) .... 1 PLC resources .................................................................... 2 Modular structure of the PLC program ............................... 4 PLC program execution ...................................................... 9

2. PLC resources ..................................................................... 1 2.1 Inputs ................................................................................... 1 2.2 Outputs ................................................................................ 1 2.3 Marks ................................................................................... 3 2.4 Variables .............................................................................. 3 2.5 Registers ............................................................................. 5 2.6 Timers .................................................................................. 6 2.6.1 Operating modes of a timer ................................................ 9 2.7 Internal clock ..................................................................... 17 2.8 Counters ............................................................................ 18

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

3. 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13

PLC programming ................................................................ 1 Module structure.................................................................. 1 Directing instructions ........................................................... 3 Consulting instructions ........................................................ 8 Operators .......................................................................... 11 Action instructions ............................................................. 13 Binary action instructions .................................................. 14 Program flow changing action instructions. ...................... 16 Arithmetic action instructions. ........................................... 18 logic action instructions ..................................................... 24 Special action instructions ................................................ 26 Summary of PLC programming commands .................... 27 Internal PLC compiling error listing .................................. 32 PLC execution error listing................................................ 34

4. 4.1 4.2 4.3

Introduction to the Motion Control system (MC) .................. 1 Introduction .......................................................................... 1 Operating modes (Manual - Automatic) .............................. 4 MC program execution........................................................ 7

Y R A IN M I L E R P

5. 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9

MC Programming ................................................................. 1 Program Structure and elements........................................ 1 Reserved elements. ........................................................... 4 Variables and constants. ..................................................... 6 Operators ............................................................................ 7 Expressions ........................................................................ 8 Statements. ....................................................................... 10 START, STOP, RESET and ABORT Signals .................. 26 Enable functions................................................................ 28 Summary of the MC programming commands ................ 28

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

WARRANTY TERMS

INITIAL WARRANTY All products manufactured or marketed by FAGOR carry a 12-month warranty for the end user. In order to prevent the possibility of having the time period from the time a product leaves our warehouse until the end user actually receives it run against this 12-month warranty, the OEM or distributor must communicate to FAGOR the destination, identification and installation date of the machine by filling out the Warranty Form that comes with each product. The starting date of the warranty for the user will be the one appearing as the installation date of the machine on the Warranty Form. This system ensures the 12-month warranty period for the user. FAGOR offers a 12-month period for the OEM or distributor for selling and installing the product. This means that the warranty starting date may be up to one year after the product has left our warehouse so long as the warranty control sheet has been sent back to us. This translates into the extension of warranty period to two years since the product left our warehouse. If this sheet has not been sent to us, the warranty period ends 15 months from when the product left our warehouse.

FAGOR is committed to repairing or replacing its products from the time when the first such product was launched up to 8 years after such product has disappeared from the product catalog. It is entirely up to FAGOR to determine whether a repair is to be considered under warranty. EXCLUDING CLAUSES The repair will take place at our facilities. Therefore, all shipping expenses as well as travelling expenses incurred by technical personnel are NOT under warranty even when the unit is under warranty. This warranty will be applied so long as the equipment has been installed according to the instructions, it has not been mistreated or damaged by accident or negligence and has been handled by personnel authorized by FAGOR. If once the service call or repair has been completed, the cause of the failure is not to be blamed the FAGOR product, the customer must cover all generated expenses according to current fees.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Index

Y R A IN M I L E R P

No other implicit or explicit warranty is covered and FAGOR AUTOMATION shall not be held responsible, under any circumstances, of the damage which could be originated. SERVICE CONTRACTS

Service and Maintenance Contracts are available for the customer within the warranty period as well as outside of it.

1. INTRODUCTION TO THE PROGRAMMABLE LOGIC CONTROLLER (PLC) The drive uses a control software to govern the currents flowing through the motor and it controls it by means of velocity and position commands. The Motion Control (MC) and PLC packages run based on this control software. The MC program emulates a CNC. It is capable of generating a movement sequence at the servo system. The PLC program, based on certain logic conditions edited by the user, controls the digital inputs and outputs of the drive. It can also access the internal Drive's variables of the control software.

General properties. The PLC can handle up to 32 logic inputs and 32 logic outputs, although depending on the I/O card (or cards) installed on the drive, only some of these resources will be represented electrically on the outside. It has 64 binary-type marks to signal the various program events. It has permanent access to the drive variables which manages them the same as its 32 32-bit registers. It handles event counters and timers. It has an internal clock to activate periodic actions. It also has a wide range of logic, arithmetic and program flow controlling instructions. Plus, there is a permanent data exchange between the control software of the Drive and the PLC for: • • •

Reading and modifying the drive variables from the PLC. Monitoring the PLC resources on the screen of the DDS Prog Module. Accessing all the PLC resources from a PC through the serial line.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 1 of 14

Editing. The PLC program must be edited in a text file with the name of MyProgram.plc. Fagor provides to the programmer an "integrated environment for developing PLC/MC programs" that makes it easy to edit, compile and transmit programs. This "Integrated environment" is executed via Editor.exe. It is recommended to save the program files in the hard disk of the PC.

Compiling. Compiling the MyProgram.plc generates an object file called MyProgram.pcd. Another file (MyProgram.err) will log all the errors detected when compiling the program. The Fagor Editor offers this compiling function. Press the button of the tool bar of the Editor (F7). This checks the errors and generates the object file.

Transmitting. The MyProgram.pcd file must saved to the Drive's Flash memory through the serial line. This memory is nonvolatile and maintains its data even when the unit is off.

Executing. On power-up, the drive acts as follows: •

If the Drive contains a PLC program in its memory (.pcd extension), it carries out a second internal compilation. The Status Display will indicate the errors that came up in this compilation (E50 - E55, see chapter 3).



It then executes it. The Status Display will indicate the errors occurred during execution (E66 - E69, see chapter 3).

1.1 PLC resources Inputs (I): They are logic variables that, associated with certain electrical inputs, let the PLC program know whether various electrical devices are on or off. The PLC can handle up to 32 logic inputs. They are represented by the letter "I" followed by its identifying number: I1, I2 ... I32.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 2 of 14

Y R A IN M I L E R P

See the EM chapter of the general manual "Fagor Servo Drive System".

Outputs (O): They are logic variables that associated with certain electrical outputs let the PLC turn on or off various electrical devices. The PLC can handle up 32 logic outputs. They are represented by with the letter "O" followed by the identifying number: O1, O2 ... O32.

Marks (M): They are elements capable of storing in a bit (like an internal relay) the status of the different boolean variables of the drive (thanks to the drive-PLC communication) and the status of the different PLC variables. The PLC can handle up to 64 logic marks. They are represented by the letter "M" followed by the identifying number: M1, M2 ... M64. These marks do not maintain their values if the unit is off. See the EM chapter of the general manual "Fagor Servo Drive System".

Variables: The PLC has access to all the variables and parameters of the Drive. The PLC has the OEM access level, therefore, it cannot overwrite variables or parameters requiring the Fagor level. It will issue error E55-307- when attempting to do so. These variables are treated by the PLC the same as the registers. They are named in the PLC program according to the Sercos nomenclature, that is: Sxxxxx or Fxxxxx where xxxxx is a decimal number between 0 and 32767.

Registers (R): They are 32-bit elements for storing a numeric value that is considered as a signed integer. Thus, its value range is within ±2147483647. Their upper and lower values may be accessed separately. The PLC can handle up to 32 registers. They are represented by the letter "R" followed by their identifying number: R1, R2 ... R32.

Timers (T): They are elements that control the status of a digital variable by timing its activation or deactivation depending on the activation and/ or deactivation of logic input or mark. The PLC can handle up to 16 timers. They are represented by the letter "T" followed by their identifying number: T1, T2 ... T16. Each timer can work in four different modes: Monostable. Delayed activation. Delayed deactivation. Signal limiting.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 3 of 14

Counters (C): They are element capable of counting up or down the number of events taking place at the logic inputs or marks. The value of these counters are stored in 32-bit registers. Thus, their value range is within ±2147483647. The PLC can handle up to 16 counters. They are represented by the letter "C" followed by their identifying number: C1, C2 ... C16.

1.2 Modular structure of the PLC program The program to be executed by the PLC consists of several MODULES properly defined by DIRECTING INSTRUCTIONS. The modules that may make up the program are: First Cycle Module (CY1) Main module (PRG) Periodic Module (PE) All these module operate, by default, with the real values of the I, O and M resources. See next section: "Real Memory vs Image Memory".

First Cycle module (CY1). CY1

END

This module is optional and it is only executed once when starting the PLC. It may be used to initialized all the various resources and variables to their initial values before going on to executing the rest of the program. A program may contain only one CY1 module. It needs not be located at the beginning of the program; but it must start with the instruction CY1. The first cycle (CY1) is executed as follows: 1- The PLC reads the voltage at the input pins (connectors of the I/O board) and it also reads the variables of the Drive. These two groups make up what is referred to as Physical Inputs. It starts filling up the Memory for Real values. 2- Executes the instructions of the module one by one and from top to bottom. It changes the Real Values of the output variables and of the marks according to the instructions. To evaluate the instructions, it can only take the values from the real memory.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 4 of 14

Y R A IN M I L E R P

3- Reflects the value of the "O" resources with voltage at the output pins. It updates the variables of the drive that the program has changed.

4- It concludes the execution of CY1 and goes on to the main module PRG.

Main module (PRG). This module contains the user program and it will be in charge of checking and changing the PLC inputs and outputs. PRG

This Main Module is executed repeatedly at every scan time set by parameter AP5 -F2001- PlcPrgScanTime.

END

A program can only contain one PRG module. It must start with the PRG instruction, although it is not necessary if this module starts at the first line of the program. The main module (PRG) is processed periodically and it develops as follows: The cyclic execution of the main module (PRG) is as follows: 1- The PLC reads the Physical Inputs. It fills up the Memory for Real Values. It assigns the values determined by the electrical inputs to the PLC input resources "I" and stores a copy of the Drive variables. For example, if the pin corresponding to the I2 resource is at 0 V (physical input), the PLC sets the I2 variable to "0" (real value). The Drive variable F709 (Power Bus On) is another example of an input data for the PLC. 2- Executes the instructions of the module one by one and from top to bottom. It changes the Real Values of the output variables and of the marks according to the instructions. To evaluate the instructions, it may take the values from the real memory as well as from the image memory. The next section of this chapter describes the structure of the PLC program and which are its execution modules. 3- It makes a copy of the Real Values memory to the Image Values memory. It only stores the image values of the resources: I1 ... I32, O1 ... O32 and M1 ...M64.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 5 of 14

4- The values of the "O" resources are reflected at the output pins of the I/O card connectors. The drive variables are updated at the control software. For example, if the O5 variable is set to "0", the PLC will set physical output O5" to 0 V. It ends the execution of the program. 5- Once the time period set by AP5 -F2001- PlcPrgScanTime since the process begun, this process starts over from the first point.

AP5 -F2001-

PRG Image Values of the Resources.

IMA

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 6 of 14

REA END

Voltages & Drive Parameters

Real Values of the Resources.

Voltages & Drive Parameters

Y R A IN M I L E R P

Periodic module (PE t). This module is optional and is used to process certain critical input/ outputs that must be checked more often than the main module. The PE module must be short. PE t

END

It is executed periodically every t milliseconds and it interrupts the execution of the main module. The t value must be between 1 and 65535 ms (1 min). Example: PE 1

; Defines the beginning of the PE module which will be ; executed every millisecond.

The periodic module (PE) is executed as follows: 1- If the main module is in execution, it interrupts it. 2- The PLC reads the Physical Inputs and modifies the Real Values memory. 3- It executes the instructions of the module one by one and from top to bottom. It changes the Real Values of the output variables and of the marks according to the instructions. To evaluate the instructions, it can only take the values of the real memory. 4- It reflects the values of the "O" resources at the output pins. It updates the drive variables. 5- It ends the execution of the PE module and resumes the execution of the Main Module where it was interrupted. 6- When the "t" time period has elapsed from the beginning of this process, it starts over from the first on. The periodic module PE modifies the status of the PLC resources. Therefore, it may interfere with the execution of the main program if they both share the resources.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 7 of 14

Execution sequence for the PLC modules. Every time the PLC program starts, the module to be executed is the first cycle module (CY1). Once it is executed, it goes on to execute the main module (PRG). This module is executed periodically as often as indicated by AP5 -F2001- PlcPrgScanTime. The Periodic Module (PE) is executed periodically with a time period indicated by the directing instruction “PE t”. This time period starts when the main module starts executing for the first time. The execution of the PE module interrupts the execution of the Main module which is resumed afterwards. When the beginning of the execution of the PE module coincides with the execution of the PRG module, the PE module will be executed first. CY1

END

PRG AP5 -F2001-

PE t t

END

END

Only if the execution of the PRG module is too long, the PE will interrupt the PRG.

CY1

PRG AP5 -F2001- = 4 ms

PE 2 2 ms

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 8 of 14

AP5 -F2001- = 4 ms

Y R A IN M I L E R P

1.3 PLC program execution Three main aspects must be taken into consideration when executing the PLC program: • • •

The instructions are executed in order. In other words, one by one and from top to bottom. The PLC handles two very different internal memories: one for real values and the other one for image values. The period for repetitive execution of the PE and PRG modules may be selected. The time consumed by the execution of the PE and PRG modules is monitored by the system.

Sequential execution. It must be borne in mind that the instructions are always executed sequentially and the result of each one depends on the results of previous instructions. Example: ; Let us suppose that at the beginning of the cycle, the resource M33 is set to "0": M33 AND I7 = O3 I10 = M33 M33 AND I8 = M55

; Resource M33 = "0", then O3 = "0". ; Resource M33 takes the value of ; resource I10. ; The value taken by M55 depends on ; value given to M33 in the previous ; instruction.

See the next section on Image Memory.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 9 of 14

Real Memory vs Image Memory. The PLC has to separate memories to store the status of the resources: The Real Memory and the Image Memory. All the steps described until now work with the Real Memory. It is the same thing to say that "the value of such resource" as to say "the real value of such resource". The Image Memory contains a copy of the values that the resources had at the end of the previous cycle. The PLC makes this copy at the end of the cycle. The resources having an image value are: I1 ... I32, O1 ... O32 and M1 ...M64. The following examples show the different behaviors of the PLC when working with real or image values. The first program line indicates that M1 is assigned the value of "1".

DRIVE PLC

DRIVE CONTROL SOFT

REAL MEMORY Variables

Beginning

Variables

End I Real

Cycle Beginning

I1 - I32 M Real

O Real

M1 - M64

O1 - O32

Cycle End

Physical Input

Physical Output

I/O BOARD Cycle End

Cycle End

Cycle End

I1 - I32 I Image M1 - M64

O1 - O32

M Image

O Image

IMAGE MEMORY

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 10 of 14

Y R A IN M I L E R P

With Real Values: The data considered for evaluating the first part of the instructions is stored in Real Memory and its execution also modifies their values. The order of the instructions causes all the resources to change their values in the first execution cycle.

PLC Program Beginning After first scan After second scan After third scan After fourth scan

() = M1 M1 = M2 M2 = M3 M3 = O5

Effects on Real Values M1 M2 M3 O5 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

With Image Values: The data considered for evaluating the first part of the instructions is stored in Image Memory and its execution modifies their values in Real Memory After each execution cycle (scan), the Image Memory is updated. The first cycle only changes the value of M1 because its image value will be "1" only at the end of the cycle.

PLC Program () = M1 IMA M1 = M2 IMA M2 = M3 IMA M3 = O5

Beginning After first scan After second scan After third scan After fourth scan

Effects on Image Values M1 M2 M3 O5 0 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1

As can be observed, the system is faster when working with real resource values. Working with image values lets analyze the same resource with the same value throughout the whole program regardless of its actual (real) status at the time.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 11 of 14

Example:

M1 ..... M1 AND I1 = SET M2 = RES M1 M2 AND I2 = SET M3 = RES M2 ..... M2 = O13

I1 M2

O13 I2

M3

This machine of states has been implemented by means of a PLC program. The execution of this program using real values causes an anomalous behavior if inputs I1 and I2 are on at the M1 state. Output O13 is never on in spite of the fact the machine has gone through the M2 state. However, the execution using image values will activate output O13 for a time period equal to the program execution period (cycle scan).

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 12 of 14

Y R A IN M I L E R P

Cycle scan and Watch-Dog. The main module is executed with a period indicated by AP5 -F2001- PlcPrgScanTime and the PE t every t milliseconds. The time it takes the PLC to execute each module is called cycle scan and it may vary in later cycles of the same program because the conditions it is executed may change.

n Cycle

n+1 Cycle

n+2 Cycle

n+3 Cycle

t

AP5 -F2001-

AP5 -F2001-

AP5 -F2001-

AP5 -F2001-

If the execution of a cycle of the main program PRG takes too long, the PLC stops the execution and shows the Watch-Dog error E68. By the same token, when the execution of the periodic module takes too long, it will show the Watch-Dog error E69. This avoids executing cycles whose duration could alter the operation of the machine or could cause the PLC to get stuck in an endless loop due to improper programming.

WatchDog Time Limit

t

WatchDog Error

t

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 13 of 14

User notes:

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to the PLC Chapter 1

Page 14 of 14

Y R A IN M I L E R P

2. PLC RESOURCES 2.1 Inputs They are elements that provide the PLC with information on the signals received from the outside. They are represented by the letter "I" followed by the input number they refer to, for example: I1, I2, I22, etc. The PLC can control up to 32 inputs although, when communicating with the outside, it is limited by the number of pins of the connector at the drive. The PLC knows the number and the names of the digital I/Os the drive has at its slots SL1 and SL2. It will issue error E55-300 if the PLC tries to access an input that does not exist physically. The digital inputs may admit digital signals at 5 Vdc or at 24 Vdc. Refer to the EM chapter and appendix A of the general manual, parameter IP5 -F00909- DigitalInputsVoltage. The diagram on the next page shows the correspondence between the connector pins and the numbering of the inputs.

2.2 Outputs They are elements that let the PLC turn on and off the various devices of the electrical cabinet. They are represented by the letter "O" followed by the output number to be referred to, for example: O1, O2, O12, etc. The PLC may can control 32 outputs although when communicating with the outside, it will be limited by the number of pins of the connector at the drive. The PLC knows the number and names of the digital I/O the drive has at its slots SL1 and SL2. It will issue error E55-301 if the PLC tries to access an input that does not exist physically. Refer to the EM chapter of the general manual. The diagram on the next page shows the correspondence between the connector pins and the numbering of the outputs.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 1 of 20

The drive module may hold up to three different I/O boards in each of its two slots. All combinations are possible except inserting the A1 board into the SL2 slot.

X9

9 1

X10

9

X11

9

1 2 3 4 5 6 7 8 9

X12

9 (Phoenix, 3.5 mm)

1 2 3 4 5 6 7 8 9 10 11 12 13

1 X6

1 2 3 4 5 6 7 8 9

(Phoenix, 3.5 mm)

13 P2

16I-8O

1 2 3 4 5 6 7 8 9

(Phoenix, 3.5 mm)

1

Pin

DIGITAL I/Os

DIG. OUTs

1

DIG. OUTs

8I-16O

1

1 2 3 4 5 6 7 8 9

P1

1

X13

9 (Phoenix, 3.5 mm)

A1

1 2 3 4 5 6 7 8 9

X7

ANALOG I/Os

9

(Phoenix, 3.5 mm)

DIG. INs

X8

DIG. INs

1

Pin 1 2 3 4 5 6 7 8 9

DIG. OUTs

DIG. INs

Pin

1

Analog I/O

11

The pin numbering according to the PLC resources is as follows: • • •

The board located in slot SL1 numbers the pins starting at I1 and O1. The board located in slot SL2 numbers the pins starting at I17 and O17 regardless of the numbers given in slot SL1. The pins are numbered from top to bottom.

Drive Module (example) SL2

SL1

1

I3

I19 I20 I21 I22

I5

X8

I7

I23 I24

9

I26

I30

Fagor Motion Control (Version 0002) (Soft : V4.01)

1

O20 O21

Page 2 of 20

O13 O14

O23 9

Chapter 2

X10

9

A1

1

O25

O26

O27

X10

X7

O28

O29

O30

O31

O15 O24

O24

1

O12

O22

PLC Resources

O22

O11

O19

O21 O23

O9

O16

9

O4

P2 P1

O20

9

O10

O18 X13

O18

O8

9 O17

Y R A IN M I L E R P 13

O19

X9

O6

1

O3

O17

O7

16I-8O

O2

I24

9 1

O5

I4

O1

X6

8I-16O

O4

I32

I22 I23

O2

I31 9

I21

X8

O3 X9

I2

I20

O1

I28 I29

FMC

I6

I3

I19

I4

1

I27

I1

I18

8I-16O I25

1 I17

I2

I8

9

1

SL1

1 I1

I18

X12

SL2

1 I17

X11

Drive Module (example)

O32

11

2.3 Marks They are elements capable of storing in a bit (like internal relays) the information defined by the user. These marks are not maintained. Therefore, if the drive's control circuits lose their voltage supply (24Vdc), their values will be lost. They are programmed by the letter M followed by its number, for example: M1, M25, M60, etc. The PLC controls up to 64 user marks M1 - M64

2.4 Variables The PLC has access to all the variables and parameters of the Drive. The PLC has the OEM access level. Therefore, it cannot overwrite variables or parameters requiring a "Fagor" access level. It will issue error E55-307- if it tries to do so. These variables are processed by the PLC the same as the Registers. They are named in the PLC program according to their Sercos name at the Drive. In other words, Sxxxxx or Fxxxxx where xxxxx is a decimal number between 0 and 32767. Examples: I3 = TG4 11 F235 ; The name of parameter F235 of the drive is ; Overload Time Limit. ( ) = CPR 8 F907 ; The name of parameter F907 of the drive is ; Digital Inputs Values.

16-bit variables. It is possible to access the high portion as well as the low portion of each variable using them as 16-bit variables. Their values will be in the ±32767 range. Example: F907L refers to the low portion of the F907 variable. F907H refers to the high portion of the F907 variable.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 3 of 20

Bit by bit. It is possible to refer to a particular BIT of a VARIABLE by preceding it with B and the bit number (0/31). The PLC considers bit 0 as the Least Significant Bit (LSB). For example:

F907:

B28F907

1 0 0 1 0 0 1

...

F907H B28F907

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 4 of 20

bit 2 bit 1 bit 0

refers to Bit 28 of variable F907.

bit 31 bit 30

B28F907

0 1 1 0 1 1 0 F907L B12F907H

Y R A IN M I L E R P

2.5 Registers They are elements that store a numeric value in 32 bits. The value stored in each register will be considered by the PLC as a signed integer value. Thus, its value will be in the ±2147483647 range. These registers are not maintained. Therefore, if the control circuits of the drive lose power (24 Vdc), their stored values will be lost. They do not have image values and they are represented by the letter "R" followed by the register number, for example: R1, R25, etc. The PLC control up to 32 user registers: R1 - R32 The value stored in a Register may be represented as: a decimal number, A hexadecimal number (preceded by the “$” character), or as a binary number (preceded by the “B” character). Examples of the different representations of the same data: Decimal 156 Hexadecimal $9C Binary B1001 1100

Bit by bit. To refer to a particular BIT of the REGISTER, write the letter B and the bit number (0/31) before the selected register. The PLC considers bit 0 as the Least Significant Bit (LSB). For example: B7R8 refers to Bit 7 of Register 8

16-bit registers. It is possible to access the high or low portion of each register, thus using them as 16-bit registers. Therefore, their value will be in the ±32767 range. Example:

R8:

bit 2 bit 1 bit 0

bit 31 bit 30

R5L refers to the low portion of register R5. R8H refers to the high portion of register R8.

1 0 0 1 0 0 1 R8H

...

0 1 1 0 1 1 0

Y R A IN M I L E R P R8L

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 5 of 20

2.6 Timers They are elements that control the status of a digital variable by timing their activation or deactivation depending on the activation and/or deactivation of a logic input or mark. The status output of the time is represented by the letter T followed by its identifier number, for example: T1, T2, T8, etc. They do not have image values. Time is registered in a 32-bit variable (unsigned). Therefore, its value will be between 0 and 4294967295 milliseconds which is equivalent to 1193 hours (almost 50 days). The PLC has 16 timers. Each has the status T output and inputs TEN, TRS, TG1, TG2, TG3 and TG4. It is also possible to check at any time , the time elapsed since it was activated.

Enable

TEN

Reset

TRS

Start Modes

TG1 TG2 TG3 TG4

TIMER

T1 / T16

Output

T1 / T16

Time

Enable Input (TEN). It is the timer enabling input. To enable the time count, the TEN input must be at logic level "1". By default, every time a time is activated, the PLC sets this input to "1". When setting TEN to "0", the timing stops, but it keeps the value of the time count. When setting TEN back to "1" , the timer resumes counting. It is represented by the letters TEN followed by the timer identifying number, for example: TEN 1, TEN 2, TEN 8, etc. TEN

t

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 6 of 20

Example:

Y R A IN M I L E R P

I2 = TEN 10 ; Input I2 enables the timer T10. ; Zero Volts at the pin corresponding to I2, interrupts the ; count.

Reset Input (TRS). It is the timer initializing input. Resetting the timer means to set its count to zero as well as its status output T. On the other hand, the timer is disabled and its count can only be resumed through its TG inputs. The timer is reset when there is an up-flank (leading edge or transition from "0" to "1") at the TRS input. By default, every time a timer is activated, the PLC sets this input low ("0"). It is represented by the letters TRS followed by the timer identifying number, for example: TRS 1, TRS 2, TRS 13, etc.

TRS

t

Example: I3 = TRS 10 ; Input I3 controls the Reset of the timer T10. ; An up-flank at the pin corresponding to I3, ; resets the count.

Trigger Inputs (TG1, TG2, TG3, TG4). They are the inputs for activating the timer. TG1, TG2, TG3 and TG4 represent four different timer behaviors. TG1 triggers the timer in MONOSTABLE mode TG2 triggers the timer in DELAYED ACTIVATION mode TG3 triggers the timer in DELAYED DEACTIVATION mode TG4 triggers the timer in SIGNAL LIMITING mode The trigger instruction consists of the TG1, TG2, TG3, or TG4 command followed by the timer identifying number and the Time Constant. The value of the Time Constant is defined in milliseconds and may be indicated by a numeric value, through an R register or through a Drive parameter. Examples: I3 = TG1 12 100

Y R A IN M I L E R P

; I3 activates the monostable timer T12 ; with a time constant of 100 ms

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 7 of 20

I3 = TG2 8 R30

; I3 triggers the timer T8 with delayed ; connection mode with a time constant ; set (in milliseconds) by the value that Register R30 has ; when executing the instruction. I3 = TG4 11 F235 ; I3 triggers the timer T11 in signal ; limiting mode with a time constant given by parameter F235 ; of the drive. ??? The timer is triggered with a flank of the trigger signal. Up-flank in the TG1, TG2 and TG4 modes Down flank in the TG3 mode (delayed deactivation). Later sections of this chapter describe how each one of these trigger inputs.

Status Output (T). This output indicates the logic state of the timer (1 or 0). It is represented by the letter "T" followed by the number identifying the timer, for example: T1, T2, T16, etc.

Elapsed time (T). This output indicates the time elapsed at the timer since it was activated (triggered on). It is represented by the letter T followed by the number identifying the timer, for example: T1, T2, T16, etc. Although both the elapsed time and the status output are represented by the same letter T, they are used in different types of instructions. In binary instructions, T12 refers to the logic state of the timer (status). T12 = M10 ; Sets mark M10 to the status (0/1) of timer 12. In arithmetic and comparison type instructions, T12 refers to the time elapsed since it was triggered on. I2 = MOV T12 R20 ; Transfers the time count of T12 to register R20 CPS T12 GT 1000 = M10 ; Checks if the time elapsed in T12 is greater than ; 1000 ms. If so, it activates mark M10. The time count is stored in a 32-bit variable (unsigned). Thus, its value may be between 0 and 4294967295 milliseconds which is equivalent to 1193 hours (almost 50 days).

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 8 of 20

Y R A IN M I L E R P

It is NOT possible to work separately with High portion and the Low portion of the time count T as it IS with the R registers.

2.6.1

Operating modes of a timer The operating mode of a timer is selected by activating one of the trigger inputs: TG1, TG2, TG3, TG4. Input TG1 activates the time in MONOSTABLE TG2 triggers the timer in the DELAYED ACTIVATION mode TG3 triggers the timer in the DELAYED DEACTIVATION mode TG4 triggers the timer in the SIGNAL LIMITING mode

Monostable mode. Input TG1. In this mode, the Status output of the time stays high (T=1) from the instant trigger input TG1 is activated and until the time period indicated by the Time Constant is elapsed.

TG1

t

T

The timer is triggered by an up-flank at the TG1 input. At this instant, the Status output goes high (1) and the timer starts timing.

Once the time indicated by the Time Constant has elapsed, the Status output goes low (0) and the Elapsed Time keeps its value.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 9 of 20

Any change at the TG1 input (up or down flank) while timing will have no effect. After timing is completed, a new up-flank at the TG1 input will trigger the timer on again and its time count will start from zero again.

Effect on the TRS input in this mode With an up-flank anytime a the TRS input while timing or after timing, the PLC sets its count to zero as well as the status output T. On the other hand, the timer stays off and it can only turned back on by means of the TG input.

Effect of the TEN input in this mode If TEN is set to "0", timing stops although it keeps the value of the time count. When TEN is set back to "1", it resumes counting from the value it had when interrupted.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 10 of 20

Y R A IN M I L E R P

Delayed activation mode. Input TG2. With this operating mode, it is possible to apply a time delay between the activation of the trigger input TG2 and the activation of the status output T of the timer. The length of this delay is determined by the Time Constant

TG2

electrical equivalent TG2

T

t

T

The timer is activated by an up-flank at the TG2 input. At that instant it starts timing from "0". Once the time period indicated by the Time Constant is elapsed, the Status Output of the timer (T) will be activated and it will stay on until a down flank at the TG2 input. The elapsed time count will keep its value after timing is completed.

A new up-flank at the TG2 input after timing is completed will activate the timer again. If the down flank at TG2 occurs after the time indicated by the time constant has elapsed, the PLC will consider the timing done and it will keep its elapsed-time count.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 11 of 20

Effect of the TRS input in this mode With an up-flank anytime a the TRS input while timing or after timing, the PLC sets its count to zero as well as the status output T. On the other hand, the timer stays off and it can only turned back on by means of the TG input.

Effect of the TEN input in this mode If TEN is set to "0", timing stops although it keeps the value of the time count. When TEN is set back to "1", it resumes counting from the value it had when interrupted.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 12 of 20

Y R A IN M I L E R P

Delayed deactivation mode. Input TG3 With this operating mode, it is possible to apply a time delay between the deactivation of the trigger input TG3 and the deactivation of the status output T of the timer. The length of the delay is determined by the Time Constant.

TG3

electrical equivalent TG3

T

t

T

The timer will be activated by an up-flank at input TG3. At this instant, the timer status output will go high (T=1). The timer waits for a down flank at TG3 to start counting from zero. Once the time period indicated by the Time Constant has elapsed, the timer status output will go low (T=0). The elapsed time count will stay after timing is completed.

A new up-flank at the TG3 input will activate the timer again after timing is completed. If before the time indicated by the Time constant has elapsed, a new up-flank occurs at the trigger input TG3, the PLC will consider that it is a new activation of the timer, it will keep its status output on (T=1) and it will start timing from zero again.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 13 of 20

Effect of the TRS input in this mode With an up-flank anytime a the TRS input while timing or after timing, the PLC sets its count to zero as well as the status output T. On the other hand, the timer stays off and it can only turned back on by means of the TG input.

Effect of the TEN input in this mode If TEN is set to "0", timing stops although it keeps the value of the time count. When TEN is set back to "1", it resumes counting from the value it had when interrupted.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 14 of 20

Y R A IN M I L E R P

Signal limiting mode. Input TG4. In this operating mode, the timer status is kept high (T=1) from the instant trigger input TG4 is activated until the time period indicated by the Time Constant has elapsed or until a down flank occurs at the TG4 input.

TG4

t

T

The timer will be activated by an up-flank at the TG4 input. At this instant, the status output of the timer goes high (T=1) and the timer starts timing from zero.

Once the time period indicated by the Time Constant has elapsed, the status output of the timer goes low (0) and it keeps the elapsedtime count. With a down flank at the trigger input TG4, the PLC will consider the timing done, it will bring the status output low (T=0) and it will keep the elapsed-time count. A new flank at input TG4 will activate the timer again.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 15 of 20

Effect of the TRS input in this mode With an up-flank anytime a the TRS input while timing or after timing, the PLC sets its count to zero as well as the status output T. On the other hand, the timer stays off and it can only turned back on by means of the TG input.

Effect of the TEN input in this mode If TEN is set to "0", timing stops although it keeps the value of the time count. When TEN is set back to "1", it resumes counting from the value it had when interrupted.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 16 of 20

Y R A IN M I L E R P

2.7 Internal clock An Internal clock does the timing in fractions of 1 millisecond. This time count is stored in 32-bit register called TIME_. Through this TIME_ register, the PLC offers the possibility to activate its digital outputs periodically and automatically.

1 ms B0TIME_

t

B1TIME_

t 2 ms

For example:

DFU B8TIME_ = M15 512 ms M15

t

Another example: B2TIME_ AND B3TIME_ AND B4TIME_ = M11 ; The mark is activated every 32 ms (for 4 ms)

4 ms B2TIME_

t

B3TIME_

t

B4TIME_

t

M11

t

The TIME_ register is handled the same as the rest of the 32-bit registers. It can also be divided into two 16-bit registers.

Y R A IN M I L E R P

()= AND TIME_L MASK R12L

()= MOV TIME_ R1 0032 ; it is handled as a single register

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 17 of 20

2.8 Counters They are elements capable of counting up or down a particular number of events. The PLC has 16 counters and they are represented by the letter "C" followed by the counter identifying number, for example: C1, C2, C12, etc. The numeric value of a counter is stored in a 32-bit variable. Thus its value will be within the ±2147483647 range. Each has a status output "C" and the control inputs CUP, CDW, CEN and CPR. It is also possible to consult its count value at any time.

Enable

CEN

Reset

CPR

Count UP

CUP

Count DOWN

CDW

COUNTER

C1 / C16

Output

C1 / C16

Time

Count-up Input (CUP). Every up-flank at this input increments the count by one unit. It is represented by the letters CUP followed by the number identifying the counter, for example CUP1, CUP2, CUP12, etc. Example: I2 = CUP 10 ; Every up-flank at input I2 increments the count of ; counter C10 by one unit.

Countdown Input (CDW). Every up-flank at this input decrements the count by one unit. It is represented by the letters CDW followed by the number identifying the counter, for example CDW1, CDW2, CDW12, etc.. Example: I3 = CDW 20 ; Every up-flank at input I3 decrements the count of ; counter C20 by one unit.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 18 of 20

Y R A IN M I L E R P

Preset Input (CPR). This input is used to preset the counter with a particular value. The counter presets the indicated value with an up-flank at the CPR input. The preset value may be indicated with a particular numeric value, through a register R or through a parameter of the drive. It is represented by the letter CPR followed by the number identifying the counter and the preset value. For example: ( ) = CPR 12 30

; Presets the C12 counter with a value ; of 30.

( ) = CPR 2 R20

; Presets the C2 counter with the value ; that register R20 has when executing ; the instruction.

( ) = CPR 8 F907

; Presets the C8 counter with the value ; of parameter F907 of the drive.

Enable Input (CEN). This is the counter enabling input. The count value can only be changed while CEN is set to "1". When setting CEN to "0", the PLC stops the counter and ignores the CUP and CDW inputs until this input goes back high (CEN = 1). The PLC automatically sets this CEN signal high when presetting the counter. It is represented by the letters CEN followed by the number identifying the counter, for example: CEN 1, CEN 2, CEN12, etc. Example: I10 = CEN 12

; When the pin corresponding to input I10 ; goes high, the C12 counter is enabled ; for counting.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 19 of 20

Status Output (C). This output indicates the logic state of the counter. It is represented by the letter "C" followed by the number identifying the counter, for example: C1, C2, C12, etc. The counter status will be C=1 when its count value is "0" and C=0 if its count value is other than "0".

Count value (C). This output indicates the numeric value of the counter. It is represented by the letter "C" followed by the number identifying the counter, for example: C1, C2, C12, etc. Although both the count value and the status output are represented by the same letter C, they are used in different types of instructions. In binary instructions, C12 refers to the logic state of the counter (status). C12 = M10 ; Assigns to mark M10 the status (0/1) of counter 12. In arithmetic and comparison type instructions, C12 refers to the count since it was activated. I2 = MOV C12 R20 ; It transfer the count of C12 to register R20. CPS C12 GT 1999 = M10 ; Checks if the count of C12 is greater than 1999, ; if so, it activates mark M10. The numeric value of a counter is stored in a 32-bit variable. Therefore, it may be in the ±2147483647 range. It is NOT possible to work separately with the High and Low portions of the count register C as it IS with the R registers.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Resources Chapter 2

Page 20 of 20

Y R A IN M I L E R P

3. PLC PROGRAMMING 3.1 Module structure The modules making up the PLC program: main module (PRG), periodic module and the first cycle module (CY1) are made up of a series of instructions which, depending on their function, may be divided into: • •

Directing instructions. Executing instructions.

The directing instructions provide the PLC with information about the type of module and how it must be executed. With executing instructions, it is possible to check and/or alter the status of the PLC resources (I,O,M,R,T,C) and consist of : • •

A Logic Expression (Boolean 0/1). One or more Action instructions. Action Logic Expresion

Action Action

A Logic Expression consists of: • •

One or more Instructions to consult the status of the resources. One or more Operators.

Therefore, the structure of a module may be summarized as follows:

Directing instruction (PRG)

Operator (AND) Logic expression (I1 AND I2)

PLC Module Executable instruction (I1 AND I2 = O2)

Consulting instruction (I1)

Action instruction (= O2)

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 1 of 36

Any type of data may be included in the PLC program as a comment. Each comment starts with the ";" character and anything written between this character and the end of the line will be ignored when executing the program. Programming example: PRG

; My program

; I10 = M12

This whole line is a comment.

M12 AND I3 = O2 = O12

; Logic Expression ; Action instructions

I3 AND I10 = M10

; Consulting Instruction (I3) ; Operator (AND) and Consulting Instruction (I10) ; Action instruction

END It is highly recommended to include lots of comments to make the program easier to understand for later maintenance. The PLC compiler admits any character as a comment.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 2 of 36

Y R A IN M I L E R P

3.2 Directing instructions They provide the PLC with information about the type of module and how it must be executed. The directing instructions available to program the PLC are: PRG, PE, CY1, END, L, DEF, IRD, OWR and TRACE.

PRG, PE, CY1: They define the type of module. PRG CY1 PE t

Main module First Cycle module. Periodic module. It will be executed periodically every "t" milliseconds as indicated in the directing instruction itself. For example: "PE 100" will be executed every 100 ms.

END: It indicates the end of the module. If not used, the PLC interprets that the module ends at the beginning of the next module or at the end of the program. Example without using the directing instruction END: CY1 ————PRG ————PE 100 ————

; Beginning of the CY1 module

; Beginning of the PRG module

; Beginning of the PE module ; End of the CY1, PRG and PE modules

Labels. They are used to identify a line within the program. It is normally used when making references or programming jumps to other lines within the program. The labels may consist of up to 32 capital letters and/or numbers followed by a colon (:). They must always start with a letter or a low dash (_). Examples: POINT: NOT M14 AND NOT I9 = M15 _1234: M14 = O8 All the labels must be different.

Y R A IN M I L E R P

Only one label may be inserted on the program lines within the CY1, PRG and PE modules and within the subroutines. The beginning of a subroutine is a label.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 3 of 36

DEF: Symbol definition. It associates a symbol to any PLC resource. It is possible to refer to this resource throughout the program by means of its associated symbol. This a programming assistance tool which affects neither the compiling nor the execution of the program. It is highly recommended to include lots of definitions to make the program easier to understand and for later maintenance. Example: DEF EMERG I1

; Assigns the "EMERG" symbol to input I1. ; Therefore, any reference to EMERG ; throughout the program will be interpreted by the PLC as ; being referred to I1. A symbol may also be associated to any number which may be in decimal format, signed or unsigned, hexadecimal, preceded by the "$" character or in binary preceded with the "B" character. Example: DEF MASK $AAAA

; Assigns the MASK symbol to ; the set of bits ; B1010101010101010.

( ) = AND R14 MASK R14

; It uses MASK ; to set to zero some of the ; bits of R14

Up to 1000 symbols may be defined and they must always be placed on the first lines of the program before any other instruction. A symbol consists of up to 32 characters and cannot coincide with any of the words reserved for instructions and cannot contain the following characters: blank space “ “, “=”,“( " ")”, comma "," and semicolon " ;”. A symbol can only be associated with one resource. However, one resource may be associated with several symbols. Example: DEF EMERGENCY-OUT O1 DEF WARNING-OUT O1 See the next section: "#INCLUDE"

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 4 of 36

Y R A IN M I L E R P

#INCLUDE With this statement, it is possible to include in a single program line a reference to a file that contains resource definitions. It facilitates the program structuring and its clarity. Example: #INCLUDE "file path" Where file path indicates the location of the file in the PC or even through a PC network. Example: #INCLUDE "C:\Editor\MyFiles\PLCFiles\motion.inc" or simply #INCLUDE "motion.inc" if the .plc program and the one for definitions motion.inc are in the same directory. The "#INCLUDE" instruction must always be at the beginning of the program, next to the "DEF" definitions. The text file: "motion.inc" must be edited with the same syntax rules as any other program. There are files already prepared with the most common definitions. These "header files" are supplied in the software package. See appendix of this chapter. motion.inc Contains the "defines" of the basic parameters to set up and control the operation of the PLC related to the MC program. ad_da.inc Contains the "defines" that are useful for handling analog inputs and outputs. Gen.inc

Contains the "defines" that are useful for handling the internal function generator.

fagor.inc

"Include" file containing the "includes" of the MC programs not of the PLC. It contains "defines" for the most relevant Sercos and Fagor variables and some constants.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 5 of 36

REA, IMA: These are not really directing instructions; but statement modifiers. They indicate to the PLC that the consultations defined next are made on the real or image values of the I, O and M resources. The registers, timers and counter do not have image values. These modifiers always refer to the consultation of resources for evaluating the logic expressions (left side of the equation) since the action instructions (=O15) are always executed upon real values. Example: IMA I3 AND M4 = O2

; Carries out the logic operation ; AND between the image value of ; I3 and the real of value M4.

By default, the consultations of resources to be evaluated are taken from the real value memory. Each IMA modifier only affects the consultation right behind it (only I3 in the previous example).

IRD: It reads the physical inputs, electrical signals and parameters of the drive and updates the real values of the PLC inputs. Special care must be taken when using this instruction because at this point in the program, the real values of the inputs will be overwritten.

OWR: It updates the physical outputs (electrical signals and parameters) with the real values that the "O" outputs have at the time.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 6 of 36

Y R A IN M I L E R P

TRACE: Directing instruction not yet available at the PLC. This instruction must be used when working with the logic analyzer. It is used to capture data during the execution of a PLC cycle. It must be borne in mind that the logic analyzer captures data at the beginning of each cycle (PRG and PE). It does it right after reading the physical inputs and before starting executing the program. To also capture data while executing the PLC cycle, the "TRACE" instruction must be used. Example of how to use the "TRACE" instruction: PRG --------------------TRACE --------------------TRACE --------------------TRACE --------------------END PE 5 ----------TRACE ----------END

; Data capture

; Data capture

; Data capture

; Data capture

The data capture while executing the trace in this program takes place: • • • •

At the beginning of each PRG cycle. Every time the periodic module is executed (every 5 ms). 3 times within the PRG module. Once within the PE module.

This way, by using the "TRACE" instruction it is possible to capture data more often by inserting this instruction at critical points. In any case, even when no TRACE instruction is inserted in the program, data capture takes place at the beginning of each PRG cycle. The "TRACE" instruction must be used only when debugging the PLC program and it should be removed once the debugging process is over.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 7 of 36

3.3 Consulting instructions With the consulting instructions, the PLC can evaluate the status of the different PLC resources (Input, Output, Mark, Timer, Counter) and they may be divided into: Simple consulting instructions Flank detecting consulting instructions Comparison consulting instructions All consulting instructions admit the prior operator NOT which inverts the logic result of the following consultation. Example: NOT I3

; This consultation returns a "0" if input I3 = 1 ; and a "1" if I3 = 0.

Simple consulting instructions. They are instructions that check the status of the PLC resources (inputs, outputs, marks, timers, counters and the register bits) returning their logic state. Example: I12

; will return a "1" if input I12 is active, ; and a "0" if otherwise.

Single bit consulting instructions. They are use for evaluating, in a logic expression, the value of a single bit of register or variable. The PLC considers bit 0 as the least significant bit. Example: ; will return the value of bit 13 of register 8. ; will return the value of bit 21 of register 8.

R8:

bit 2 bit 1 bit 0

bit 31 bit 30

B13R8 B5R8H

1 0 0 1 0 0 1 R8H

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 8 of 36

...

0 1 1 0 1 1 0 R8L

Y R A IN M I L E R P

Consulting instructions for Flank detection. They are instructions that check for a change at the indicated Input, Output or Mark. This comparison may be done with Real and Image values of the resources and it will be done between the current value of the indicated resource and the value it had when this program line was executed last. There are two types of Consulting Instructions for Flank Detection: DFU: Detects an up-flank (change from 0 to 1) at the indicated resource. It returns a "1" when detected. DFD: Detects a down-flank (change from 1 to 0) at the indicated resource. It returns a "1" when detected. The programming format for the different combinations is: DFU DFD

I O M

1/32 1/32 1/64

Considering that these instructions may evaluate Real and Image values, the following points should be borne in mind: *

The PLC updates the real values of the inputs when starting the cycle by taking the values of the physical inputs.

*

The image values of the inputs, outputs and marks are updated at the end of the program.

Example: I3 = M8 DFU IMA M8 = O9

DFU M8 = O3

PRG

t

I3

electrical real image

M8

real image

O3

real image

O9

real image

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 9 of 36

Consulting instructions for comparisons. The PLC has the CPS for making comparisons between 32-bit registers (signed). The following items may be compared: • • • • •

The value of a register (R). The value of a variable. The time elapsed at a timer (T). The internal count of a counter (C). An integer within the ±2147483647 range.

It can also compare the high and low portions of those registers separately (16 bits with sign). If the required condition is met, the consulting instruction returns a "1" and if not, a "0". These are the different types of possible comparisons: GT (Greater than) Returns a "1" if the first operand is GREATER THAN the second one. GE (Greater equal) Returns a "1" if the first operand is GREATER than or EQUAL to the second one. EQ (Equal) Returns a "1" if the first operand is EQUAL to the second one. NE (Not equal) Returns a "1" if the first operand is NOT EQUAL to the second operand. LE (Less equal) Returns a "1" if the first operand is LESS than or EQUAL to the second one. LT (Less than) Returns a "1" if the first operand is LESS THAN the second one. The comparison may be made with numbers given in any of these formats: Decimal: Any integer in the ±2147483647 range Hexadecimal: Preceded by the $ sign and between 0 and FFFFFFFF Binary: Preceded by the letter B and up to 32 bits (1 or 0). Programming examples:

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 10 of 36

Y R A IN M I L E R P

CPS C12 EQ -1999 = M10 ; If the internal count of the counter C12 is EQUAL ; to -1999, the PLC sets mark M10 to "1", ; or to "0" if otherwise.

CPS T2 GE 100 = TG1 5 2000 ; When the time elapsed at the timer T2 ; is GREATER THAN OR EQUAL TO 100 ms, ; The timer T5 will be triggered in monostable mode ; with time constant of 2 seconds.

CPS R3L LT $990E = M22 ; If the low portion of R3 is LESS THAN $990E ; it activates M22. Remember that $990E ; represents a negative number. ; Thus, R3L=$0000, would set M22 = 0.

3.4 Operators And operator is a symbol that indicates the logic operation to carry out in a Logic Expression between the different Consulting Instructions. The PLC uses the following operators:

NOT. It inverts the result of the following consulting instruction. NOT I2 = O3

; Output O3 shows the inverted state of input I2.

I2 O3 I2

0

1

1

0

O3

AND. It carries out the logic operation "AND" between consulting instructions. I4 AND I5 = O6

; Output O6 goes high when both inputs ; I4 and I5 are high at the same time. I4 I5 O6

I4

0 I5 O6

0

0

0

1

0

1

0

0

1

1

1

OR. It carries out the logic operation "OR" between consulting instructions. I7 OR I8 = O9

; Output O9 goes high when either one or both ; inputs I7 and I8 are high. I7 I8 O9

I7

O9

I8

Y R A IN M I L E R P 0

0

0

0

1

1

1

0

1

1

1

1

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 11 of 36

XOR. It carries out the logic operation "EXCLUSIVE OR" between consulting instructions. I10 XOR I11 = O12

; Output O12 goes high when both inputs ; I10 and I11 are at different logic levels.

I10 I11 O12 I10

0

I11

0

0

0

1

1

1

0

1

1

1

0

O12

Priorities. In a logic expression, the order these operators are evaluated is from left to right and with the weight indicated below (from first to last): NOT AND XOR OR

Parenthesis. Parenthesis "(" and ")" may also be used to clarify and select the order a logic expression is to be evaluated. Example: (I2 OR I3) AND (I4 OR (NOT I5 AND I6)) = O7

I2

I3

I6 I4 I5

O7

Y R A IN M I L E R P

Up to 16 consecutive parenthesis levels are allowed in a single logic expression "(...(...( ... )))".

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 12 of 36

A consulting instruction consisting in two parenthesis alone always has the value of "1". In other words: ( ) = O2 ; Output O2 will be high (= 1).

3.5 Action instructions Introduction. Action instructions are used to alter the state of the PLC resources (I,O,M,R,T,C), depending on the result of the Logic Expression. An executable statement (equation) consists of a Logic Expression and one or several Action Instructions. All the Action Instructions must be preceded by the equal sign (=). All the Action Instructions admit a NOT before them which inverts the result of the expression for that action. Example: I2 = O3 = NOT M10 = NOT TG1 2 100 = CPR 1 100 ; Output O3 will show the state of input I2. ; Mark M10 will show the opposite state of input I2. ; A down-flank (inverted up-flank) at input I2 will trigger TG1 ; of timer T2. ; An up-flank at input I2 will preset counter C1 with a value ; of 100.

Action instructions may be: • • • • •

Binary changing program flow Arithmetic Logic Specific

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 13 of 36

3.6 Binary action instructions Binary action instructions may be: For assignment Conditional

Binary Assignment Action Instructions. This type of binary actions assign to the indicated PLC resource (input, output, mark, timer, counter and register bit) the value resulting from evaluating the logic expression (0/1). Examples: I3 = TG1 4 100 ; The PLC assigns to trigger input TG1 of timer T4 ; the state of input I3. Therefore, an up-flank ; at input I3 will trigger input TG1 of T4. (I2 OR I3) AND (I4 OR (NOT I5 AND I6)) = M11 ; The PLC assigns to mark M11 the value resulting ; from evaluating the logic expression: ; (I2 OR I3) AND (I4 OR (NOT I5 AND I6)). Up to 16 consecutive parenthesis levels are allowed in a single logic expression "(...(...( ... )))".

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 14 of 36

Y R A IN M I L E R P

Binary Conditional Action Instructions. The PLC offers three binary conditional conditions: SET, RES and CPL, for modifying the state of the indicated input, output, mark or register bit. Their programming formats are: SET RES CPL

I 1/32 O 1/32 M 1/64 B 0/31 R 1/32

=SET If the result of the logic expression is "1", this action assigns a "1" to the indicated input, output, mark or register bit. If the result is a "0", this action does not alter the state of the indicated resource. Example: CPS T2 EQ 100 = SET B0R10 ; When the time elapsed at timer T2 equals 100 ms, ; bit 0 of R10 will be set to "1". =RES If the result of the logic expression is "1", this action assigns a "0" to the indicated input, output, mark or register bit. If the result is a "0", this action does not alter the state of the indicated resource. Example: I12 OR NOT I22

= RES M5 = NOT RES M6

; When the result of the logic expression: I12 OR NOT I22 ; is "1", mark M5 will be set to "0" but it will not modify M6. ; On the contrary, If the result is "0", M5 will not be changed, ; but M6 will be set to "0". =CPL If the result of the logic expression is "1", this action inverts the state of the indicated input, output, mark or register bit. If "0", it does not change the state of the indicated resource. Example: DFU I8 OR DFD M2 = CPL B12R3

Y R A IN M I L E R P

; At every up-flank of I8 or a down-flank of M2, the PLC ; will invert the state of bit 12 of register R3.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 15 of 36

3.7 Program flow changing action instructions. These actions interrupt the program flow or sequence resuming its execution at another executable statement indicated by a label (Some Text). This label may be inserted before or after the executable statement that indicates the action.. A subroutine is a portion of the program which, being properly labeled, may be called upon from any executable statement. The first executable statement in a subroutine must be indicated by a label (SomeText) and the last executable statement must be followed by an END instruction. If END is not programmed as the end of the subroutine, the PLC will keep on executing to the end of the END module or to the end of the program which will be considered as the end of the subroutine. The subroutines should be placed after the program END because if they are placed at the beginning, the PLC will start executing them and will interpret the END of the subroutine as the end of the module and it will interpret it as the end of the program since it could not find the call to the subroutine.

= JMP SomeText Unconditional jump. If the result of the logic expression is "1", this action executes a jump to the indicated label and the program goes on executing from that point on. If the result is "0", this action will be ignored. Example: ; ———————— I8 = JMP _JUMP ; If I8=1 the program continues at the ; _JUMP label NOT M14 AND NOT B7R120 = O8 ; If I8=1 this line is skipped CPS T2 EQ 2000 = O12 ; If I8=1 this line is skipped ;———————— _JUMP: (I12 AND I23) OR M54 = O6 ;————————

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 16 of 36

Y R A IN M I L E R P

= CAL SomeText Call to a Subroutine. If the result of a logic expression is "1", this action will execute the indicated subroutine. After the subroutine has been executed, the PLC will execute the action instruction or executable statement programmed after the command "CAL SomeText". If the result of logic expression is "0", the call will be ignored and the program will go on without executing the subroutine. Examples: I2 = CAL L5 = O2 ; If input I2 = 1, subroutine L5 will be executed and, when ; done, output O2 will be set to the value of I2 (1).

PRG ———————— I9 = CAL L15 ———————— END

; If I9=1, executes subroutine L15 ; End of main program

L15: ; Beginning of subroutine L15 ———————— (I12 AND I23) OR M5 = O6 NOT M14 AND NOT B7R10 = O8 CPS T2 EQ 2000 = O12 ———————— END ; End of subroutine L15

= RET Return or End of subroutine. If the result of a logic expression is "1", this action will be treated by the PLC like an END and it will finish the subroutine. If the result is "0" this action will be ignored by the PLC. If END is not programmed at the end of the subroutine and no RET is executed, the PLC will keep on executing to the end of the module END or to the end of the program which will be interpreted by the PLC as the end of the subroutine.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 17 of 36

3.8 Arithmetic action instructions. The PLC has the following arithmetic action instructions: MOV, NGU, NGS, ADS, SBS, MLS, DVS and MDS which can be used to operate with the indicated PLC resources.

=MOV Transfers the states of the indicated origin to the indicated destination. This transfer will be in 4, 8, 12, 16, 20, 24, 28 or 32 bits (to be selected). The Origin or data source may be given in either binary or BCD code and may be selected among the following resources: I O M T C R #

Group of inputs starting at the selected one. Group of outputs starting at the selected one. Group of marks starting at the selected one. Time elapsed at the selected timer. Count value of the selected counter. Value of the selected register Number in decimal, hexadecimal or binary.

The destination of the move (or copy) may also be given in either binary or BCD format and may be selected among the following resources: I O M R

Group of inputs starting at the selected one. Group of outputs starting at the selected one. Group of marks starting at the selected one. Value of the selected register.

Their programming formats are:

Origin MOV

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 18 of 36

Destination Origin code

I 1/32 O 1/32 M 1/64 T 1/16 C 1/16 R 1/32 Variables #

I 1/32 O 1/32 M 1/64 R 1/32 Variables

0 (Bin) 1 (BCD)

Destination Nr of bits to code transmit 0 (Bin) 32 1 (BCD) 28 24 20 16 12 08 04

Y R A IN M I L E R P

The origin and destination must always be defined as well as the number of bits to move except when transferring 32 bits from Binary to Binary (0032) in which case, it is not necessary. Examples: MOV MOV MOV MOV

I12 O1 C2 $CF

M10 32 bits from Bin to Bin R10 0012 12 bits from Bin to Bin O2 0108 8 bits from Bin to BCD M11 1020 20 bits from BCD to Bin

Important considerations when using (MOV). Transferring data of different sizes and in binary code may create certain situations where the exact effect of this MOV instruction must be clearly understood. Memory layout. Any MOV operation whose origin or destination has an element of smaller size (number of bits) than the number of bits being transferred, can affect the adjacent memory bits. Memory layout by groups (arrays):

I

O

I32

....

I17

I16

....

I1

O32

....

O17

O16

....

O1

M64

.... ....

M49

M16

....

M1

M

R32:

B31R32

....

B16R32

B15R32

....

B0R32

R31H

R31:

R31L .... R1H

R1:

R1L

Examples: ( ) = MOV I1 R3 0004 ; Moves the value of the first four inputs ; to register R3. ( ) = MOV R7H R5

; Moves the value of the high portion of ; R7 to R5. And since the MOV involves ; 32 bits, it also drags the data adjacent ; to R7H in memory (R8L).

NC

R3: NC

I4 I3 I2 I1 R8L

R5:

R7H

Y R A IN M I L E R P

NC: No Change.

If the data transfer could affect an array of resources other than the one indicated in the instruction, it will cause a program compiling error. Example: ( ) = MOV I1 M60 0008

; Compiling error, because ; only marks M60 through M64 ; would be used to move 8 bits.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 19 of 36

Binary to BCD. The BCD data might need more bits. When this happens, the PLC will ignore the most significant bits. Examples: ( ) = MOV 125 R11 0108 ; move number 125 to R11 in 8 bits ; The binary code for 125 is: B01111101 ; which can easily be shown in 8 bits. ; But its BCD code is: 000100100101 ; which needs at least 12 bits. Thus the MOV operation would result in: NC

R11: NC

0 0 1 0 0 1 0 1

NC: No Change.

To avoid losing digits, the transfer should be made using more bits. Use other registers in intermediate operations if more than 32 bits are needed.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 20 of 36

Y R A IN M I L E R P

=NGU R 0/31 Negation of all register bits. This action inverts all 32 bits of the indicated register. It lets referring to either the high or the low portion of the registers. Example: I15 = NGU R15

; If input I15 = “1”, the PLC ; inverts all 32 bits of R15

R15:

1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0

R15:

0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 1

=NGS R 0/31 Changes the sign of the contents of a register. This action changes the sign of the indicated register. In other words, it changes all the bits and adds one to the resulting value. It lets referring to either the high or low portion of the registers. Example: I16 = NGS R8

; If input I16 = “1” the PLC changes the ; sign of the contents of register R8. R8:

1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0 $B5B5DAD8 = -1246373160

R8:

0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 $4A4A2528 = 1246373160

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 21 of 36

=ADS, =SBS, =MLS, =DVS, =MDS These actions are used to add (ADS), subtract (SBS), multiply (MLS), divide (DVS) and module or rest of a division (MDS) between register contents and numbers. The result is always stored in the indicated register. Their programming format is: “Type of operation” “1st operand” “2nd operand” “destination register”. The type of operation will be: ADS, SBS, MLS, DVS or MDS.

ADS SBS MLS DVS MDS

1st operand 2nd operand destination R 1/32 R 1/32 R 1/32 Variable Variable Variable # #

Examples: If registers R9=1234 and R1=100: () = ADS R9 R1 R2 = SBS R9 R1 R3 = MLS R9 R1 R4 = DVS R9 R1 R5 = MDS R9 R1 R6

; R2 = 1234 + 100 = 1334 ; R3 = 1234 - 100 = 1134 ; R4 = 1234 x 100 = 123400 ; R5 = 1234 : 100 = 12 ; R6 = 1234 MOD 100 = 34

() = ADS 1563 R1 R2 = SBS R9 1010 R3 = MLS 1000 R1 R4 = DVS R9 1000 R5 = MDS R9 1000 R6

; R2 = 1563 + 100 = 1663 ; R3 = 1234 - 1010 = 224 ; R4 = 1000 x 100 = 100000 ; R5 = 1234 : 1000 = 1 ; R6 = 1234 MOD 1000 = 234

A division by zero using DVS or MDS, will cause error E67 and the PLC program will be interrupted.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 22 of 36

Y R A IN M I L E R P

Important considerations when using (ADS, SBS, MLS, DVS, MDS). When executing this type of arithmetic instructions, the result may need more bits than the operands and they both can registered in 16 or 32 bits. This causes certain situations that one must be aware of. Size of the operation. The operation indicated by the instruction may be executed by the PLC using 16-bit or 32-bit registers. Rule:

If any of the two operands or the destination of the operation takes 32 bits, the operation will be executed using 32-bit registers. Only when both operands and the destination have 16 bits, will the operation be executed using 16-bit registers.

Size of the destination. 32-bit destination. The operation will be executed using 32-bit registers. If the result exceeds the 32 bits, no error message will be issued. 16-bit destination. If the operation takes 32 bits, it will truncate the result (chop off) keeping only its low portion.

It is very important to watch that the result of an operation fits in the destination register.

Examples of how to make a mistake: ( ) = MLS R3 R2L R4

; Where R3 = 9000000 = $895440 ; and R2L = 400 = $190 ; 9000000 x 400 = 3600000000 = ; $D693A400 > $7FFFFFFF ; Thus, the result is wrong, because ; $D693A400 = -694967296

( ) = DVS R5 R6L R7L

; Where R5 = 1000000 ; and R6L = 11 ; The operation takes 32 bits ; 1000000 : 11 = 90909 = $1631D ; But R7L = $631D = 25373

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 23 of 36

3.9 logic action instructions The PLC offers the following logic action instructions: AND, OR, XOR, RR and RL.

=AND, =OR, =XOR These actions are used to carry out, bit by bit, logic operations AND, OR and XOR between the contents of registers or between the contents of a register and a number. The result is always stored in the indicated register. Its programming format is: “Type of operation” “1st operand” “2nd operand” “destination register or variable”. The type of operation will be AND, OR or XOR. As first and second operands, it is possible to define registers (R1/ 32) or numbers in decimal, hexadecimal or binary format. The result of the operation will stored in the destination register. Only one of the 32 registers may be defined here (R1/32). Examples: If registers R20=B10010010 R21=B01000101 () = AND R20 R21 R22 = OR R20 R21 R23 = XOR R20 R21 R24

; R22 = B0 ; R23 = B11010111 ; R24 = B11010111

() = AND B1111 R21 R25 = OR R20 B1111 R26 = XOR B1010 B1110 R27

; R25 = B00000101 ; R26 = B10011111 ; R27 = B00000100

=RR, =RL Register rotation These actions are used to rotate the contents of a register. They may be rotated to the right or to the left and there are two types of rotations: type 1 (RR1 or RL1) and type 2 (RR2 or RL2). It lets referring to either the high or low portion of the registers.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 24 of 36

Rotation Type 1 (RL1 or RR1): Rotation to the left (RL1) or to the right (RR1) inserting a "0" bit in the empty bit. The first or last bit is lost. RL1

Y R A IN M I L E R P RR1

0

0

Rotation type 2 (RL2 or RR2): Roll-over rotation to the left (RL2) or to the right (RR2) inserting the bit going out at one end in the empty bit created at the other end of the register. RL2

RR2

Its programming format is: “Type of operation” “origin” “Number of repetitions” “destination” The type of operation will be RR1, RR2, RL1 or RL2. Both the origin and the destination must be registers (R1/32). If the origin and destination registers are the same, they both must be defined in the instruction. The number of repetitions indicate the consecutive rotations applied to the register. Examples: ()= RR1 R10 1 R20

; A type-1 rotation of R10 to the ; right leaving the result in R20.

()= RL2 R10H 4 R11

; Four type-2 rotations to the left of ; the high portion of R10 leaving ; the result in R11. ; Sets the bits of R11H to zero.

R10:

1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0

R20:

0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0

R10:

1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0

R11:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1

Important considerations when using (AND, OR, XOR, RR, RL).

Y R A IN M I L E R P

The same warnings are applicable here as for the previous chapter for arithmetic operations and: for a 32-bit destination, if the operation took 16 bits, it will expand the result of the operation filling the high portion of the register with zeros. It is very important to watch that the result of an operation fits in the destination register.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 25 of 36

3.10

Special action instructions

=ERA Block erase This action is used to delete a group of inputs, outputs, marks or registers or to initialize the status of a group of timers and counters. When erasing a group of inputs, outputs, marks or registers, the PLC will set the indicated registers to zero. Erasing a set of timers is the same as resetting them and erasing a set of counters is the same as presetting them with a value of zero. Its programming format is:

ERA

Range I 1/32 O 1/32 M 1/64 T 1/16 C 1/16 R 1/32

1/32 1/32 1/64 1/16 1/16 1/32

This action is especially useful in the first cycle module (CY1) to set the desired resources to their initial work conditions. Examples: ( ) = ERA O5 12

; The PLC sets outputs O5 through O12 ; to zero.

( ) = ERA C15 18 ; The PLC presets counters C15, C16, ; C17 and C18 to zero.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 26 of 36

Y R A IN M I L E R P

3.11Summary of PLC programming commands

PLC RESOURCES Inputs: Outputs: User marks: Timers: Counters: User registers

I O M T C R

1/32 1/32 1/64 1/16 1/16 1/32

The value stored in each register will be considered by the PLC as an integer number with sign and it may be referred to in one of the following formats: Decimal Hexadecimal Binary

:Any integer in the ±2147483647 range :Preceded by the $ sing and between 0 and FFFFFFFF :Preceded by the letter B and with up to 32 bits

DIRECTING INSTRUCTIONS PRG CY1 PE t END LABEL DEF REA IMA IRD OWR TRACE

Main module. First cycle module. Periodic module. Every t milliseconds. End of module. Label Symbol definition. The consultations are made with real values. The consultations are made with image values. Updates the "I" resources with the values of the physical inputs. Updates the physical outputs with the real values of the "O" resources. Captures data for the logic analyzer while executing the PLC cycle.

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 27 of 36

SIMPLE CONSULTING INSTRUCTIONS I 1/32 Inputs O 1/32 Outputs M 1/64 Marks T 1/16 Timers C 1/16 Counters B 0/31 R 1/32 Register bit

CONSULTING INSTRUCTIONS FOR FLANK DETECTION

DFU DFD

DFU DFD

Up-flank detection. Down flank detection.

CPS

For comparing values.

I 1/32 O 1/32 M 1/64

COMPARISON CONSULTING INSTRUCTIONS

CPS

1st operand T 1/16 C 1/16 R 1/32 #

order GT GE EQ EN LE LT

2nd operand T 1/16 C 1/16 R 1/32 #

OPERATORS NOT AND OR XOR

Inverts the result of the preceding consulting instruction. Carries out the logic function "AND" between consulting instructions. Carries out the logic function "OR" between consulting instructions. Carries out the logic function "EXCLUSIVE OR" between consulting instructions.

BINARY ASSIGNMENT ACTION INSTRUCTIONS

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 28 of 36

=I =O =M = TEN = TRS = TGn = CUP = CDW = CEN = CPR = B 0/31

Y R A IN M I L E R P

1/32 Inputs 1/32 Outputs 1/64 Marks 1/16 Timers 1/16 1/16 n/R 1/16 Counters 1/16 1/16 1/16 n/R R 1/32 Register bit

Binary Conditional Action Instructions. = SET = RES = CPL

Sets the resource to “1”. Sets the resource to “0”. Inverts the state of the resource.

SET I 1/32 RES O 1/32 CPL M 1/64 B 0/31 R 1/32

Program flow changing action instructions. = JMP LABEL Unconditional jump. = RET Return or End of Subroutine. = CAL LABEL Call to a Subroutine.

ARITHMETIC ACTION INSTRUCTIONS = MOV

Transfers the logic states of the indicated origin to the indicated destination.

Origin MOV

I 1/32 O 1/32 M 1/64 T 1/16 C 1/16 R 1/32 Variables #

Destination Origin code I 1/32 O 1/32 M 1/64 R 1/32 Variables

0 (Bin) 1 (BCD)

Destination Nr of bits to code transmit 0 (Bin) 32 1 (BCD) 28 24 20 16 12 08 04

= NGU R 1/32 Inverts all the bits of a Register. = NGS R 1/32 Changes the sign of the contents of a Register. = ADS Adds values between registers or between a register and a number. = SBS Subtracts values between registers or between a register and a number. = MLS Multiplies values between registers or between a register and a number. = DVS Divides values between registers or between a register and a number. = MDS Module of the division between registers or between a register and a number.

ADS SBS MLS DVS MDS

Y R A IN M I L E R P

1st operand 2nd operand destination R 1/32 R 1/32 R 1/32 Variable Variable Variable # #

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 29 of 36

LOGIC ACTION INSTRUCTIONS = AND = OR = XOR

Logic operation AND between registers or between a register and a number. Logic operation OR between registers or between a register and a number. Logic operation XOR between registers or between a register and a number.

AND OR XOR

1st operand 2nd operand destination R 1/32 R 1/32 R 1/32 # #

= RR 1/2 Register rotation to the right. = RL 1/2 Register rotation to the left.

RR1 RL1 RR2 RL2

1st operand 2nd operand destination R 1/32 1/31 R 1/32 R 1/32

1/31

R 1/32

SPECIAL ACTION INSTRUCTIONS = ERA

Block erase

ERA

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 30 of 36

Range I 1/32 O 1/32 M 1/64 T 1/16 C 1/16 R 1/32

1/32 1/32 1/64 1/16 1/16 1/32

Y R A IN M I L E R P

Beginning of module End of module

CY1, PRG, PE END

Definitions

Directing Jump and return Subroutine

Simple Consulting Flank detection

Signed comparison

Lógic

JMP LABEL, RET CAL LABEL

Input, Output, Register Mark Timer, Counter Register bit Variables Internal clock Up

DFU

Down

DFD

CPS

R T C num

REA, IMA

I/O Update

IRD, OWR

I, O, R M T, C B( )R( ) Sxx, Fxx TIME_

GT GE EQ NE LE LT

NOT function AND function Exclusive OR function OR function Open-close parenthesis

1/32 1/64 1/16 0/31 1/32

R T C num

NOT AND XOR OR ()

RR1, RL1 RR2, RL2

Set Reset Invert boolean

R num

R

ADS SBS MLS DVS MDS

R num

1/31

R

R

I O M B( )R( )

SET RES CPL

Add Subtract Multiply Divide Module

Operators

Real, image

I O M

Rotations

Logic Flip-flop

DEF, INCLUDE

R num

R num

R

Arihtmetic

Transfer

MOV

Negate unsigned Change sign

Block erase

Timer control

Output Enable Reset Modes

Counter control

Output Enable Count up, down Preset

I, O, R M T, C Sxx, Fxx num NGU NGS

0 1

0 1

32 28 24 20 16 12 08 04

R I, O, R M T, C

Y R A IN M I L E R P

ERA

T TEN TRS TG1, TG2, TG3, TG4 C CEN CUP, CDW CPR

I O M R Sxx, Fxx

1/16

1/16

num

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 31 of 36

3.12

Internal PLC compiling error listing On power-up, the drive compiles the .pcd program internally again. If an error occurs then, the Status display indicates an error (E50 - E55) and the PLC program cannot be executed and the motor cannot be turned. Compiling errors cannot be reset. Some of these errors may have different meanings. The 16 most significant bits of the GV37 -F2012- variable define the error in greater detail.

E50 - Internal error F2012H = 25 = $19 - The checksum of the program code loaded is wrong. Load the program again onto the drive. If the problem persists, the Flash or Ram memory may be defective or the loaded code may be defective. Load the new program onto the drive. Contact Fagor Automation. F2012H 25 - Internal error. Contact Fagor Automation.

E51 - Insufficient resources F2012H = 101 - The program has too many labels. Modify the program to correct it. F2012H = 102 - Too many TRACE instructions Modify the program to correct it. F2012H = 103 - The program requires too many memory resources. Reduce the size of the program.

E52 - Insufficient memory F2012H = 150 - The program generated by the compilation does not fit in the memory used for it. Reduce the size of the program.

E53 - There is no .pcd program FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 32 of 36

Y R A IN M I L E R P

F2012H = 200 - The .pcd program has not been loaded onto the drive. Load the program onto the drive.

E54 - Wrong .pcd program

F2012H = 250 - The .pcd program loaded onto the drive is not valid. The PC editor has not compiled it properly. Compile the PLC program again with the Editor and load the .pcd file onto the drive.

E55 - Access to resources F2012H = 300 - Error when accessing an input. The PLC knows the quantity and numbers of the digital I/O available in the drive slots SL1 and SL2. The PLC program tries to access an input which does not exist physically. Modify the program to correct this error. F2012H = 301 - Error when accessing an output. Modify the program to correct this error. F2012H = 302 - Error when accessing a mark. F2012H = 303 - Error when accessing a timer. F2012H =F2012H = 304 - Error when accessing a counter. F2012H = 305 - Error when accessing a register. F2012H = 306 - Error when accessing a parameter or variable of the drive control software (it does not exist). Check that it exists and that the name of that parameter or variable is correct. F2012H = 307 - Insufficient authorization level when accessing a parameter or variable of the drive control software. The PLC has the OEM access level and cannot overwrite variables or parameters requiring the "Fagor" access level. F2012H = 308 - Error when writing a parameter or variable of the drive control software. This resource cannot be written. F2012H = 309 - Error when reading a parameter or variable of the drive control software. This resource cannot be read. F2012H = 310 - An access error has occurred in the MOV instruction between groups of resources due to the size of the first operand (origin). Modify the program to correct this access error.

Y R A IN M I L E R P

F2012H = 311 - An access error has occurred in the MOV instruction between groups of resources due to the size of the second operand (destination). Modify the program to correct this access error. F2012H = 312 - An access error has occurred in the ERA instruction between groups of resources due to the size of the group (block) to be erased. Modify the program to correct this access error.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 33 of 36

3.13

PLC execution error listing The program starts executing after the .pcd program is compiled internally. The Status Display will indicate the errors occurred during execution as E66 - E69. These errors will stop the PLC execution and the motor. The execution errors may be reset. Each one of these errors may have different meaning depending on the value of the GV37 -F2012- variable.

E66 - Internal error F2012H = 32768 ($8000) - Internal execution error. Contact Fagor Automation.

E67 - Division by zero F2012H = 32784 ($8010) - The program has tried to divide by zero. Modify the program accordingly.

E68 - PRG watchdog F2012H = 32800 ($8020) - Watchdog time limit exceeded by the PRG module. The execution time of the PRG module is too long. Reduce the length of the PRG module.

E69 - PE watchdog F2012H = 32816 ($8030) - Watchdog time limit exceeded by the PE module. The execution time of the PE module is too long. Reduce the length of the PE module.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 34 of 36

Y R A IN M I L E R P

Appendix 1. Header files "ad_da.inc" Contains "defines" useful for handling analog inputs and outputs. ; AD_DA.INC ; ; ; "Defines" of the two analog inputs ; DEF ANA_IN_1 DEF ANA_IN_2

F00905L ;value of analog input 1 F00906L ;value of analog input 2

; ; "Defines" of the two analog outputs ; DEF ANA_OUT_1 F01408L ;value of analog output 1 DEF ANA_OUT_2 F01409L ;value of analog output 2 ; ; "Defines" of the two gains for the analog outputs ; DEF ANA_OUT_1_GAIN F01402 ;value of analog output 1 for 10V . DEF ANA_OUT_2_GAIN F01403 ;value of analog output 2 for 10V .

"Gen.inc" Contains the "defines" useful for handling the internal function generator.

; GEN.INC ; ; ; "Defines" of the drive parameters defining the waveform (type of wave). ; DEF GEN_SHAPE F01800L DEF GEN_PERIOD F01801L DEF GEN_AMPLITUDE F01802L DEF GEN_TYPE F01803L DEF GEN_OUTPUT F01804L DEF GEN_DUTY_CYCLE F01805L DEF GEN_N_WAVES F01806L DEF GEN_ON F01807L DEF GEN_OFFSET F01808L ; ; "Defines" of the values that could be given to GEN_SHAPE defining the waveform ; DEF GEN_SINEWAVE 0 DEF GEN_SQUAREWAVE 1 DEF GEN_TRIANGULAR 2 DEF GEN_CONTINUOUS 3 DEF GEN_CNT_ABS_ACC 4

Y R A IN M I L E R P

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 35 of 36

"motion.inc" Contains "defines" of the basic parameters for system configuration and control of its operation.

; MOTION.INC ; ; ; "Defines" of the parameters necessary to set the main work mode and the submode. ; DEF K_OPER_MODE F01313L ;main operation mode ;0 - automatic ;1 - manual DEF

K_AUTO_SUBMODE

F01314L

;submode of the automatic mode ;0 - continuous ;1 - single block ;2 - single instruction

DEF

K_MAN_SUBMODE

F01319L

;submode of the manual mode ;0 - continuous ;1 - incremental

DEF DEF DEF DEF

K_START_SIG K_STOP_SIG K_RESET_SIG K_ABORT_SIG

F01315L F01316L F01317L F01318L

;an up-flank starts the program ;an up-flank stops the program ;resets the program ;aborts the block being executed

; ; "Defines" of the parameters used for jog movements ; DEF JOG_POS F01320L ;jog in the positive direction DEF JOG_NEG F01321L ;jog in the negative direction

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

PLC Programming Chapter 3

Page 36 of 36

Y R A IN M I L E R P

4. INTRODUCTION TO THE MOTION CONTROL SYSTEM (MC) 4.1 Introduction The drive governs the currents through the motor with a control software and controls the system with position commands. The Motion control (MC) and PLC packages work based on this control software. The PLC program, based on certain logic conditions edited by the user, controls the digital inputs and outputs of the Drive. The operation of the MC software is closely related to the PLC since the MC software has direct access to the electrical inputs and outputs of the drive. Thus, the interaction with the outside world is done through the PLC using control marks and variables. The MC program emulates a CNC. It is capable of generating a sequence of movements at the motor using internal position commands. On the other hand, it has access to the internal parameters of the control software. The sequence of movements is given by the MC program and may be conditioned by the digital inputs and outputs of the drive swhich are handled by the PLC.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 1 of 10

General properties. The programming language is exclusive of Fagor. It uses high-level terminology similar to that of the BASIC programming language. It offers statements for the detailed description of movements and their synchronization. It offers arithmetic, relational and logic expressions executed using 32-bit registers. It has a wide range of instructions to control the program flow. The MC program works permanently connected with the PLC. The PLC may established how the MC is going to work and give it signals to start and stop through the parameters of the drive. The control software of the drive and the MC constantly exchange information making it possible to read and modify the drive parameters from the MC.

Editing. The MC programs setting the machine operation must be edited in text files with the extension .mc. Fagor provides the programmer with an "integrated environment to develop PLC/MC programs" that facilitates program editing as well as later compiling and transferring them. This "Integrated environment" is executed from the Editor.exe. It is recommended to save the program files in the hard disk of the PC.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 2 of 10

Y R A IN M I L E PR

Compiling. Compiling any file with the extension .mc generates an object file with the same name; but with the extension .mcc, except: Compiling a file with the specific name of manual.mc generates an object file with the name of manual.jog. Another file with the extension .err will log all the errors occurred while compiling the program. The Fagor Editor offers a compiling function. Press the the tool bar of the Editor (F7). This checks the errors and generates the object file.

on

Transmission. The .mcc and .jog files must be saved into the Flash memory of the drive though the serial line. These object files control the behavior of the machine in automatic and jog mode respectively. The Flash memory is a nonvolatile memory which maintains its data even without electrical power. Object programs may also be uploaded or downloaded with the portable programming module "DDS Prog Module".

Execution. On power-up, the drive acts as follows: •

The drive checks that the it has received the programs for manual (manual.jog) and automatic operation (auto.mcc). If any of them is missing, it issues error 900.



Signals START, STOP, RESET and ABORT govern the system start and stop at all times both in automatic and manual modes.



The F1313 variable defined in the fagor.inc file as K_OPER_MODE determines the operating mode: automatic or manual.



The drives interprets the program line by line and executes it also line by line.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 3 of 10

4.2 Operating modes (Manual - Automatic) There are two operating modes for the drive. To switch from one mode to the other, use the variable: PV13 -F1313- KernelOperationMode: F1313 = 0 automatic mode, by default. F1313 = 1 manual mode Both operating modes are handled by two different MC programs. The automatic mode by the object file with the extension .mcc, and the manual mode by the object file with the extension .jog. The appendix of chapter 5 shows a sample program for the manual mode "manual.mc". Signals START, STOP, RESET and ABORT govern the system start and stop at all times both in automatic and manual modes. Chapter 5 indicates the exact function of these control signals. In either mode, the PLC program must handle these control signals because only the PLC has access to the electrical inputs and outputs.

Automatic mode. After power-up, this mode becomes active. To start the automatic program, the START signal must be activated. The object file with the extension .mcc (resulting from compiling an .mc file) indicates the sequence of motor movements. Under normal conditions, this sequence will be executed in a repetitive way. When the program ends, it will jumps to the beginning and executes it again. The JOG+ and JOG- signals (belonging to the manual mode) do not affect the automatic mode.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 4 of 10

Y R A IN M I L E PR

Submodes of the automatic mode. Within the automatic mode, there are several submodes: CONTINUOUS SUBMODE The statements of the MC program are executed one after another. After activating the START signal, the execution does not stop until the STOP or the RESET signal is activated. This is the most common submode. SINGLE BLOCK SUBMODE In this mode, after the START signal, program execution continues until it finds the first movement block, it executes it and stops. In other words, with one START signal, it only executes one single movement block. This is handy for a controlled execution of the program in the debugging stage. SINGLE INSTRUCTION SUBMODE It is similar to the "single block" mode; but with each START signal, it only executes one instruction be it of movement or not. This is handy for a controlled execution of the program in a lower level debugging stage

To switch from one submode to another, use the variable: PV14 -F1314- KernelAutoMode: F1314 = 0 Continuous submode, by default F1314 = 1 Single block submode F1314 = 2 Single instruction submode

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 5 of 10

Manual mode. Sometimes, the user needs to move the axis manually using back and forth push-buttons. The manual.mc handles this operating mode. The appendix on chapter 5 of this manual shows the suggested manual.mc program. As with the automatic mode, the START signal must be activated to start the manual program.

The PLC controls the execution of the program in the manual mode through these drive parameters: JOG+ signal --> PV20 -F01320- JogPositiveSignal JOG- signal --> PV21 -F01321- JogNegativeSignal JOG+ This signal turns the motor clockwise (forth). JOGThis signal turns the motor counterclockwise (back). The manual.mc program determines how these signals handle the motor.

Submodes of manual operation. Within the manual operating mode, there are several submodes. CONTINUOUS Every JOG signal causes the axis to move at constant speed for as long as this signal stays active. INCREMENTAL Every JOG signal causes the axis to move a set distance at a constant speed.

To switch from one operating submode to another, use the variable: PV19 -F1319- KernelManualMode: F1319 = 0 continuous, by default. F1319 = 1 incremental. In either case, the moving speed is determined by parameter F1322 JogVelocity whose default value is 5 m/min. For the incremental submode, the distance is given by parameter F1323 JogIncrementalPosition, whose default value is 1 mm.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 6 of 10

Y R A IN M I L E PR

All this according to the setting of the manual.mc program. See appendix on chapter 5.

4.3 MC program execution When executing the MC program, the following aspects must be considered: • • • • •

The statements are interpreted before they are executed. The physical units used in numeric data. The maximum precision of these units is 1/10000. Assigning numeric constant to a variable. Value range permitted.

Anticipated interpretation. The MC language is an interpreted language. In other words, each instruction is translated into a sub-language which is actually the code executed by the microprocessor. While executing a motion instruction, the following instructions are interpreted and virtually executed. This way, consecutive motor movements are dynamically chained together. For example, to make that the first movement reaches its target position at the speed set by the second one. The programmer must be aware, at all times, of this "Virtual Anticipated Execution" especially watching for how instructions like DWELL, ZERO and HOME and the assignment instructions. See the corresponding sections on chapter 5.

Physical units. The physical units for the numeric data in the instructions are: • • •

Linear position in mm Angular position in degrees Feedrate in m/min

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 7 of 10

0.0001 precision. These numeric data is internally processed with a maximum precision of 0.0001 of those units • •

The linear position is stored in tenths of a micron etc. ...

Example: MOVE P=1 V=0.05 L=NULL It is a movement to a target position of 1 mm at 50 mm/min a final speed of "0". However, the values processed by the microprocessor are 10000 and 500.

Numerical constants. In hexadecimal. Care must be taken when assigning a numerical constant in hexadecimal format to a variable. In this case, the variable is loaded with that exact value. It is NOT stored in 0.0001 units. Example: VAR = $186A0 MOVE D=VAR L=NEXT

:$186A0 = 100000

It is a 10 mm movement from the current position at the default feedrate (F1312) and speed-linked to the next instruction.

In decimal format When assigning a numerical constant in decimal format, that value IS processed in 0.0001 units. Example: VAR = 6 MOVE D=VAR L=NEXT It is a 6 mm movement from the current position at the default feedrate (F1312) and speed-linked to the next instruction.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 8 of 10

Y R A IN M I L E PR

Integer - decimal. On the other hand, the numerical constant in decimal format cannot have more than 5 digits to the left of the decimal point or more than 4 to the right of the decimal point. Therefore, to assign a value greater than 99999.9999 use an arithmetic expression or the hexadecimal value of that constant. Example: VAR = 150 * 1000 VAR = $59682F00

; $59682F00 = 150 * 1000 * 10000

Two different ways to assign a value of 150000 to the VAR variable.

Size of variables. A variable is stored in 32 bits. Thus, the maximum value range is: in hexadecimal format:$7FFFFFFF ... $80000000 in decimal format: 2147483647 ... -2147483648 If the compiler detects that this range has been exceeded, it will issue an internal overflow error E008. If the execution of the program causes this overflow, it will issue error E907.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 9 of 10

User notes.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

Introduction to MC language Chapter 4

Page 10 of 10

Y R A IN M I L E PR

5. MC PROGRAMMING 5.1 Program Structure and elements The MC program to be executed by the Drive consists of these three basic sections: Definition of resources, Declaration of variables and Execution modules. The first three sections are not necessary, but this order must be followed.

Definition of resources. In order to simplify the reading and maintenance of the programs, it is possible to assign names to the resources being used throughout the program using the DEF instruction. With the INCLUDE instruction, it is possible to write a single line making reference to a "header file" that will only contain resource definitions. A header file cannot contain a reference to another header file. Appendix 3 in this chapter shows the ‘fagor.inc’ file. It contains "defines" for the main Sercos and Fagor variables. It also includes "defines" for some constants. This file is supplied in the same software package. The compiler admits up to 1000 definitions per program.

Declaration of variables. If the program is going to use variables, they must be declared beforehand. The DIM instruction is used for declaring variables and arrays. Up to 1000 variables may be declared.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 1 of 40

Execution modules. The execution modules come after the resource definition and variable declaration. The MC program will consist of the main module (mandatory) which begins with the PROGRAM statement and end with the END statement. It may be accompanied by other optional modules (subroutines). Each subroutine begins with SUB name statement and ends with the ENDSUB statement where "name" is the name that identifies the subroutine.

Instructions. The instructions must always be inside the execution modules. Each program instruction ends with its "return" of "line feed" which is also necessary after the last line or statement of the file.

Labels. They are used to identify a line within the program. It is usually used when referring or jumping to other program lines. The labels may have up to 32 characters (capital letters, numbers and the low dash or underline (_) followed by a colon (:). They must always start with a letter or a low dash (_). Example: POINT: MOVE D=300 L=NULL ----GOTO POINT Besides the letters ‘A’ to ‘Z’ (ANSI character set between 65 and 90), the following special characters can also be used (ANSI between 192 and 223): ‘À’, ‘Á’, ‘Â’, ‘Ã’, ‘Ä’, ‘Å’, ‘Æ’, ‘Ç’, ‘È’, ‘É’, ‘Ê’, ‘Ë’, ‘Ì’, ‘Í’, ‘Î’, ‘Ï’, ‘Ð’, ‘Ñ’, ‘Ò’, ‘Ó’, ‘Ô’, ‘Õ’, ‘Ö’, ‘×’, ‘Ø’, ‘Ù’, ‘Ú’, ‘Û’, ‘Ü’, ‘Ý’, ‘Þ’ and ‘ß’.

A program cannot contain two labels with the same name. There may be only one label on the program lines within the execution modules PROGRAM - END and SUB name - ENDSUB. The jumps must be to labels contained in the same module.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 2 of 40

Y R A IN M I L E PR

Comments. The MC allows inserting any text in the program as comments. The comments begin with a semicolon (;) and anything written between the semicolon and the end of the line will be ignored when executing the program. Examples: PROGRAM ; Initialization ACC = 12 JERK = 240

; Acceleration of 12 m/s^2 ; Jerk = Acc/ts, for ts of 50ms, ; Jerk = 240 m/s^3

HOME ; Move to home position ; MOVE P=0 V=1 The MOVE instruction is a comment and will be ignored when executing the program. It is recommended to be generous with comments in order to facilitate later understanding and maintenance of the program. The MC compiler accepts any character for a comment.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 3 of 40

5.2 Reserved elements. All the words of the MC language must be in capital letters. The only exception is the "file path" of the definitions in the #INCLUDE statement.

Reserved words. They cannot be used for labels, variable names or to define resources. They are: #INCLUDE BOR DIM END ENDWHILE GOTO LE NE OR WAIT XOR

AND BXOR DWELL ENDFOR EQ GT LT NEXT PRESENT WAIT_IN_POS ZERO

BAND CALL ELSE ENDIF FOR HOME MOD NOT PROGRAM

BNOT DEF ELSEIF ENDSUB GE IF MOVE NULL SUB WHILE

The following letters are also reserved because they may be part of the attributes of certain commands. D

L

P

V

Symbols used. Certain symbols have a special meaning in MC programming language. Care must be taken to use them properly as described in the next sections. ( ) [ ] . , _ = + - * / : ;

Drive variables (reserved). All the parameters, variables and commands of the Drive are reserved variables. These elements are named with the letters "S" and "F" followed by a numeric indicator. Thus, no text using this nomenclature ("S" and "F" followed by a number) can be used as label, user variable name or to define a resource. Examples of variable names reserved for the drive: S49 ; Sercos parameter "PositivePositionLimit" F1313 ; Fagor parameter Fagor "KernelOperationMode"

Y R A IN M I L E PR

All cases allow the syntax S49 or S00049 and F1313 or F01313.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 4 of 40

All these drive variables may be accessed from the MC program, some as read-only and other as read/write.

PLC variables (reserved). All the marks, registers and counters of the PLC are reserved variables. These elements are named with the letters "M", "R" and "C" followed by a numeric indicator. There are 64 PLC marks (M1/M64), 32 Registers (R1/R32) and 16 Counters (C1/C16). Thus, no text with this nomenclature ("M", "R" and "C" followed by a number ) may be used as labels, user variable names or to identify a resource. Examples of variable names reserved for the PLC: M13 R001 C8

; PLC mark number 13 ; Register number 1 ; Counter number 8

All cases allow the syntax M1 or M01 and R12 or R00012, etc.

All these PLC resources may be accessed from the MC program. The counters as read-only and the marks and registers as read/ write.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 5 of 40

5.3 Variables and constants. Variables and Arrays. In order to have a memory space to be accessed individually (variable) or indexed (array), it must be declared previously. They are declared using the DIM statement on the user program header. For example: DIM

POS, TABLE[5]

reserves 32-bit registers in the memory for the POS variable and for the 5-element array TABLE. The name of the variables and arrays may have up to 32 characters (capital letters, numbers and the low dash (_). These names must always begin with a letter or a low dash (_). The name assigned by the user cannot coincide with the reserved elements mentioned in the previous section. Each declared variable (whether it is used in the program or not) has a memory space of 32 bits. Each declared array (whether it is used in the program or not) has a memory space of n x 32 bits. where "n" is the number of elements of the array indicated between brackets "[n] in its declaration. Up to 1000 "32-bit" registers may be reserved as memory space for general purpose variables and arrays. The following diagram shows how to refer to each element of a 5element array. This index may be indicated by means of a constant or a variable containing the result of an arithmetic expression.

DIM POS

32 bits POS

Constants.

DIM TABLE[5]

32 bits TABLE[0] TABLE[1] TABLE[2] TABLE[3] TABLE[4]

Y R A IN M I L E PR

On the other hand, constants are all set values that cannot be altered by the program. They are:

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 6 of 40

• • •

Decimal numbers. Hexadecimal numbers. For example: $1E2 Read-only variables because their values cannot be changed by the program. For example: S51 PositionFeedback1

5.4 Operators The operator is a symbol indicating the logic or mathematical function to be carried out. The MC language has arithmetic, relational, logic and binary operators. See the next section: "Expressions".

Arithmetic Operators. * / MOD + -

: multiply : divide : rest of a division : add : subtract

Examples: 3.1415 * 2.22 = 6.9741 365 MOD 12 = 5

365 / 12 = 30.4166

Binary operators. They act as binary operators between variables and constants. BNOT BAND BXOR BOR

: binary negation (one's complement) : binary AND : binary exclusive OR : binary OR

EQ NE GT GE LT LE

: equal to : not equal to : greater than : greater than or equal to : less than : less than or equal to

Relational operators.

Logic operators. They act as logic operators between conditions. NOT AND XOR OR

: logic negation : logic AND : logic exclusive OR : logic OR

Truth tables.

Z0 = NOT Z1

Z0 = Z1 AND Z2

Z1 Z0

Z1 Z2 Z0

0

1

0

0

0

1

0

0

1

0

1

0

0

1

1

1

Y R A IN M I L E PR Z0 = Z1 XOR Z2

Z0 = Z1 OR Z2

Z1 Z2 Z0

Z1 Z2 Z0

0

0

0

0

0

0

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

1

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 7 of 40

5.5 Expressions An expression is any valid combination of operators, constants and variables.

Arithmetic and binary expressions. They are a combination of arithmetic and binary operators with constants and variables. X10 = (X12 * 1000) - X13 M10 = M12 BAND (M14 BOR $F)

Conditional expressions. They are used to set the conditions in "IF, WHILE" type statements and they consist of relational and logic expressions. The result of these expressions is boolean (true "1" or false "0"). Relational expressions are a combination of relational operators with constants, variables and arithmetic or binary expressions. IF (R1 GE 1999) WHILE ((R1 + 100) GT 7854) Relational expressions may be chained together using logic operators in order to make a larger expression. IF ((R1 GE 1999) OR ((R1 + 100) GT 7854))

The result of a relational expression cannot be assigned to a variable to a variable. R0 = (R1 + 100) GT 7854

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 8 of 40

; it is not a valid statement

Y R A IN M I L E PR

Order of priorities. It is important to always bear in mind the order of priorities applied when executing the different parts of an arithmetic or logic expression. Executing priority (from highest to lowest): 1.Arithmetic and binary operations • BNOT, - (negative arithmetic sign) • *, / , MOD (multiplication, division, rest of a division) • +, - (addition, subtraction) • BAND • BXOR • BOR 2.Relational operations (, ...) 3.Logic operations • NOT • AND • XOR • OR The use of parenthesis alters the executing sequence of the different parts of the expression. Examples (the lines indicate the executing order: the same expressions are clearer when using parenthesis):

Z0 = Z1 MOD Z2 * Z3 + Z4 * Z5 MOD Z6 - Z7 M0 = M1 BOR M2 BXOR M3 BAND M4 BOR $FF ) IF ( BNOT M1 BAND M2 - M3 GT 88 AND M4)

Z0 = (( Z1 MOD Z2 ) * Z3 ) + (( Z4 * Z5 ) MOD Z6 ) - Z7 M0 = (M1 BOR ( M2 BXOR ( M3 BAND M4 ))) BOR $FF IF (((( BNOT M1 ) BAND ( M2 - M3 )) GT 88 ) AND M4)

It is highly recommended to include lots of parenthesis clarifying the executing order. On the other hand, they facilitate later understanding and maintenance of the program.

Y R A IN M I L E PR

Using redundant or additional parenthesis will cause errors nor will it slow down the calculations. Up to 16 nesting levels are allowed using parenthesis.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 9 of 40

5.6 Statements. The MC language programming statements may be classified into: • • • • • • •

Resource definition statements. Variable declaration statements. Module definition statements. Assignment statements. Flow control statements. Wait statements. Movement statements.

Use the following nomenclature when describing statements: may be constant, a variable or an arithmetic or binary expression. any conditional expression between parenthesis "(" and ")".

Resource definition statements. They are used to associate names to system resources in order to be use them in a friendlier way throughout the program. There are two statements of this kind.

DEF This statement associates a name chosen by the user to a particular resource. Its format is: DEF

name resource

Where name is the chosen identifier. The "name" may have up to 32 characters (capital letters, numbers and a low dash (_). It must always begin with a letter or a low dash (_). The defined resource may be a drive variable or a numeric constant. For example: DEF ACC S260 DEF LIMIT 100 These statements associate the name of ‘ACC’ to the drive variable "S260 PositioningAcceleration" and the name of ‘LIMIT’ to the numeric constant "100". A name may only correspond to one resource, but a resource may have several names. Otherwise it issues warning W002.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 10 of 40

Y R A IN M I L E PR

Appendix 3 in this chapter shows the ‘fagor.inc’ file. It contains the "defines" for the main Sercos and Fagor variables. It also includes "defines" for some constants. This file is supplied in the same software package.

#INCLUDE With this statement, it is possible to include on a single program line a reference to a file containing the definitions of the resources. It facilitates the program structure and clarity. Its syntax is: #INCLUDE

"file path"

Where file path indicates the file location at the PC or even through a PC network. The file path must be indicated between quote marks ("). It must be follow the syntax rules of MS Windows and cannot exceed 255 characters. The file name cannot have any of these characters : ‘\’, ‘/’, ‘:’, ‘*’, ‘?’, ‘"’, ‘’ or ‘|’. It extension must be ‘.INC’ or ‘.inc’. Example: The ‘fagor.inc’ file contains defines for the main Sercos and Fagor variables. This file is supplied in the same software package. To use these definitions in the program, write the following line at the beginning of the program: #INCLUDE "C:\Editor\MyFiles\MCFiles\fagor.inc" or just #INCLUDE "fagor.inc" if the .mc program file and the fagor.inc file are in the same directory. The "#INCLUDE" statement must always be at the beginning of the program together with the "DEF" definitions. A user program may contain as many header.inc files as necessary. A header file cannot be referred to inside another header file. The ".inc" text file must be written following the same syntax rules required by any other program. The compiler admits up to 1000 definitions per program.

Y R A IN M I L E PR

There are files ready with the most common definitions. These "header files" are supplied in the same software package. See the appendix at the end of this chapter.

motion.inc, ad_da.inc, and Gen.inc "include" files for PLC programs . Not for MC. fagor.inc

Contains the "defines" for the main Sercos and Fagor variables and some constants.

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 11 of 40

Variable declaration statement. If the program is going to use variable, they must be defined beforehand. In other words, give them a name and reserve memory space for them. The DIM statement is used to declare variables and arrays.

DIM Several names of variables and/or arrays may be declared in a statement separated by commas (,). The order makes no difference. Its syntax is: DIM

VAR1, VAR2[number] , ...

Where VAR1 would be the name of the variable, VAR2 the name of an array and number the size or total number of elements in that array. The MC language operates with 32-bit variables. Therefore, each declared variable will have one of those 32-bit registers to store its numeric value. An array of "n" elements has "n" 32-bit registers. Up to 1000 variables may be declared. For example: DIM

POS, TABLE[5]

reserves a 32-bit register for the POS variable and 5 registers for the TABLE array.

DIM POS

32 bits POS

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 12 of 40

DIM TABLE[5]

32 bits TABLE[0] TABLE[1] TABLE[2] TABLE[3] TABLE[4]

Y R A IN M I L E PR

Module definition statements. The statements described next are used to define the beginning and end of the execution modules.

PROGRAM END They establish the beginning and end of the main program module and it is the only mandatory module. This module is the starting point of the execution of the program, but it does not need to be the first line of code. Its format is: PROGRAM instruc1 instruc2 ... END

Subroutine A subroutine is a portion of code identified with a name. It may be called upon for execution from any position of the program using the CALL instruction.

SUB ENDSUB They define the block of instructions between them as a subroutine. The format is:: SUB name instruc1 instruc2 ... ENDSUB This way, the series of codes between SUB and ENDSUB is group in a subroutine identified with the given name. The name of the subroutine may have up to 32 characters (capital letters, numbers and the low dash (_). It must always begin with a letter or a low dash (_) Two subroutines cannot have the same name. The ENDSUB statement establishes the end of the subroutine. It may also be used as return command so the execution of the program goes on from the line following the CALL instruction.

Y R A IN M I L E PR

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 13 of 40

Assignment statements. They are used to assign a value to the variables. Its syntax is: destination = The destination must be a variable declared by the user or a read/ write variable of the drive. The value given to the variable may be a constant or the result of an arithmetic or binary operation. For example: VAR1 = VAR2 * 2 + (VAR3 - 1) / 3 This statement assigns the result of the arithmetic expression to VAR1. The result of a relational expression cannot be assigned to a variable.

Flow control statements. The IF, WHILE, FOR statements evaluate the values of the program variables. They condition the flow of the program execution based on this evaluation. How are the conditions evaluated?: Usually, variables are evaluated through relational and logic operators: EQ, NE, GT, ... OR, AND, etc. When the condition is an arithmetic or logic expression, it will be considered TRUE when its result is OTHER THAN ZERO and FALSE if otherwise. For example: (KT+T0) (P3 AND P4) (ADD)

will true if arithmetic op. KT+T00 will be true if the result of logic op. is "1". will be true if the value of ADD0

IF ENDIF

Cnd ? Yes

FMC Fagor Motion Control (Version 0002) (Soft : V4.01)

MC Programming Chapter 5

Page 14 of 40

No

IF Cnd Instruction1 Instruction2 ENDIF

Y R A IN M I L E PR

Instruction1 Instruction2

IF ELSE ENDIF

IF Cnd Instruction1 ELSE Instruction2 ENDIF

No

Cnd ? Yes Instruction1

IF ELSIF ENDIF

Instruction2

No

Cnd1 ?

Cnd2 ?

Yes

Yes

Instruction1

Instruction2

IF Cnd1 Instruction1 ELSEIF Cnd2 Instruction2 ENDIF

No

This chained condition evaluation format allows up to 8 nesting levels

WHILE

Cnd ?

Yes

WHILE Cnd Instruction1 Instruction2 ENDWHILE

Instruction1 Instruction2

No

FOR A

M