Twido
Twido
Twido
Programmable Controllers
Software Reference Guide
TWD USE 10AE Version 1.0
31003914 00
2 TWD USE 10AE 05/2002
Table of Contents
Safety Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
About the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Chapter 5 Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
At a Glance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Communications Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
TwidoSoft to Controller Communications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Remote Link Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ASCII Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Modbus Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Standard Modbus Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Important Information
NOTICE Read these instructions carefully, and look at the equipment to become familiar with
the device before trying to install, operate, or maintain it. The following special
messages may appear throughout this documentation or on the equipment to warn
of potential hazards or to call attention to information that clarifies or simplifies a
procedure.
The addition of this symbol to a Danger or Warning safety label indicates
that an electrical hazard exists, which will result in personal injury if the
instructions are not followed.
This is the safety alert symbol. It is used to alert you to potential personal
injury hazards. Obey all safety messages that follow this symbol to avoid
possible injury or death.
DANGER
DANGER indicates an imminently hazardous situation, which, if not avoided, will
result in death, serious injury, or equipment damage.
WARNING
WARNING indicates a potentially hazardous situation, which, if not avoided, can result
in death, serious injury, or equipment damage.
CAUTION
CAUTION indicates a potentially hazardous situation, which, if not avoided, can result
in injury or equipment damage.
ADDITIONAL Those responsible for the application, implementation or use of this product must
SAFETY ensure that the necessary design considerations have been incorporated into each
INFORMATION application, completely adhering to applicable laws, performance and safety
requirements, regulations, codes and standards.
GENERAL
WARNINGS
WARNING
AND CAUTIONS
EXPLOSION HAZARD
l Substitution of components may impair suitability for Class I, Div 2
compliance.
l Do not disconnect equipment unless power has been switched off or
the area is known to be non-hazardous.
Failure to observe this precaution can result in severe injury or
equipment damage.
WARNING
UNINTENDED EQUIPMENT OPERATION
l Turn power off before installing, removing, wiring, or maintaining.
l This product is not intended for use in safety critical machine
functions. Where personnel and or equipment hazards exist, use
appropriate hard-wired safety interlocks.
l Do not disassemble, repair, or modify the modules.
l This controller is designed for use within an enclosure.
l Install the modules in the operating environment conditions
described.
l Use the sensor power supply only for supplying power to sensors
connected to the module.
l Use an IEC60127-approved fuse on the power line and output circuit
to meet voltage and current requirements. Recommended fuse:
Liitlefuse 5x20 mm slowblow type 218000 series/Type T.
Failure to observe this precaution can result in severe injury or
equipment damage.
At a Glance
Document Scope This is the Software Reference manual for Twido programmable controllers and
consists of the following major parts:
l Description of the Twido programming software and an introduction to the
fundamentals needed to program Twido controllers.
l Description of communications, managing analog I/O, and other special
functions.
l Description of the software languages used to create Twido programs.
l Description of instructions and functions of Twido controllers.
Validity Note The information in this manual is applicable only for Twido programmable
controllers.
Product Related Schneider Electric assumes no responsibility for any errors that appear in this
Warnings document. No part of this document may be reproduced in any form or means,
including electronic, without prior written permission of Schneider Electric.
I
At a Glance
Overview This part provides an introduction to the software languages and the basic
information required to create control programs for Twido programmable controllers.
1
At a Glance
Overview This chapter provides a brief introduction to TwidoSoft, the programming and
configuration software for Twido controllers, and to the List, Ladder, and Grafcet
programming languages used to create control programs.
Introduction to TwidoSoft
TwidoSoft TwidoSoft is a 32-bit Windows-based program for a personal computer (PC) running
Microsoft Windows 98 Second Edition or Microsoft Windows 2000 Professional
operating systems.
The main software features of TwidoSoft:
l Standard Windows user interface
l Program and configure Twido controllers
l Controller communication and control
For more details, see the TwidoSoft Operation Guide.
Introduction A programmable controller reads inputs, writes to outputs, and solves logic based
on a control program. Creating a control program for a Twido controller consists of
writing a series of instructions in one of the Twido programming languages.
Twido The following languages can be used to create Twido control programs:
Languages l Instruction List language
An Instruction List program is a series of logical expressions written as a
sequence of Boolean instructions.
l Ladder diagrams
A Ladder diagram is a graphical means of displaying a logical expression.
l Grafcet
Twido supports the use of Grafcet list instructions, but not graphical Grafcet.
You can use a personal computer (PC) to create and edit Twido control programs
using these programming languages.
A List/Ladder reversibility feature allows you to conveniently reverse a program from
Ladder to List and from List to Ladder.
Instruction List A program written in Instruction List language consists of a series of instructions
Language executed sequentially by the controller. The following is an example of a List
program.
0 BLK %C8
1 LDF %I0.1
2 R
3 LD %I0.2
4 AND %M0
5 CU
6 OUT_BLK
7 LD D
8 AND %M1
9 ST %Q0.4
10 END_BLK
Ladder Diagrams Ladder diagrams are similar to relay logic diagrams that are used to represent relay
control circuits. Graphic elements such as coils, contacts, and blocks represent
instructions. The following is an example of a Ladder diagram.
%I0.1 %C8
N R E
%M1 %Q0.4
S ADJ Y D
%C8.P 777
%I0.2 %M0
CU F
CD
Grafcet Grafcet is an analytical method which divides any sequential control system into a
Language series of steps which have associated actions, transitions, and conditions. The
following illustration shows examples of Grafcet instructions in List and Ladder
programs respectively.
0 -*- 3
1 LD %M10
2 # 4
3 # 5
4 -*- 4
5 LD %I0.7
6 # 6
7 -*- 5
8 LD %M15
9 # 7
10 ...
–*–3
%M10 4
#
5
#
–*–4
%I0.7 6
#
–*–5
%M15 7
2
At a Glance
Overview This chapter provides details about the language objects used for programming
Twido controllers.
Introduction Word and bit objects are valid if they have been allocated memory space in the
controller. To do this, they must be used in the application before downloaded to the
controller.
Example The range of valid objects is from zero to the maximum reference for that object type.
For example, if your application’s maximum references for memory words is %MW9,
then %MW0 through %MW9 are allocated space. %MW10 in this example is not
valid and can not be accessed either internally or externally.
Bit Objects
Introduction Bit objects are software variable bits that are single bits of data that can be used as
operands and tested by Boolean instructions. The following is a list of bit objects:
l I/O bits
l Internal bits (memory bits)
l System bits
l Step bits
l Bits extracted from words
List of Operand The following table lists and describes all of the main bit objects that are used as
Bits operands in Boolean instructions.
Type Description Address or Maximum number Write
Value access1
Immediate 0 or 1 (False or True) 0 or 1 - -
values
Inputs These bits are the "logical images" of the %Ix.y.z2 Note4 No
Outputs electrical states of the I/O. They are stored in Yes
%Qx.y.z2
data memory and updated during each scan of
the program logic.
Internal Internal bits are internal memory areas used to %Mi 128 TWDLCAA10DRF, Yes
(Memory) store intermediary values while a program is TWDLCAA16DRF
running. 256 All other
Note: Unused I/O bits can not be used as controllers
internal bits.
System System bits %S0 to %S127 monitor the correct %Si 128 According
operation of the controller and the correct to i
running of the application program.
Function The function block bits correspond to the outputs %TMi.Q, Note4 No3
blocks of the function blocks. %Ci.P, and so
These outputs may be either directly connected on.
or used as an object.
Reversible Function blocks programmed using reversible E, D, F, Q, Note4 No
function programming instructions BLK, OUT_BLK, and TH0, TH1
blocks END_BLK.
Word One of the 16 bits in some words can be Varies Varies Varies
extracts extracted as operand bits.
Grafcet Bits %X1 to %Xi are associated with Grafcet %X21 62 TWDLCAA10DRF, Yes
steps steps. Step bit Xi is set to 1 when the TWDLCAA16DRF
corresponding step is active, and set to 0 when 94 TWDLCAA24DRF,
the step is deactivated. Modular Controllers
Notes:
1. Written by the program or by using the Animation Tables Editor.
2. See I/O Addressing.
3. Except for %SBRi.j and %SCi.j, these bits can be read and written.
4. Number is determined by controller model.
Word Objects
Introduction Word objects that are addressed in the form of 16-bit words that are stored in data
memory and can contain an integer value between -32768 and 32767 (except for
the fast counter function block which is between 0 and 65535).
Examples of word objects:
l Immediate values
l Internal words (%MWi) (memory words)
l Constant words (%KWi)
l I/O exchange words (%IWi, %QWi)
l System words (%SWi)
l Function blocks (configuration and/or runtime data)
Word Formats The contents of the words or values are stored in user memory in 16-bit binary code
(two’s complement) using the following convention:
Bit position
F E D C B A 9 8 7 6 5 4 3 2 1 0
0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 Bit state
16348
8192
4096
2048
1024
512
256
128
64
32
16
|+
Bit value
8
4
2
1
In signed binary notation, bit 15 is allocated by convention to the sign of the coded
value:
l Bit 15 is 0: the content of the word is a positive value.
l Bit 15 is 1: the content of the word is a negative value (negative values are
expressed in two’s complement logic).
Words and immediate values can be entered or retrieved in the following format:
l Decimal
Min: -32768, Max: 32767 (for example, 1579)
l Hexadecimal
Min: 16#0000, Max: 16#FFFF (for example, 16#A536)
Alternate syntax: #A536
Extracted bits It is possible to extract one of the 16 bits from the following words:
Internal %MWi:Xk 1500 Yes
System %SWi:Xk 128 Depends on i
Constants %KWi:Xk 64 No
Input %IWi.j:Xk Note 2 No
Note:
1. Written by the program or by using the Animation Tables Editor.
2. Number is determined by controller model.
Format Use the following format to address internal, system, and step bit objects:
% M, S, or X i
Description The following table describes the elements in the addressing format.
Group Element Description
Symbol % The percent symbol always precedes a software variable.
Object type M Internal bits store intermediary values while a program is
running.
S System bits provide status and control information for the
controller.
X Step bits provide status of step activities.
Number i The maximum number value depends on the number of objects
configured.
Bit Objects TwidoSoft is used to extract one of the 16 bits from words. The address of the word
Extracted from is then completed by the bit row extracted according to the following syntax:
Words
WORD :X k
Introduction Addressing word objects, except for input/output addressing (see Addressing
Inputs/Outputs, p. 31) and function blocks (see Function Block Objects, p. 34),
follows the format described below.
Format Use the following format to address internal, constant and system words.
% M, K or S W i
Description The following table describes the elements in the addressing format.
Group Element Description
Symbol % The percent symbol always precedes an internal
address.
Object type M Internal words store intermediary values while a
program is running.
K Constant words store constant values or alphanumeric
messages. Their content can only be written or modified
by using TwidoSoft.
S System words provide status and control information for
the controller.
Format W 16-bit word.
Number i The maximum number value depends on the number of
objects configured.
Addressing Inputs/Outputs
Introduction Each input/output (I/O) point in a Twido configuration has a unique address: for
example, a specific input on a controller is assigned the address of "%I0.0.4".
I/O addresses can be assigned for the following hardware:
l Controller configured as Remote Link Master
l Controller configured as Remote I/O
l Expansion I/O modules
Multiple In a program, you can have multiple references to a single output or coil. Only the
References to an result of the last one solved is updated on the hardware outputs. For example,
Output or Coil %Q0.0.0 can be used more than once in a program, and there will not be a warning
for multiple occurrences. So it is important to confirm which output will result in the
desired operation.
CAUTION
Unintended Operation
No duplicate output checking or warnings are provided. Review the use
of the outputs or coils before making changes to them in your
application.
Failure to observe this precaution can result in injury or
equipment damage.
Network Addressing
Introduction Application data is exchanged between peer controllers and the master controller on
a Twido Remote Link network by using the network words %INW and %QNW. See
Communications , p. 63 for more details.
Introduction Function blocks provide bit objects and specific words that can be accessed by the
program.
S D
ADJ Y
%Ci.P 9999
CU
CD F
Bit Objects Bit objects correspond to the block outputs. These bits can be accessed by Boolean
test instructions using either of the following methods:
l Directly (for example, LD E) if they are wired to the block in reversible
programming (see Principles for Programming Basic Function Blocks, p. 208).
l By specifying the block type (for example, LD %Ci.E).
Inputs can be accessed in the form of instructions.
Word Objects Word objects correspond to specified parameters and values as follows:
l Block configuration parameters: some parameters are accessible by the program
(for example, pre-selection parameters), and some are inaccessible by the
program (for example, time base).
l Current values: for example, %Ci.V, the current count value.
Objects See the following appropriate sections for a list of objects that are accessible by the
Accessible by program.
the Program l For Basic Function Blocks, see Basic Function Blocks, p. 206.
l For Advanced Function Blocks, see Bit and Word Objects Associated with
Advanced Function Blocks, p. 257.
Structured Objects
Introduction Structured objects are combinations of simple objects. Twido supports the following
types of structured objects:
l Bit Strings
l Word Tables
Bit Strings Bit strings are a series of adjacent object bits of the same type and of a defined
length (L).
Example: Bit string %M8:6
%M8 %M9 %M10 %M11 %M12 %M13
Bit strings can be used with the Assignment instruction (see Assignment
Instructions, p. 232).
Note: (1) Only bits 0...L-1 can be addressed. Not all I/O can be addressed in bit
strings.
Word Tables Word tables are a series of adjacent words of the same type and of a defined length
(L).
Example: Word table %KW10:7
%KW10 16 bits
%KW16
Word tables can be used with the Assignment instruction (see Assignment
Instructions, p. 232).
Indexed Words
Introduction An indexed word is an internal or constant word with an indexed object address.
There are two types of object addressing:
l Direct addressing
l Indexed addressing
Direct A direct address of an object is set and defined when a program is written.
Addressing Example: %M26 is an internal bit with the direct address 26.
Words Available The following are the available types of words for indexed addressing.
for Indexed
Type Address Maximum size Write access
Addressing
Internal words %MWi[MWi] 0-i< or = %MWj<1500 Yes
Constant words %KWi[%MWj] 0-i<%MWj<64 No
Indexed words can be used with the Assignment instruction (see Assignment
Instructions, p. 232) and in Comparison instructions (see Comparison Instructions,
p. 236). This type of addressing enables series of objects of the same type (such as
internal words and constants) to be scanned in succession, by modifying the content
of the index word via the program.
Index Overflow An overflow of the index occurs when the address of an indexed object exceeds the
System Bit %S20 limits of the memory zone containing the same type of object. In summary:
l The object address plus the content of the index is less than 0.
l The object address plus the content of the index is greater than the largest word
directly referenced in the application. The maximum number is 1499 (for words
%MWi) or 63 (for words %KWi).
In the event of an index overflow, the system sets system bit %S20 to 1 and the
object is assigned an index value of 0.
Note: The user is responsible for monitoring any overflow. Bit %S20 must be read
by the user program for possible processing. The user must confirm that it is reset
to 0.
%S20 (initial state = 0):
l On index overflow: set to 1 by the system.
l Acknowledgment of overflow: set to 0 by the user, after modifying the index.
Symbolizing Objects
Introduction You can use Symbols to address Twido software language objects by name or
customized mnemonics. Using symbols allows for quick examination and analysis
of program logic, and greatly simplifies the development and testing of an
application.
Example For example, WASH_END is a symbol that could be used to identify a timer function
block that represents the end of a wash cycle. Recalling the purpose of this name
should be easier than trying to remember the role of a program address such as
%TM3.
Editing Symbols Symbols are defined and associated with language objects in the Symbol Editor.
Symbols and their comments are stored with the application on the PC hard drive,
but are not stored on the controller. Therefore, they can not be transferred with the
application to the controller.
See the TwidoSoft Operation Guide for more details for using symbols.
3
User Memory Structure
Introduction The controller memory accessible by an user application is divided into two distinct
sets:
l Bit values
l Word values (16-bit signed values)
Bit Memory The bit memory is stored in the internal RAM memory that is integrated into the
controller. It contains the map of 1280 bit objects.
Memory Types The following are the different types of memory for Twido controllers.
l Internal RAM (integrated)
This is integrated controller RAM memory. The first 10KB of internal RAM
memory is fast RAM while the next 32 KB is standard RAM. Internal RAM
contains program, constants, and data.
l Internal EEPROM
An integrated 32KB EEPROM that provides internal backup in the controller of an
application. Protects application from corruption due to battery failure or a power
outage lasting longer than 30 days. Contains program and constants.
l External memory backup cartridge
An optional external EEPROM cartridge for backing up an application or allowing
for a larger application. Can be used to update the application in controller RAM.
Contains program and constants, but no data.
Structure The following diagram describes the memory structure without an external memory
without External cartridge.
Memory Internal Data
Cartridge RAM
Program
Constants
Internal Saving
EEPROM program and
constants
Saving
%MW
Structure with The optional external memory cartridge provides back up for programs and
External Memory constants, and also offers expanded memory for larger applications.
Cartridge The following diagram describes the memory structure with the external memory
cartridge.
Internal Internal Field
RAM Data EEPROM cannot be used
Saving
%MW
External
EEPROM Program
cartridge
Constants
Saving Memory The controller internal RAM memory can be saved by one of the following:
l Internal battery (for up to 30 days)
l Internal EEPROM (maximum of 32 KB)
l Optional external memory cartridge (maximum of 64KB)
Transferring the application from the internal EEPROM memory to the RAM memory
is done automatically when the application is lost in RAM (if it has not been saved
or if there is no battery).
Manual transfer can also be performed using TwidoSoft.
Memory The following table describes the types of memory configurations possible with
Configurations Twido controllers.
Compact Controllers Modular Controllers
Memory type 10DRF 16DRF 24DRF 20DUK 20DRT 40DUK
20DTK 40DTK
Internal RAM 10KB 32KB 32KB 32KB 32KB 32KB
Available extended 64KB 64KB
memory*
Maximum application 10KB 32KB 32KB 32KB 32KB or 32KB or
size 64KB* 64KB*
Maximum external 32KB 32KB 32KB 64KB 32KB or 32KB or
backup 64KB 64KB
4
At a Glance
Overview This chapter describes controller operating modes and cyclic and periodic program
execution. Included are details about power outages and restoration.
Cyclic Scan
Introduction The cyclic scan binds the master task cycles one after the other without waiting for
anything except the inevitable system processing. After having effected the output
update (third phase of the task cycle), the system executes a certain number of its
own tasks and immediately triggers another task cycle.
Note: The scan time of the user program is monitored by the controller watchdog
timer and must not exceed 150 ms. Otherwise a fault appears causing the
controller to stop immediately in Halt mode. Outputs in this mode are forced to their
default fallback state.
Operation The following drawing shows the running phases of the cyclical scan time.
Processing the Processing
program the program
I.P. %I %Q I.P. %I %Q
Internal Processing
Acquiring Inputs
RUN STOP
Processing Program
Updating Outputs
Periodic Scan
Introduction In this operating mode, acquiring inputs, processing the application program, and
updating outputs are done periodically according to the time defined at configuration
(from 2-150 ms).
At the beginning of the controller scan, a timer, the value of which is initialized at the
period defined at configuration, starts to count down.The controller scan must end
before the timer has finished and relaunches a new scan.
Operation The following drawing shows the running phases of the periodic scan time.
Processing the Processing the
program program
Starting the
period
Internal processing
Acquiring inputs
RUN STOP
Program processing
Updating outputs
Internal processing
End of period
General Points The master task cycle is monitored by a watchdog timer called Tmax (a maximal
duration of master task cycle). It permits the showing of application errors (infinite
loops, and so on.) and assures a maximal duration for output refreshing.
Software In periodic or cyclic operation, the triggering of the watchdog causes a software
WatchDog error. The application passes into a HALT state and sets bit %S11 to 1. The
(Periodic or relaunching of the task necessitates a connection to Twido Soft in order to analyze
Cyclic the cause of the error, modification of the application to correct the error, and
Operation) relaunching the INIT and RUN requests.
Note: The HALT state is when the application is stopped immediately because of
an application software error such as a scan overrun. The data retains the current
values, which allows for an analysis of the cause of the error. The tasks are all
stopped on the current instruction. Communication with the controller is available.
Check on In periodic operation an additional check is used to detect the period being
Periodic exceeded:
Operation l %S19 indicates that the period has been exceeded. It is set to:
l 1 by the system when the scan time is greater that the task period.
l 0 by the user.
l %SW0 contains the period value (0-150 ms). It is:
l Initialized when starting from a cold start by the value set in the configuration.
l It can be modified by the user.
Using Master The following system words are used for information on the controller scan cycle
Task Running time:
Time l %SW11 initializes to the maximum watchdog time (10 to 500 ms).
l %SW30 contains the execution time for the last controller scan cycle.
l %SW31 contains the execution time for the longest controller scan cycle since
the last cold start.
l %SW32 contains the execution time for the shortest controller scan cycle since
the last cold start.
Note: This different information can also be accessed from the configuration editor.
Operating Modes
Introduction Twido Soft is used to take into account the three main operating mode groups:
l Checking
l Running or production
l Stopping
Note: These operating modes are defined in the "Design Guide for Operating and
Stopping Modes" produced by the Applied Industrial Automation Development
Agency.
Starting through These different operating modes can be obtained around or starting from Grafcet
Grafcet using the following methods:
l Grafcet initialization
l Presetting of steps
l Maintaining a situation
l Freezing charts
Preliminary processing and use of system bits ensure effective operating mode
management without complicating and overburdening the user program.
Grafcet System Use of bits %S21, %S22 and %S23 is reserved for preliminary processing only.
Bits These bits are automatically reset by the system. They must be written by Set
Instruction S only.
The following table provides Grafcet-related system bits:
Bit Function Description
%S21 GRAFCET initialization Normally set to 0, it is set to 1 by:
l A cold restart, %S0=1.
l The user, in the pre-processing program part only,
using a Set Instruction S %S21 or a set coil -(S)-
%S21.
Consequences:
l Deactivation of all active steps.
l Activation of all initial steps.
%S22 GRAFCET RESET Normally set to 0, it can only be set to 1 by the program
in pre-processing.
Consequences:
l Deactivation of all active steps.
l Scanning of sequential processing stopped.
%S23 Preset and freeze Normally set to 0, it can only be set to 1 by the program
GRAFCET in pre-processing.
l Reset Grafcet by setting %S22 to 1.
l Preposition the steps to be activated by a series of S
Xi instructions.
l Enable prepositioning by setting %S23 to 1.
Freezing a situation:
l In initial situation: by maintaining %S21 at 1 by
program.
l In "empty" situation: by maintaining %S22 at 1 by
program.
l In situation determined by maintaining %S23 at 1.
Illustration The following illustration shows the various power restarts detected by the system.
If the duration of the cut is less than the power supply filtering time (about 10 ms for
an alternating current supply or 1 ms for a direct current supply), this is not noticed
by the program which runs normally.
Run
Run
Application
Power failure
Standby power
Power restoration
WAIT
No
Saving No
Context OK
Yes
Memory card No
identical
Yes
Normal execution of
Warm start Cold start
program
Note: The context is saved in a battery backed-up RAM. At power up, the system
checks the state of the battery and the saved context to decide if a warm start can
occur.
Run/Stop Input The Run/Stop input bit has priority over the Automatic Start in Run option that is
Bit Versus Auto available from the Scan Mode dialog box (see the TwidoSoft Operation Guide). If the
Run Run/Stop bit is set, then the controller will restart in the Run Mode when power is
restored.
The mode of the controller is determined as follows:
Run/Stop Input Bit Auto Start in Run Resulting State
Zero Zero Stopped
Zero One Stopped
Rising edge Don’t care Running
One Don’t care Running
Not configured in software Zero Stopped
Not configured in software One Running
Note: For all Compact type of controllers, if the controller was in Run mode when
power was interrupted, and the "Automatic Start in Run" flag was not set from the
Scan Mode dialog box, the controller will restart in Stop mode when power is
restored.
Note: For all Modular type of controllers, if the battery in the controller is operating
normally when power was interrupted, the controller will startup in the mode that
was in effect at the time the power was interrupted. The "Automatic Start in Run"
flag, that was selected from the Scan Mode dialog, will have no effect on the mode
when the power is restored.
Operation The table below describes the processing phases for power cuts.
Phase Description
1 In the event of a power cut the system stores the application context and the time
of the cut.
2 It sets all outputs in a fallback state as a function of the security parameters (%S9).
3 When power is restored, the context saved is compared with the one in progress
which defines the type of start to run:
l If the application context has changed (loss of system context or new
application), the controller initializes the application: start up from cold,
l If the application context is the same, the controller restarts without initializing
data: warm restart.
Illustration The drawing below describes a warm restart operation in RUN mode.
RUN WAIT
Acquisition of inputs
if bit %S1=1,
possible process with Restoration of power
warm restart
Partial configuration
auto-tests
Detection of
power cut Yes
Set bit %S1 to 1
>Micro power for only one cycle
cut
No
BOT
Update outputs
Restart of the The table below describes the restart phases for running a program after a warm
Program restart.
Execution
Phase Description
1 The program execution resumes from the same element where it was prior to
the power cut, without updating the outputs.
Note: Only the same element from the user code is restarted. The system code
(for example, the updating of outputs) is not restarted.
2 At the end of the restart cycle, the system:
l Unreserves the application if it was reserved (and provokes a STOP
application in case of debugging)
l Reinitializes the messages
3 The system carries out a restart cycle in which it:
l Relaunches the task with bits %S1 (warm-start flag) and %S13 (first cycle in
RUN) set to 1
l Resets bits %S1 and %S13 to 0 at the end of the first task cycle
Processing of a In the event of a warm-start, if a particular application process is required, bit %S1
Warm-Start must be tested at the start of the task cycle, and the corresponding program called
up.
Outputs after As soon as a power failure is detected, the outputs are set to a fall-back (default)
Power Failure state of 0.
When power is restored, outputs are at last state until they are updated again by the
task.
Illustration The drawing below describes a cold restart operation in RUN mode.
RUN WAIT
Acquisition of inputs
if bit %S0=1,
possible process with Restoration of power
cold restart
AUTO-TESTS
Detection of Completion of
power cut Yes
configuration auto-tests
>Micro power
cut
Initialization of
No application
BOT
Update outputs
Operation The table below describes the restart phases for running a program after a cold
restart.
Phase Description
1 At start up, the controller is in RUN.
At a cold restart after a stop due to an ERROR, the system forces a cold restart.
The program execution restarts at the beginning of the cycle.
2 The system:
l Resets internal bits and words and the I/O images to 0
l Initializes system bits and words
l Initializes function blocks from configuration data
3 For this first restart cycle, the system:
l Relaunches the task with bits %S0 (cold restart flag) and %S13 (first cycle in
RUN) set to 1
l Resets bits %S0 and %S13 to 0 at the end of this first task cycle
Processing of a In the event of a cold-start, if a particular application process is required, bit %S0
Cold-Start (which stays at 1) must be tested during the first cycle of the task.
Outputs after As soon as a power failure is detected, the outputs are set to a fall-back (default)
Power Failure state of 0.
When power is restored, outputs are at 0 until they are updated again by the task.
Introduction The controllers can be initialized by Twido Soft by setting system bits %S0 (a cold
restart) and %S1 (a warm restart).
Cold Start For a cold start initialization, system bit %S0 must be set to 1.
Initialization
Warm Start For a warm start initialization, system bit %S1 and %S0 must be set to 1.
Initialization The following example shows how to program a warm restart initialization using
Using %S0 and system bits.
%S1
%S1 %S0
Note: Do not set %S0 to 1 for more than one controller scan.
Warm Start A warm start initialization can also be requested using an INIT command. The INIT
Initialization command sends the controller into the IDLE state, and reinitialization of the
Using INIT application data and task state in STOPPED state.
Command
II
At a Glance
Overview This part describes communications, built-in analog functions, and managing analog
I/O modules for Twido controllers.
5
At a Glance
Communications Overview
Overview Twido provides one or two serial communications ports used for communications to
remote controllers, peer controllers, or general external devices. Either port, if
available, can be used for any of the services, with the exception of communicating
with Twido Soft, which can only be performed using the first port. Three different
base protocols are supported on each Twido controller: Remote Link, ASCII, or
Modbus (modbus master or modbus slave).
Remote Link The remote link is a high-speed master/slave bus designed to communicate a small
amount of data between the master controller and up to seven remote (slave)
controllers. Application or I/O data is transferred, depending on the configuration of
the remote controllers. A mixture of remote controller types is possible, where some
can be remote I/O and some can be peers.
ASCII The ASCII protocol is a simple half-duplex character mode protocol used to transmit
and/or receive a character string to/from a simple device (printer or terminal). This
protocol is supported only via the "EXCH" instruction.
Modbus The Modbus protocol is a master/slave protocol that allows for one, and only one,
master to request responses from slaves, or to act based on the request. The master
can address individual slaves, or can initiate a broadcast message to all slaves.
Slaves return a message (response) to queries that are addressed to them
individually. Responses are not returned to broadcast queries from the master.
Modbus Master - The modbus master mode allows the Twido controller to initiate
transmission of a modbus query, with a response expected from a modbus slave.
The modbus master mode is only supported via the "EXCH" instruction. Both
Modbus ASCII and RTU are supported in modbus master mode.
Modbus Slave - The modbus slave mode allows the Twido controller to respond to
modbus queries from a modbus master, and is the default communications mode if
no communication is configured. The Twido controller supports the standard
modbus data and control functions and service extensions for object access. Both
Modbus ASCII and RTU are supported in modbus slave mode.
Overview Each Twido controller has on its Port 1 a built-in EIA RS-485 terminal port with
internal power supply. You must use Port 1 to communicate to the TwidoSoft
programming package. No optional cartridge or communication module can be used
for this connection.
CAUTION
UNEXPECTED EQUIPMENT DAMAGE
TwidoSoft may not sense a disconnect when physically moving the
TSXPCX1031 communication cable from a first controller and quickly
inserting it in a second controller. To avoid this condition, use TwidoSoft
to disconnect before moving the cable.
Failure to observe this precaution can result in injury or
equipment damage.
Cable The EIA RS-232C Port on your personal computer is connected to the controller’s
Connection Port 1 using the TSXPCX1031 multi-function communication cable. This cable
converts signals between EIA RS-232 and EIA RS-485. This cable is equipped with
a 4-position rotary switch to select different modes of operation. The switch
designates the four positions as "0-3", and the appropriate setting for TwidoSoft to
Twido controller is location 2.
This connection is illustrated in the diagram below.
Port 1 PC Serial Port
RS485 TSXPCX1031 EIA RS-232
2
1 3
0
Note: The DPT signal is not tied to ground. The signal is internally pulled up
indicating to the firmware executive that this is a TwidoSoft connection.
Pin outs of Male The following figure shows the pin outs of a male 8-pin miniDIN connector.
and Female Pin outs RS-485
Connectors 1 A (+)
2 B (-)
6 7 8 3 NC
3 4 5 4 /DE
5 DPT
1 2 6 NC
7 0V
8 5V
The following figure shows the pin outs of a female 9-pin subD connector.
Pin outs RS-232
1 6 1 DCD
2 RX
3 TX
4 DTR
5 SG
9 6 NC
5 7 RTS
8 CTS
9 NC
Introduction The remote link is a high-speed master/slave bus designed to communicate a small
amount of data between the master controller and up to seven remote (slave)
controllers. Application or I/O data is transferred, depending on the configuration of
the remote controllers. A mixture of remote controller types is possible, where some
can be remote I/O and some can be peers.
Note: The remote I/O bus and the protocol used is proprietary and no third party
devices are allowed on the network.
CAUTION
UNEXPECTED EQUIPMENT OPERATION
l Be sure that there is only one master controller on a remote link and
that each slave has a unique address. Failure to observe this
precaution may lead to corrupted data or unexpected and
ambiguous results.
l Be sure that all slaves have unique addresses. No two slaves should
have the same address. Failure to observe this precaution may lead
to corrupted data or unexpected and ambiguous results.
Failure to observe this precaution can result in injury or
equipment damage.
Note: The remote link requires an EIA RS-485 connection and can only run on one
communications port at a time.
Hardware Remote link must use a minimum 3-wire EIA RS-485 port. This means that it can be
Configuration configured to use either the first or an optional second port if present.
Cable
Connection to
Note: The DPT signal on pin 5 must be tied to ground on pin 7 in order to signify
Each Device
the use of remote link communications. When this signal is not tied to ground, the
Twido controller as either the master or slave will default to a mode of attempting
to establish communications with TwidoSoft.
Note: The DPT to GND connection is only necessary if you are connected to a
base controller on Port 1.
Software There must be only one master controller defined on the remote link. In addition,
Configuration each remote controller must maintain a unique slave address. Multiple masters or
slaves using identical addresses can either corrupt transmissions or create
ambiguity.
CAUTION
Unexpected Equipment Operation
Be sure that there is only one master controller on a remote link and that
each slave has a unique address. Failure to observe this precaution
may lead to corrupted data or unexpected and ambiguous results.
Failure to observe this precaution can result in injury or
equipment damage.
Master The master controller is configured using TwidoSoft to manage a remote link
Controller network of up to seven remote controllers. The master supports a heterogeneous
Configuration mixture of both remote controllers (either as remote I/O and peer controllers) on the
remote link. The address of the master is configured using TwidoSoft to be at
address 0.
Remote Each of the remote controllers can be used as either a remote I/O or a peer
Controller controller. These are configured using TwidoSoft to be assigned address from 1 and
Configuration 7 (Note that 0 is reserved for the remote link master).
The table below summarizes the differences and constraints of each of these types
of remote controller configurations:
Type Application Program Data Access
Remote I/O No %I and %Q
Not even a simple "END" Only local I/O on the remote controller is
statement accessible. (Not its expansion I/O)
Peer controller Yes %INW and %QNW
Remote The update cycle of the remote link is not synchronized with the master controller’s
Controller Scan scan. The communications with the remote controllers is interrupt driven and
Synchronization happens as a background task in parallel with the running of the master controller’s
scan. At the end of the scan cycle, the most up to date values are read into the
application data to be used for the next solve. This processing is the same for
remote I/O and peer controllers.
Any controller can check for general link activity using system bit %S111. But to
achieve synchronization, a master or peer will have to use system bit %S110. This
is set to 1 when a complete update cycle has taken place. The application program
is responsible to reset this to 0.
The master can enable or disable the remote link using system bit %S112.
Controllers can check on the proper configuration and health of the remote link using
%S113. The DPT signal on Port 1 (used to determine if TwidoSoft is connected) is
sensed and reported on %S100.
All these are summarized in the following table:
System Bit State Indication
%S100 0 master/slave: DPT not active (TwidoSoft cable NOT connected)
1 master/slave: DPT active (TwidoSoft cable connected)
%S110 0 master/slave: reset by application
1 master: all remote link exchanges completed (remote I/O only)
slave: exchange with master completed
%S111 0 master: single remote link exchange completed
slave: single remote link exchange detected
1 master: single remote link exchange active
slave: single remote link exchange detected
%S112 0 master: remote link disabled
1 master: remote link enabled
%S113 0 master/slave: remote link configuration/operation OK
1 master: remote link configuration/operation error
slave: remote link operation error
Slave Controller If a slave controller restarts, one of the following events happens:
Restart l A cold start (%S0 = 1) forces a re-initialization of the communications.
l A warm start (%S1 = 1) forces a re-initialization of the communications.
l In Stop mode, the slave continues communicating with the master. If the master
indicates a Stop is requested:
l The remote I/O affects a Stop,
l A peer controller continues in it’s current state.
Remote I/O Data The remote controller configured to be a remote I/O does not have or execute its
Access own application program. The remote controller's base digital inputs and outputs are
a simple extension of the master controller's. The application must only use the full
three digit addressing mechanism provided.
%Q2.0.2
%I7.0.4
To communicate with remote I/O, the master controller uses the standard input and
output notation of %I and %Q. To access the third output bit of the remote I/O
configured at address 2, the master would set %Q2.0.2. Similarly, to read the fifth
input bit of the remote I/O configured at location 7, the master would load %I7.0.4.
Note: The master is restricted to accessing only the digital I/O that is part of the
remote’s local I/O. No analog or expansion I/O can be transferred, unless you use
peer communications.
Remote Link
%I2.0.0 %I0.0.0
... ...
%I2.0.x %I0.0.x
%Q2.0.0 %Q0.0.0
... ...
%Q2.0.x %Q0.0.x
%I4.0.0 %I0.0.0
... ...
%I4.0.x %I0.0.x
%Q4.0.0 %Q0.0.0
... ...
%Q4.0.x %Q0.0.x
Peer Controller To communicate with peer controllers, the master uses network words %INW and
Data Access %QNW to exchange data. Each peer on the network is accessed by its remote
address "j" using words %INWj.k and %QNWj.k. Each peer controller on the network
uses %INW0.0 to %INW0.3 and %QNW0.0 to %QNW0.3 to access data on the
master. Network words are updated automatically when the controllers are in RUN
or STOPPED mode.
The example below illustrates the exchange of a master with two configured peer
controllers.
Remote Link
%INW1.0 %QNW0.0
... ...
%INW1.x %QNW0.x
%QNW1.0 %INW0.0
... ...
%QNW1.X %IWN0.x
%QNW0.0
%INW3.0 ...
... %QNW0.x
%INW3.X
%INW0.0
%INW3.0
...
...
%INW0.X
%INW3.X
Status In addition to the system bits explained earlier, the master maintains status on the
Information presence and configuration of remote controllers. This is done in system words
%SW111 and %SW113. Either the remote or the master can acquire the value of
the last error that occurred while communicating on the remote link in system word
%SW112.
Each of these is detailed in the following table:
System Use
Words
%SW111 Remote Link status: two bits for each remote controller (master only)
x0-5 0 - Remote controller 1-6 not present
1 - Remote controller 1-6 present
x6 0 - Remote controller 7 not present
1 - Remote controller 7 present
x8-13 0 - Remote I/O detected at remote controller 1-6
1 - Peer controller detected at remote controller 1-6
x14 0 - Remote I/O detected at remote controller 7
1 - Peer controller detected at remote controller 7
%SW112 Remote Link configuration/operation error code:
0 - operations are successful
1 - timeout detected (slave)
2 - checksum error detected (slave)
3 - configuration mismatch (slave)
%SW113 Remote Link configuration: two bits for each remote controller (master
only)
x0-5 0 - Remote controller 1-6 not configured
1 - Remote controller 1-6 configured
x6 0 - Remote controller 7 not configured
1 - Remote controller 7 configured
x8-13 0 - Remote I/O configured as remote controller 1-6
1 - Peer controller configured as remote controller 1-6
x14 0 - Remote I/O configured as remote controller 7
1 - Peer controller configured as remote controller 7
I0.1
Master Controller Remote I/O Peer Controller
Q0.0
Q0.1
The hardware configuration is three base controllers of any type. Port 1 is used in a
dual mode. One mode is to configure and transfer the application program with
TwidoSoft. The second mode is for the Remote Link network. If available, an
optional Port 2 on any of the controllers can be used, but a controller only supports
a single Remote Link.
Note: In this example the first two inputs on the Remote I/O are hard wired to its
outputs.
Connect the D(+) and D(-) signal wires together. And at each controller, the DPT
signal is tied to ground. Although tying the signal to ground is not required for use
with a remote link on Port 2 (optional cartridge or communication module), it is good
practice.
Note: The cable needs to be moved after each controller configuration and
application transfer.
Once all three controllers are programmed, connect the controllers on the Remote
Link network as described in Step 2.
Step 4: Configure the Software:
Controller Comm Setup Controller Comm Setup Controller Comm Setup
Type: Remote Link Type: Remote Link Type: Remote Link
Address: 0 (Master) Address: 1 Address: 2
Note: Only one controller can be configured as the master on a Remote Link.
In TwidoSoft, add a "Remote I/O" at address "1" and a "Peer controller" at address
"2".
For the controller configured as a remote I/O, verify that the controller
communication setup is set to "Remote Link" and the address is set to "1". For the
controller configured as peer, verify that the controller communication setup is set to
"Remote Link" and the address is set to "2".
LD %I0.0
ST %Q1.0.0
LD %I1.0.0
ST %Q0.0
LD %I0.1
ST %Q1.0.1
LD %I1.0.1
ST %Q0.1
In this example, master application increments an internal memory word and
communicates this to the peer controller using a single network word. The peer
controller takes the word received from the master and echoes it back. In the master,
a different memory word receives and stores this transmission.
For communication with the remote I/O controller, the master sends its local inputs
to the remote I/O’s outputs. With the external I/O hard wiring of the remote I/O, the
signals are returned and retrieved by the master.
Note: This communication takes place under the master’s application. There is no
application in the remote I/O controller.
ASCII Communications
Introduction ASCII protocol provides Twido controllers a simple half-duplex character mode
protocol to transmit and/or receive data with a simple device. This protocol is
supported using the EXCHx instruction and controlled using the %MSGx function
block.
Three types of communications are possible with the ASCII Protocol:
l Transmission Only
l Transmission/Reception
l Reception Only
The maximum size of frames transmitted and/or received using the EXCHx
instruction is 128 bytes.
Hardware An ASCII link can be established on either the EIA RS-232 or EIA RS-485 port and
Configuration can run on as many as two communications ports at a time.
The table below lists the devices that can be used:
Device Port Characteristics
TWDCAA10/16/24DRF, 1 Base controller supporting a 3-wire EIA RS-485 using a miniDin
TWDLMDA20/40DUK, connector.
TWDLMDA20/40DTK,
TWDLMDA20DRT
TWDNOZ232D 2 Communication module supporting a 3-wire EIA RS-232 using a
miniDin connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNOZ485D 2 Communication module supporting a 3-wire EIA RS-485 using a
miniDin connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNOZ485T 2 Communication module supporting a 3-wire EIA RS-485 using a
terminal connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNAC232D 2 Communication adapter supporting a 3-wire EIA RS-232 using a
miniDin connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDNAC485D 2 Communication adapter supporting a 3-wire EIA RS-485 using a
miniDin connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDNAC485T 2 Communication adapter supporting a 3-wire EIA RS-485 using a
terminal connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDXCPODM 2 Operator Display expansion module supporting a 3-wire EIA RS-
232 using a miniDIN connector, EIA RS-485 using a miniDIN
connector, or EIA RS-485 using a terminal connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Communication expansion module.
Nominal Cabling Nominal cable connections are illustrated below for both the EIA RS-232 and the
EIA RS-485 types.
Note: If port 1 is used on the Twido controller, the DPT signal must be tied to GND.
This signifies to the Twido controller that the communications through port 1 is
ASCII and is not the protocol used to communicate with the TwidoSoft software.
The specific remote device might require the use of additional signals (DTR, DSR,
and so on).
Twido Remote
Controller Device
TXD RXD GND TXD RXD GND
Note: The DPT to GND connection is only necessary if you are connected to a
base controller on Port 1.
Software To configure the controller to use a serial connection to send and receive characters
Configuration using the ASCII protocol, you must:
Stage Description
1 Configure the serial port for ASCII using TwidoSoft.
2 Create in your application a transmit/receive buffer for ASCII to use the EXCHx
instruction.
Configuring the A Twido controller can use its primary port 1 or an optionally configured port 2 to use
Port the ASCII protocol. To configure a serial port for ASCII:
Step Action
1 Define any additional option cartridges or modules physically configured to the
base.
2 Right-click on the port and click Edit Controller Comm Setup... and change serial
port type to "ASCII".
3 Set the associated communication parameters.
Configuring the The maximum size of the frames transmitted and/or received is 128 bytes, and the
Transmit/ word table associated with the EXCHx instruction is composed of both the
Receive Buffer transmission and reception tables.
for ASCII
Most Significant Byte Least Significant Byte
Control words Command Length (Tx/Rx)
Reserved (0) Reserved (0)
Transmission table Transmitted Byte 1 Transmitted Byte 2
... ...
... Transmitted Byte n
Transmitted Byte n+1
Reception table Received Byte 1 Received Byte 2
... ...
... Received Byte p
Received Byte p+1
Control The Length byte contains the length to be transmitted, which is overwritten by the
Parameters number of characters received at the end of the reception, if reception is requested.
The Command byte must contain one of the following:
l 0: Transmission Only
l 1: Transmission/Reception
l 2: Reception Only
Transmission/ When in Transmit Only mode, the Control and Transmission tables are filled in prior
Reception to executing the EXCHx instruction, and can be of type %KW or %MW. No space is
Tables required for the reception of characters in Transmission Only mode. Once all bytes
are transmitted, the state of %MSGx.D is set to 1, and a new EXCHx instruction can
be executed.
When in Transmission/Reception mode, the Control and Transmission tables are
filled in prior to executing the EXCHx instruction, and must be of type %MW. Space
for up to 128 reception bytes is required at the end of the Transmission table. Once
all bytes are transmitted, the Twido controller switches to reception mode and waits
to receive any bytes.
When in Reception Only mode, the Control table is filled in prior to executing the
EXCHx instruction, and must be of type %MW. Space for up to 128 reception bytes
is required at the end of the Control table. The Twido controller immediately enters
the reception mode and waits to receive any bytes.
Reception ends when the end-of-frame byte is received, or the Reception table is
full. If a non-zero time out is configured, reception ends when the time out is
completed. If a zero time out value is selected, there is no reception time out;
therefore to stop reception, the %MSGx.R input must be activated.
There is no inherent addressing associated with the ASCII protocol, unless the
simple device has it built into the protocol, but the Twido controller does not support
it.
Message The Twido controller can be configured to send and/or receive messages in
Exchange character mode. The language offers two services for this:
l EXCHx instruction: to transmit/receive messages
l %MSGx function block: to control the message exchanges.
The Twido controller uses the protocol configured for that port when processing an
EXCHx instruction.
Note: Each communications port can be configured for different protocols or the
same. The EXCHx instruction or %MSGx function block for each communications
port is accessed by appending the port number (1 or 2).
EXCHx The EXCHx instruction allows the Twido controller to send and/or receive
Instruction information to/from ASCII devices. The user defines a table of words (%MWi:L or
%KWi:L) containing control information and the data to be sent and/or received (up
to 64 data words in transmission and/or reception). The format for the word table is
described earlier.
A message exchange is performed using the EXCHx instruction:
Syntax: [EXCHx %MWi:L] or [EXCHx %KWi:L]
%MSGx Function The use of the %MSGx function block is optional; it can be used to manage data
Block exchanges. The %MSGx function block has three purposes:
l Communications error checking
The error checking verifies that the block length (word table) programmed with
the EXCHx instruction is large enough to contain the length of the message to be
sent. This is compared with the length programmed in the least significant byte
of the first word of the word table).
l Coordination of multiple messages
To ensure the coordination when sending multiple messages, the %MSGx
function block provides the information required to determine when a previous
message is complete.
l Transmission of priority messages
The %MSGx function block allows the current message transmission to be
stopped, in order to allow the immediate sending of an urgent message.
The %MSGx function block has one input and two outputs associated with it:
Input/Output Definition Description
R Reset input Set to 1: re-initializes communication or resets
block (%MSGx.E = 0 and %MSGx.D = 1).
%MSGx.D Communication 0: Request in progress.
complete 1: communication done if end of transmission, end
character received, error, or reset of block.
%MSGx.E Error 0: Message length OK and link OK.
1: if bad command, table incorrectly configured,
incorrect character received (speed, parity, and so
on.), or reception table full.
Error and If an error occurs when using the EXCHx instruction, bits %MSGx.D and %MSGx.E
Operating Mode are set to 1 and system word %SW63 contains the error code for Port 1, and
Conditions %SW64 contains the error code for Port 2.
The minimum requirement for the wiring of the ASCII communications cable is a
basic 3-wire connection. Cross the transmit and receive signals.
Note: On the PC side of the cable, additional connections (such as Data Terminal
Ready and Data Set Ready) may be needed to satisfy the handshaking. No
additional connections are required to satisfy the Twido controller.
Finally, the error status of the %MSG2 is sensed and stored on the first output bit on
the local base controller I/O. Additional error checking using %SW64 could also be
added to make this more robust.
Step 5: Initialize the Animation Table Editor:
Address Current Retained Format
1 %MW10 0104 0000 Hexadecimal
2 %MW11 0000 0000 Hexadecimal
3 %MW12 4F4B 0000 Hexadecimal
4 %MW13 0A0D 0000 Hexadecimal
5 %MW14 TW 0000 ASCII
6 %MW15 ID 0000 ASCII
7 %MW16 O 0000 ASCII
8 %MW17 A 0000 ASCII
The final step is to download this application controller and run it. Initialize an
Animation Table Editor to animate and display the %MW10 through %MW17 words.
On the Terminal Emulator, the characters "O"-"K"-CR-LF are displayed. There may
be many of these depending on the number of times the EXCH block times out and
a new one is issued. On the Terminal Emulator, type "T"-"W"-"I"-"D"-"O"-" "-"A". This
is exchanged with the Twido controller and displayed in the Animation Table Editor.
Modbus Communications
Introduction The Modbus protocol is a master-slave protocol that allows for one, and only one,
master to request responses from slaves, or to act based on the request. The master
can address individual slaves, or can initiate a broadcast message to all slaves.
Slaves return a message (response) to queries that are addressed to them
individually. Responses are not returned to broadcast queries from the master.
Hardware A Modbus link can be established on either the EIA RS-232 or EIA RS-485 port and
Configuration can run on as many as two communications ports at a time.
The table below lists the devices that can be used:
Device Port Characteristics
TWDCAA10/16/24DRF, 1 Base controller supporting a 3-wire EIA RS-485 using a miniDin
TWDLMDA20/40DUK, connector.
TWDLMDA20/40DTK,
TWDLMDA20DRT
TWDNOZ232D 2 Communication module supporting a 3-wire EIA RS-232 using a
miniDin connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNOZ485D 2 Communication module supporting a 3-wire EIA RS-485 using a
miniDin connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNOZ485T 2 Communication module supporting a 3-wire EIA RS-485 using a
terminal connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Operator Display expansion module.
TWDNAC232D 2 Communication adapter supporting a 3-wire EIA RS-232 using a
miniDin connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDNAC485D 2 Communication adapter supporting a 3-wire EIA RS-485 using a
miniDin connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDNAC485T 2 Communication adapter supporting a 3-wire EIA RS-485 using a
terminal connector.
Note: This adapter is only available for the Compact 16 and 24 I/O
controllers and the Operator Display expansion module.
TWDXCPODM 2 Operator Display expansion module supporting a 3-wire EIA RS-
232 using a miniDIN connector, EIA RS-485 using a miniDIN
connector, or EIA RS-485 using a terminal connector.
Note: This module is only available for the Modular controllers.
When the module is attached, the controller cannot have an
Communication expansion module.
Nominal Cabling Nominal cable connections are illustrated below for both the EIA RS-232 and the
EIA RS-485 types.
Note: If port 1 is used on the Twido controller, the DPT signal must be tied to GND.
This signifies to the Twido controller that the communications through port 1 is
Modbus and is not the protocol used to communicate with the TwidoSoft software.
The specific remote device might require the use of additional signals (DTR, DSR,
and so on).
Twido Remote
Controller Device
TXD RXD GND TXD RXD GND
Note: The DPT to GND connection is only necessary if you are connected to a
base controller on Port 1.
Software To configure the controller to use a serial connection to send and receive characters
Configuration using the Modbus protocol, you must:
Stage Description
1 Configure the serial port for Modbus using TwidoSoft.
2 Create in your application a transmit/receive buffer for Modbus to use the
EXCHx instruction.
Configuring the A Twido controller can use its primary port 1 or an optionally configured port 2 to use
Port the Modbus protocol. To configure a serial port for Modbus:
Step Action
1 Define any additional option cartridges or modules physically configured to the
base.
2 Right-click on the port and click Edit Controller Comm Setup... and change serial
port type to "Modbus".
3 Set the associated communication parameters.
Modbus Master Modbus master mode allows the controller to initiate transmission of a Modbus
query, with a response expected from a Modbus slave. The Modbus Master mode
is only supported via the EXCHx instruction. Both Modbus ASCII and RTU are
supported in Modbus Master mode.
The maximum size of the frames transmitted and/or received is 128 bytes, and the
word table associated with the EXCHx instruction is composed of transmission and
reception tables.
Most Significant Byte Least Significant Byte
Control words Command Length (Tx/Rx)
Rx Offset Tx Offset
Transmission table Transmitted Byte 1 Transmitted Byte 2
... ...
... Transmitted Byte n
Transmitted Byte n+1
Reception table Received Byte 1 Received Byte 2
... ...
... Received Byte p
Received Byte p+1
Control The Length byte contains the length to transmit, which is overwritten by the number
Parameters of characters received at the end of the reception, if reception is requested.
This parameter is the length in bytes of the transmission table. If the Tx Offset
parameter is equal to 0, this parameter will be equal to the frame length itself minus
the 2 CRC bytes. If the Tx Offset parameter is not equal to 0, one byte of the buffer
(indicated by the offset value) will not be transmitted and this parameter is equal to
the frame length itself plus 1.
The Command byte in case of Modbus RTU request (except for broadcast) must
always equal to 1 (Tx and Rx).
The Tx Offset byte contains the offset (1 for the first byte, 2 for the second byte, and
so on.) within the Transmission Table to ignore when transmitting the packet. This
is used to handle the issues associated with byte/word values within the Modbus
protocol. For example, if this byte contains 3, the third byte would be ignored,
making the fourth byte in the table the third byte to be transmitted.
The Rx Offset byte contains the offset (1 for the first byte, 2 for the second byte, and
so on.) within the Reception Table to add when transmitting the packet. This is used
to handle the issues associated with byte/word values within the Modbus protocol.
For example, if this byte contains 3, the third byte within the table would be filled with
a ZERO, and the third byte was actually received would be entered into the fourth
location in the table.
Transmission/ When using either mode (Modbus ASCII or Modbus RTU), the Transmission table
Reception is filled with the request prior to executing the EXCHx instruction. At execution time,
Tables the controller determines what the Data Link Layer is, and performs all conversions
necessary to process the transmission and response. Start, end, and check
characters are not stored in the Transmission/Reception tables.
Once all bytes are transmitted, the controller switches to reception mode and waits
to receive any bytes. Reception is completed in one of several ways: end-of-frame
character received in ASCII mode; time out on a character or frame has been
detected; the Reception table is full.
The Transmitted Byte X entries contain Modbus protocol (RTU encoding) data that
is to be transmitted. If the communications port is configured for Modbus ASCII, the
correct framing characters are appended to the transmission. The first byte contains
the device address (specific or broadcast), the second byte contains the function
code, and the rest contain the information associated with that function code.
Note: This is a typical application, but does not define all the possibilities. No
validation of the data being transmitted will be performed.
The Received Byte X entries contain Modbus protocol (RTU encoding) data that is
to be received. If the communications port is configured for Modbus ASCII, the
correct framing characters are removed from the response. The first byte contains
the device address, the second byte contains the function code (or response code),
and the rest contain the information associated with that function code.
Note: This is a typical application, but does not define all the possibilities. No
validation of the data being received will be performed, except for checksum
verification.
Modbus Slave Modbus slave mode allows the controller to respond to Modbus queries from a
Modbus master. The controller supports the standard Modbus Data and Control
functions, and UMAS extensions for configuration and object access.
When the TSXPCX1031 cable is attached to the controller, Modbus Slave mode
communications is started at the port, temporarily disabling the communications
mode that was running prior to the cable being connected.
The Modbus protocol supports two Data Link Layer formats: ASCII and RTU. Each
is defined by the Physical Layer implementation, with ASCII using 7 data bits, and
RTU using 8 data bits.
When using Modbus ASCII mode, each byte in the message is sent as two ASCII
characters. The Modbus ASCII frame begins with a start character (’:’), and ends
with two end characters (CR and LF). The end-of-frame character defaults to 0x0A
(line feed), and the user can modify the value of this byte during configuration. The
check value for the Modbus ASCII frame is a simple two’s complement of the frame,
excluding the start and end characters.
Modbus RTU mode does not reformat the message prior to transmitting; however,
it uses a different checksum calculation mode, specified as a CRC.
The Modbus Data Link Layer has the following limitations:
l Address 1-247
l Bits: 128 bits on request using Modbus open requests
l Words: 64 words of 16 bits on request using Modbus open requests
Message The Twido controller can be configured to send and/or receive messages in
Exchange character mode. The language offers two services for this:
l EXCHx instruction: to transmit/receive messages
l %MSGx function block: to control the message exchanges.
The Twido controller uses the protocol configured for that port when processing an
EXCHx instruction.
Note: Each communications port can be configured for different protocols or the
same. The EXCHx instruction or %MSGx function block for each communications
port is accessed by appending the port number (1 or 2).
EXCHx The EXCHx instruction allows the Twido controller to send and/or receive
Instruction information to/from Modbus devices. The user defines a table of words (%MWi:L or
%KWi:L) containing control information and the data to be sent and/or received (up
to 64 data words in transmission and/or reception). The format for the word table is
described earlier.
A message exchange is performed using the EXCHx instruction:
Syntax: [EXCHx %MWi:L] or [EXCHx %KWi:L]
%MSGx Function The use of the %MSGx function block is optional; it can be used to manage data
Block exchanges. The %MSGx function block has three purposes:
l Communications error checking
The error checking verifies that the block length (word table) programmed with
the EXCHx instruction is large enough to contain the length of the message to be
sent. This is compared with the length programmed in the least significant byte
of the first word of the word table).
l Coordination of multiple messages
To ensure the coordination when sending multiple messages, the %MSGx
function block provides the information required to determine when a previous
message is complete.
l Transmission of priority messages
The %MSGx function block allows the current message transmission to be
stopped, in order to allow the immediate sending of an urgent message.
The %MSGx function block has one input and two outputs associated with it:
Input/Output Definition Description
R Reset input Set to 1: re-initializes communication or resets
block (%MSGx.E = 0 and %MSGx.D = 1).
%MSGx.D Communication 0: Request in progress.
complete 1: communication done if end of transmission, end
character received, error, or reset of block.
%MSGx.E Error 0: Message length OK and link OK.
1: if bad command, table incorrectly configured,
incorrect character received (speed, parity, and so
on.), or reception table full.
Error and If an error occurs when using the EXCHx instruction, bits %MSGx.D and %MSGx.E
Operating Mode are set to 1 and system word %SW63 contains the error code for Port 1, and
Conditions %SW64 contains the error code for Port 2.
The hardware configuration is two Twido controllers. One will be configured as the
Modbus Master and the other as the Modbus Slave.
Note: In this example, each controller is configured to use EIA RS-485 on Port 1
and an optional EIA RS-485 Port 2. On a Modular controller, the optional Port 2 can
be either a TWDNOZ485D or a TWDNOZ485T. On a Compact controller, the
optional Port 2 can be either a TWDNAC485D or a TWDNAC485T.
To configure each controller, connect the TSXPCX1031 cable to Port 1 of the first
controller.
Note: The TSXPCX1031 cable can only be connected to one controller at a time,
on the EIA RS-485 Port 1 only.
Next, connect the cable to the COM 1 port of the PC. Be sure that the switch is in
position 2. Download and monitor each application. Repeat procedure for second
controller.
The wiring in this example demonstrates a simple point to point connection. The
three signals A(+), B(-), and GND signals are wired according to the diagram.
If using Port 1 of the Twido controller, the DPT signal must be tied to ground This
conditioning of DPT determines if TwidoSoft is connected. When tied to ground, the
controller will use the port configuration set in the application to determine the type
of communication.
Step 3: Configure the Port:
Hardware -> Add Option Hardware -> Add Option
TWDNOZ485- TWDNOZ485-
Hardware => Controller Comm. Setup Hardware => Controller Comm. Setup
Port: 2 Port: 2
Type: Modbus Type: Modbus
Address: 1 Address: 2
Baud rate: 19200 Baud rate: 19200
Data: 8 Bit Data: 8 Bit
Parity: None Parity: None
Stop: 1 Bit Stop: 1 Bit
End of Frame: 65 End of Frame: 65
Response Timeout: 10 x 100 ms Response Timeout: 100 x 100 ms
Frame Timeout: 10 ms Frame Timeout: 10 ms
In both the master and slave applications, the optional EIA RS-485 ports are
configured. Be sure to change the controller communications to initialize the Modbus
addresses or Port 2 to two different addresses. In this example, the master is set to
an address of 1 and the slave to 2. The number of bits is set to 8, indicating that we
will be using Modbus RTU mode. If this had been set to 7, then we would be using
Modbus-ASCII mode. The only other default modified was to increase the response
timeout to 1 second.
Note: Since Modbus RTU mode was selected, the "End of Frame" parameter was
ignored.
Using TwidoSoft, an application program is written for both the master and the slave.
For the slave, we simple initialize some memory words to a set of known values. In
the master, the exchange block is initialized to read 4 words from the slave at
Modbus address 2 starting at location %MW0.
Note: Notice the use of the RX offset set in %MW1 of the Modbus master. The
offset of three will add a byte (value = 0) at the third position in the reception area
of the table. This aligns the words in the master so that they fall correctly on word
boundaries. Without this offset, each word of data would be split between two
words in the exchange block. This offset is used for convenience.
Before issuing the EXHC2 instruction, the application checks the Done bit
associated with %MSG2. Finally, the error status of the %MSG2 is sensed and
stored on the first output bit on the local base controller I/O. Additional error checking
using %SW64 could also be added to make this more robust.
Step 5: Initialize the Animation Table Editor:
Address Current Retained Format
1 %MW5 0203 0000 Hexadecimal
2 %MW6 0008 0000 Hexadecimal
3 %MW7 6566 0000 Hexadecimal
4 %MW8 6868 0000 Hexadecimal
5 %MW9 6970 0000 Hexadecimal
6 %MW10 7172 0000 Hexadecimal
After downloading and setting each controller to run, open an animation table on the
master. Examine the response section of the table to check that the response code
is 3 and that the correct number of bytes was read. Also in this example, note that
the words read from the slave (beginning at %MW7) are aligned correctly with the
word boundaries in the master.
Modbus Link The diagram below illustrates the use of Modbus function code 16 to write output
Example 2 words to a slave. This example uses two Twido Controllers.
Step 1: Configure the Hardware:
Twido Twido
Modbus Master Modbus Slave
A(+) B(-) GND A(+) B(-) GND
Note: Notice the use of the TX offset set in %MW1 of the Modbus master’s
application. The offset of seven will suppress the upper most byte in the sixth word
(the value 00 hexadecimal in %MW5). This works to align the data values in the
transmission table of the exchange block so that they fall correctly on word
boundaries.
Before issuing the EXHC2 instruction, the application checks the Done bit
associated with %MSG2. Finally, the error status of the %MSG2 is sensed and
stored on the first output bit on the local base controller I/O. Additional error checking
using %SW64 could also be added to make this more robust.
After downloading and setting each controller to run, open an animation table. The
two values in %MW16 and %MW17 are written to the slave. In the master, the
animation table can be used to examine the reception table portion of the exchange
data. This data displays the slave address, the response code, the first word written,
and the number of words written starting at %MW8 in the example above.
Introduction You can use these requests to exchange data between devices to access bit and
word information. The same table format is used for both RTU and ASCII modes.
Format Reference
Bit %Mi, 0x or 1x registers
Word %MWi, 3x or 4x registers
Note: The Rx Offset=3 will add a byte (value=0) at the third position in the reception
table. Allow a good positioning of the number of bytes read and of the read words’
values in this table.
Note:
l This request does not need the use of offset.
l The response frame is the same as the request frame here (in a normal case).
l For a bit to write 1, the associated word in the transmission table must contain
the value FF00H. 0 for a bit value is 0.
Note:
l This request does not need the use of offset.
l The response frame is the same as the request frame here (in a normal case).
Note:
l The Tx Offset=7 will suppress the 7th byte in the sent frame. Allow a good
correspondence of words’ values in the transmission table.
Note: The Tx Offset=7 will suppress the 5th MMSB byte in the sent frame. Allow a
good correspondence of words’ values in the transmission table.
6
At a Glance
Overview This chapter describes how to manage the built-in analog channel and
potentiometers.
Potentiometers
Programming The numerical values, from 0 to 1023 for potentiometer 1 and 0 to 511 for
potentiometer 2, corresponding to the analog values provided by these
potentiometers are contained in the following two system words:
l %IW0.0.0 for potentiometer 1 (leftmost)
l %IW0.0.1 for potentiometer 2 (rightmost)
These words can be used in arithmetic operations. They can be used for any type
of adjustment, for example, presetting a time-delay or a counter, adjusting the
frequency of the pulse generator or machine preheating time.
5s
0 1023
The following parameters are selected at configuration for the time-delay block
%TM0:
l Type TON
l Time base TB : 10 ms
The preset value of the time-delay is calculated from the adjustment value of the
potentiometer using the following equation %TM0.P := 2*%SW112+500.
Code for the above example:
LD 1
[%MW0:=2*%SW112]
%MW0:=2*%SW112
[%TM0.P:=%MW0+500]
BLK %TM0
%TM0.P:=%MW0+500 LD %I0.0
IN
OUT_BLK
%I0.2 %TM0 %Q0.0 LD Q
IN
ST %Q0.0
Q
END_BLK
...................
END
Analog Channel
Programming Controlling the temperature of an oven: The cooking temperature is set to 350°C.
Example A variation of +/- 2.5°C results in tripping of output %Q0.1 and %Q0.2, respectively.
Practically all of the possible setting ranges of the analog channel from 0 to 511 is
used in this example. Analog setting for the temperature set points are:
Temperature (°C) Voltage System Word %IW0.0.1
0 0 0
347.5 7.72 395
350 7.77 398
352.5 7.83 401
450 10 511
%Q0.0
LD [%IW0.0.1 = 395]
%IW0.0.1 = 395
ST %Q0.0
%Q0.1
LD [%IW0.0.1 <= 398]
%IW0.0.1 <= 398
ST %Q0.1
%Q0.2
LD [%IW0.0.1 >= 401]
%IW0.0.1 >= 401
ST %Q0.2
7
At a Glance
Overview This chapter provides an overview of managing analog modules for Twido
controllers.
Introduction In addition to the built-in 10-bit potentiometer and 9-bit analog channel, all the Twido
controllers that support expansion I/O are also able to configure and communicate
analog I/O modules.
These analog modules are:
Name Channels Signal Range Encoding
TWDAMI2HT 2 In 0 - 10 Volts or 4 - 20 mA 12 Bit
TWDAM01HT 1 Out 0 - 10 Volts or 4 - 20 mA 12 Bit
TWDAMM3HT 2 In, 1 Out 0 - 10 Volts or 4 - 20 mA 12 Bit
TWDALM3LT 2 In, 1 Out 0 - 10 Volts, Inputs Th or RTD, Outputs 12 Bit
4 - 20 mA
Operating Input and output words (%IW and %QW) are used to exchange data between the
Analog Modules user application and any of the analog channels. The updating of these words is
done synchronously with the controller scan during RUN mode.
CAUTION
Unexpected Equipment Operation
When the controller is set to STOP, the analog output is set to its fall-
back position. As is the case with digital output, the fall-back position is
zero.
Failure to observe this precaution can result in injury or
equipment damage.
Introduction Addresses are assigned to the analog channels depending on their location on the
expansion bus.
Example of In this example, a TWDLMDA40DUK has its built-in 10-bit potentiometer, a 9-bit
Addressing built-in analog channel. On the expansion bus, a TWDAMM3HT analog module, a
Analog I/O TWDDMM8DRT input/output digital relay module, and a second TWDAMM3HT
analog module are configured.
Introduction This section provides information on configuring analog module’s inputs and
outputs.
Configuring The Configure Module dialog box is used to manage the parameters of the analog
Analog I/O modules.
Note: You can only modify the parameters offline, when you are not connected to
a controller.
Addresses are assigned to the analog channels depending on their location on the
expansion bus. As a programming aid, you can also assign previously defined
symbols to manipulate the data in your user application.
You can configure channel types for the TWDAM01HT, TWDAMM3HT, and
TWDALM3LT's single output channel to be:
l Not used
l 0 - 10 V
l 4 - 20 mA
You can configure channel types for the TWDAMI2HT and TWDAMM3HT’s two
input channels to be:
l Not used
l 0 - 10 V
l 4 - 20 mA
CAUTION
Unexpected Equipment Damage
If you have wired your input for a voltage measurement, and you
configure TwidoSoft for a current type of configuration, you may
permanently damage the analog module. Ensure that the wiring is in
agreement with the TwidoSoft configuration.
Failure to observe this precaution can result in injury or
equipment damage.
Introduction This section provides an example of using Analog modules available with Twido.
Example This example compares the analog input signal with five separate threshold values.
A comparison of the analog input is made and a bit is set on the base controller if it
is less than the threshold.
LD [%IW1.0 <= 16]
%Q0.0 ST %Q0.0
%IW1.0 <= 16
LD [%IW1.0 <= 32]
%Q0.1 ST %Q0.1
%IW1.0 <= 32 LD [%IW1.0 <= 64]
ST %Q0.2
%Q0.2
%IW1.0 <= 64 LD [%IW1.0 <= 128]
ST %Q0.3
%Q0.3
%IW1.0 <= 128 LD [%IW1.0 <= 256]
ST %Q0.4
%Q0.4
%IW1.0 <= 256
8
At a Glance
Overview This chapter provides details for using the optional Twido Operator Display.
Operator Display
Introduction The Operator Display is a Twido option that provides an interface for displaying and
controlling application data and some controller functions such as operating state
and the Real-Time Clock (RTC). This option is available as a cartridge
(TWDXCPODC) for the Compact controllers or as an expansion module
(TWDXCPODM) for the Modular controllers.
The Operator Display has two operating modes:
l Display mode: only displays data.
l Edit mode: allows you to change data.
Note: The operator display is updated at a specific interval of the controller scan
cycle. This can cause confusion in interpreting the display of dedicated outputs for
%PLS or %PWM pulses. At the time these outputs are sampled, their value will
always be zero, and this value will be displayed. Ensure that the actual dedicated
output is manipulated by the configuration of the controlling function block.
Displays and The Operator Display provides the following separate displays with the associated
Functions functions you can perform for each display.
l Controller identification and state information
Display firmware revision and the controller state.Change the controller state with
the Run, Initial, and Stop commands. Display error codes in the Halted state.
l System objects and variables
Select application data by the address: %I, %Q, and all other software objects
on the base controller. Monitor and change the value of a selected software data
object.
l Serial port settings
Display and configure communication port settings.
l Time of day clock
Display and configure the current date and time (if the RTC is installed).
l Real-Time correction factor
Display and modify the RTC Correction value for the optional RTC.
Note: Time of day clock and real-time correction are only available if the Real-Time
Clock (RTC) option cartridge (TWDXCPRTC) is installed.
Illustration The following is a simplified diagram of the Operator Display, which consists of a
display area and four push-button input keys.
Display area
T M 1 2 3
V 1 2 3 4
MOD/
ESC ENTER
Input keys
Display Area The Operator Display provides an LCD display capable of displaying two lines of
characters:
l The first line of the display has three 13-segment characters and four 7-segment
characters.
l The second line has one 13-segment character, one 3-segment character (for a
plus/minus sign), and five 7-segment characters.
Input Keys The functions of the four input push-buttons depend on the Operator Display mode:
Key In Display Mode In Edit Mode
ESC Discard changes and return to previous
display.
Change current edit element to
successor value.
Advance to next display. Advance to next editing element.
Selecting and The initial display or screen of the Operator Display shows the controller identifi-
Navigating the cation and state information. Press the push-button to sequence through each
Displays of the displays. The screens for the Time of Day Clock or the Real-Time Correction
Factor are not displayed If the optional RTC cartridge (TWDXCPRTC) is not
detected on the controller.
As a shortcut, press the ESC key to return to the initial display screen. For most
screens, depressing ESC will return to the Controller Identification and State
Information screen. Only when editing a System Objects and Variable that is not the
initial entry (%I0.0.0), will pressing ESC take you to the first or initial system object
entry.
To modify an object value, instead of pressing the push-button to go to the first
value digit, press the MOD/ENTER again.
Introduction The initial display or screen of the Twido optional Operator Display shows the
Controller Identification and State Information.
Example The firmware revision is displayed in the upper-right corner of the display area, and
the controller state is displayed in the upper-left corner of the display area, as seen
in the following:
R U N 1 2 3
Controller Firmware
state revision
Displaying and Using the Operator Display, you can change to the INI state from the STP state, or
Changing from STP to RUN, or from RUN to STP. Do the following to change the state of the
Controller States controller:
Step Action
1 Press the key until the Operations Display is shown (or press ESC). The current
controller states is displayed in the upper-left corner of the display area.
2 Press the MOD/ENTER key to enter edit mode.
3 Press the key to select a controller state.
4 Press the MOD/ENTER key to accept the modified value. Or press the ESC key to
discard any modifications made while in edit mode.
Introduction The optional Operator Display provides these features for monitoring and adjusting
application data:
l Select application data by address (such as %I or %Q).
l Monitor the value of a selected software object/variable.
l Change the value of the currently displayed data object (including forcing inputs
and outputs).
System Objects The following table lists the system objects and variables, in the order accessed, that
and Variables can be displayed and modified by the Operator Display.
Object Variable/Attribute Description Access
Input %I.x.y.z Value Read/Force
Output %Q.x.y.z Value Read/Write/Force
Timer %TMX.V Current Value Read/Write
%TMX.P Preset Value Read/Write
%TMX.Q Done Read
Counter %Cx.V Current Value Read/Write
%Cx.P Preset Value Read/Write
%Cx.D Done Read
%Cx.E Empty Read
%Cx.F Full Read
Memory Bit %Mx Value Read/Write
Memory Word %MWx Value Read/Write
Constant Word %KWx Value Read
System Bit %Sx Value Read/Write
System Word %SWx Value Read/Write
Analog Input %IW.x.y.z Value Read
Analog Output %QW.x.y.z Value Read/Write
Fast Counter %FCx.V Current Value Read/Write
%FCx.P Preset value Read/Write
%FCx.D Done Read
Notes:
1. Variables will not be displayed if they are not used in an application since Twido
uses dynamic memory allocation.
2. If the value of %MW is greater than +32767 or less than -32787, the operator
display will continue to blink.
3. If the value of %SW is greater than 65535, the operator display continues to blink,
except for %SW0 and %SW11. If a value is entered that is more than the limit,
the value will return to the configured value.
4. If a value is entered for %PLS.P that is more than the limit, the value will be set
to saturation.
Displaying and Each type of system object is accessed by starting with the Input Object (%I),
Modifying sequencing through to the Message object (%MSG), and finally looping back to the
Objects and Input Object (%I).
Variables To display a system object:
Step Action
1 Press the key until the Data Display screen is shown.
The Input object ("I") will be displayed in the upper left corner of the display area.
The "I" character (or previous object name) is not blinking.
2 Press the MOD/ENTER key to enter edit mode.
The Input Object "I" character (or previous object name) begins blinking.
3 Press the key to step sequentially through the list of objects.
4 Press the key to step sequentially through the field of an object type and press
the key to increment through the value of that field. You can use the key
and key to navigate and modify all fields of the displayed object.
5 Repeat Steps 3 and 4 until editing is complete.
6 Press the MOD/ENTER key to accept the modified values.
Note: The object’s name and address have to be validated before accepting any
modifications. That is, they must exist in the configuration of the controller prior to
using the operator display.
Press ESC to discard any changes made in edit mode.
Data Values and In general, the data value for an object or variable is shown as a signed or unsigned
Display Formats integer in the lower-right of the display area. In addition, all fields suppress leading
zeros for displayed values. The address of each object is displayed on the Operator
Display in one of the following six formats:
l I/O format
l Function block format
l Simple format
l Network I/O format
l Step counter format
l Shift bit register format
Input/Output The input/output objects (%I, %Q, %IW, and %QW) have three-part addresses such
Format as %IX.Y.Z and are displayed as follows:
l Object type and controller address in the upper-left
l Expansion address in the upper-center
l I/O channel in the upper-right
In the case of a simple input (%I) and output (%Q), the lower-left portion of the
display will contain a character that is either "U" for unforced or "F" for a forced bit.
The force value is displayed in the lower-right of the screen.
The output object %Q0.3.11 appears in the display area as follows:
Q 0 3 1 1
F 1
Function Block The function blocks (%TM, %C, %FC, %VFC, %PLS, %PWM, %DR, %R, and
Format %MSGj) have two-part addresses containing an object number and a variable or
attribute name and are displayed as follows:
l Function block name in the upper-left
l Function block number (or instance) in the upper-right
l The variable or attribute in the lower-left
l Value for the attribute in the lower-right
In the following example, the current value for timer number 123 is set to 1,234.
T M 1 2 3
V 1 2 3 4
Simple Format A simple format is used for objects %M, %MW, %KW, %S, %SW, and %X as
follows:
l Object number in the upper-right
l Signed value for the objects in the lower portion
In the following example, memory word number 67 contains the value +123.
M W 6 7
+ 1 2 3
Network Input/ The network input/output objects (%INW and %QNW) appear in the display area as
Output Format follows:
l The object name in the upper-left
l Controller address in the upper-center
l Object number in the upper-right
l Signed value for the object in the lower portion
In the following example, the first input or network word of the remote controller
configured at remote address #2 is set to the value -4.
M N W 2 1
- 4
Step Counter The step counter (%SC) format displays the object number and the step counter bit
Format as follows:
l Object name and number in the upper left
l The step counter bit in the upper right
l The value of the object in the lower portion of the display
In the following example, bit number 129 of step counter number 3 is set to -1.
S C 3 1 2 9
- 1
Shift Bit Register The shift bit register (%SBR) format displays an object number and the register bit
Format as follows:
l Object name and number in the upper left
l The register bit in the upper right
The following example shows the display of shift bit register number 4.
S B R 4 9
1
Introduction You can display and modify protocol settings using the Operator Display. The
maximum number of serial ports is two. In the example below, the first port is
configured as Modbus protocol with an address 123. The second serial port is
configured as a Remote Link with an address of 5.
M 1 2 3
R 4
Displaying and Twido controllers can support up to two serial ports. To display the serial port
Modifying Serial settings using the operator display:
Port Settings
Step Action
1 Press the key until the Communication Display is shown. The single letter of
the protocol setting of the first serial port ("M", "R", or "A") will be displayed in the
upper left corner of the operator display.
2 Press the MOD/ENTER key to enter the edit mode.
3 Press the key until you are in the field that you wish to modify.
4 Press the key increment the value of that field.
5 Continue steps 3 and 4 until the Serial Port Settings are complete.
6 Press the MOD/ENTER key to accept the modified values or ESC to discard any
modifications made while in edit mode.
Introduction You can modify the date and time using the operator display if the RTC option
cartridge (TWDXCPRTC) is installed on your Twido controller. The Month is
displayed in the upper-left side of the HMI Display. Until a valid time has been
entered, the month field will contain the value "RTC". The day of the month is
displayed in the upper-right corner of the display. The time of day is in military
format. The hours and minutes are shown in the lower-right corner of the display and
are separated by the letter "h". The example below shows that the RTC is set to
March 28, at 2:22 PM.
M A R 2 8
1 4 h 2 2
Introduction You can display and modify the Real-Time Correction Factor using the operator
display. Each Real-Time Clock (RTC) Option module has a RTC Correction Factor
value that is used to correct for inaccuracies in the RTC module’s crystal. The
correction factor is an unsigned 3-digit integer from 0 to 127 and is displayed in the
lower-right corner of the display.
The example below shows a correction factor of 127.
R T C C o r r
1 2 7
III
At a Glance
Overview This part provides instructions for using the Ladder, List, and Grafcet programming
languages to create control programs for Twido programmable controllers.
9
At a Glance
Introduction Ladder diagrams are similar to relay logic diagrams that represent relay control
circuits. The main differences between the two are the following features of Ladder
programming that are not found in relay logic diagrams:
l All inputs are represented by contact symbols ( ).
l All outputs are represented by coil symbols ( ).
l Numerical operations are included in the graphical Ladder instruction set.
Ladder The following illustration shows a simplified wiring diagram of a relay logic circuit and
Equivalents to the equivalent Ladder diagram.
Relay Circuits
LS1 PB1 CR1 M1
LS1 PB1 CR1 M1 %I0.0 %I0.2 %I0.4 %Q0.4
LS2 SS1
LS2 SS1 %I0.1 %I0.7
Ladder Rungs A program written in Ladder language is composed of rungs which are sets of
graphical instructions drawn between two vertical potential bars. The rungs are
executed sequentially by the controller.
The set of graphical instructions represent the following functions:
l Inputs/outputs of the controller (push buttons, sensors, relays, pilot lights, ...)
l Functions of the controller (timers, counters, ...)
l Math and logic operations (addition, division, AND, XOR, ...)
l Comparison operators and other numerical operations (A<B, A=B, shift, rotate,
...)
l Internal variables in the controller (bits, words, ...)
These graphical instructions are arranged with vertical and horizontal connections
leading eventually to one or several outputs and/or actions. A rung cannot support
more than one group of linked instructions.
Example of The following diagram is an example of a Ladder program composed of two rungs.
Ladder Rungs
%I0.1 %M42
Example Rung 1
%I0.3
%M42 %Q1.2
Example Rung 2
%M22:=%MW15+%KW1
Programming Each Ladder rung consists of a grid of seven rows by eleven columns that are
Grid organized into two zones as shown in the following illustration.
Columns
1 2 3 4 5 6 7 8 9 10 11
Rows
1
4
Potential
Grid Bars
5
Cells
6
Test Zone
Action Zone
Grid Zones The Ladder diagram programming grid is divided into two zones:
l Test Zone
Contains the conditions that are tested in order to perform actions. Consists of
columns 1 - 10, and contains contacts, function blocks, and comparison blocks.
l Action Zone
Contains the output or operation that will be performed according to the results of
the tests of the conditions in the Test Zone. Consists of columns 8 - 11, and
contains coils and operation blocks.
Entering A Ladder rung provides a seven by eleven programming grid that starts in the first
Instructions in cell in the upper left-hand corner of the grid. Programming consists of entering
the Grid instructions into the cells of the grid. Test instructions, comparisons, and functions
are entered in cells in the test zone and are left-justified. The test logic provides
continuity to the action zone where coils, numerical operations, and program flow
control instructions are entered and are right-justified.
The rung is solved or executed (tests made and outputs assigned) within the grid
from top to bottom and from left to right.
Rung Headers In addition to the rung, a rung header appears directly above the rung. Use the rung
header to document the logical purpose of the rung. The rung header can contain
the following information:
l Rung number
l Labels (%Li)
l Subroutine declarations (SRi:)
l Rung title
l Rung comments
For more details about using the rung header to document your programs, see
Program Documentation, p. 159.
Introduction Ladder diagrams consist of blocks representing program flow and functions such as
the following:
l Contacts
l Coils
l Program flow instructions
l Function blocks
l Comparison blocks
l Operate blocks
Contacts, Coils, Contacts, coils, and program flow (jump and call) instructions occupy a single cell of
and Program the ladder programming grid. Function blocks, comparison blocks, and operate
Flow blocks occupy multiple cells.
The following are examples of a contact and a coil.
Contact Coil
Function Blocks Function blocks are placed in the test zone of the programming grid. The block must
appear in the first row; no ladder instructions or lines of continuity may appear above
or below the function block. Ladder test instructions lead to the function block’s input
side, and test instructions and/or action instructions lead from the block’s output
side.
Function blocks are vertically oriented and occupy two columns by four rows of the
programming grid.
The following is an example of a counter function block.
%C0
R E
S ADJ Y D
%C0.P 9999
CU F
CD
Comparison Comparison blocks are placed in the test zone of the programming grid. The block
Blocks may appear in any row or column in the test zone as long as the entire length of the
instruction resides in the test zone.
Comparison blocks are horizontally oriented and occupy two columns by one row of
the programming grid.
See the following example of a comparison block.
%MW0=%SW50
Operate Blocks Operate blocks are placed in the action zone of the programming grid. The block
may appear in any row in the action zone. The instruction is right-justified; it appears
on the right and ends in the last column.
Operate blocks are horizontally oriented and occupy four columns by one row of the
programming grid.
The following is an example of an operate block.
Introduction Instructions in Ladder diagrams consist of graphic elements. This section lists and
describes graphic elements used in Twido Ladder instructions. See the TwidoSoft
Operation Guide for details on using these graphic elements in Twido Ladder
programs.
Contacts The contacts graphic elements are programmed in the test zone and take up one
cell (one row high by one column wide).
Name Graphic Instruction Function
element
Normally open contact LD Passing contact when the
controlling bit object is at state 1.
Link Elements The graphic link elements are used to connect the test and action graphic elements.
Name Graphic Functions
element
Horizontal connector Links in series the test and action graphic
elements between the two potential bars.
Coils The coil graphic elements are programmed in the action zone and take up one cell
(one row high and one column wide).
Name Graphic Instruction Functions
element
Direct coil ST The associated bit object takes the
value of the test zone result.
Function Blocks The graphic elements of function blocks are programmed in the test zone and
require four rows by two columns of cells (except for very fast counters which require
five rows by two columns).
Name Graphic Functions
element
Timers, counters, Each of the function blocks uses inputs and outputs
registers, and so on. that enable links to the other graphic elements..
Note: Outputs of function blocks can not be
connected o each other (vertical shorts).
Operate and Comparison blocks are programmed in the test zone, and operate blocks are
Comparison programmed in the action zone.
Blocks
Name Graphic Functions
element
Comparison block Compares two operands, the output changes to 1
when the result is checked.
Size: one row by two columns
Introduction The OPEN and SHORT instructions provide a convenient method for debugging
and troubleshooting Ladder programs. These special instructions alter the logic of a
rung by either shorting or opening the continuity of a rung as explained in the
following table.
In List programming, the OR and AND instructions are used to create the OPEN and
SHORT instructions using immediate values of 0 and 1 respectively.
Examples The following are examples of using the OPEN and SHORT instructions.
SHORT
Programming Advice
Handling Use program jumps with caution to avoid long loops that can increase scan time.
Program Jumps Avoid jumps to instructions that are located upstream. (An upstream instruction line
appears before a jump in a program, while a downstream instruction line appears
after a jump in a program.)
Programming of An output bit or internal bit can only be controlled once in the program. In the case
Outputs of output bits, only the last value scanned is taken into account when the outputs are
updated.
Using Directly- Sensors used directly for emergency stops must not be processed by the controller.
Wired They must be connected directly to the corresponding outputs.
Emergency Stop
Sensors
Handling Power Make power returns conditional on a manual operation, as an automatic restart of
Returns the installation could cause unexpected operation of equipment (use system bits
%S0, %S1 and %S9).
Time and The state of system bit %S51, which indicates any schedule block faults, should be
Schedule Block checked.
Management
Syntax and Error When a program is entered, TwidoSoft checks the syntax of the instructions, the
Checking operands, and their association. See the TwidoSoft Operation Guide for more
details.
In order to perform the same function, the following equations must be programmed:
LD %I0.0
%I0.0 %I0.1 %Q0.1
MPS
AND( %I0.1
OR( %I0.2
AND %I0.3
%I0.2 %I0.3
)
)
ST %Q0.1
%I0.2 %Q0.0 MPP
AND %I0.2
ST %Q0.0
If several contacts are placed in parallel, they should either be nested within one
another or totally dissociated from each other:
%I0.2 %I0.3
%I0.6 %I0.7
%I0.2 %I0.4
%I0.2 %I0.3
%I0.4
%I0.2 %I0.3
%I0.4
LD %I0.0
%I0.0 %I0.1 %Q0.1 AND( %I0.1
OR( %I0.2
AND %I0.3
)
%I0.2 %I0.3
)
OR( %I0.4
AND %I0.3
%I0.4 %I0.3 )
ST %Q0.1
LD %I0.0
%I0.0 %I0.1 %I0.5 %Q0.1
AND( %I0.1
OR( %I0.2
AND %I0.3
)
%I0.2 %I0.3
AND %I0.5
OR( %I0.2
AND %I0.4
%I0.2 %I0.4 )
)
ST %Q0.1
Ladder/List Reversibility
%I0.5 %Q0.4
LD %I0.5
OR %I0.4
%I0.4 ST %Q0.4
Ensuring Programs created in Ladder can always be reversed to List, but some List logic may
Reversibility not reverse to Ladder. To ensure reversibility from List to Ladder, it is important to
follow the set of List programming guidelines in Guidelines for Ladder/List
Reversibility, p. 157 .
Instructions The structure of a reversible function block in List language requires the use of the
Required for following instructions:
Reversibility l BLK marks the block start, and defines the beginning of the rung and the start of
the input portion to the block.
l OUT_BLK marks the beginning of the output portion of the block.
l END_BLK marks the end of the block and the rung.
The use of the reversible function block instructions are not mandatory for a properly
functioning List program. For some instructions it is possible to program in List which
is not reversible. For a description of non-reversible List programming of standard
function blocks, see Principles for Programming Basic Function Blocks, p. 208.
Non-Equivalent Avoid the use of certain List instructions, or certain combinations of instructions and
Instructions to operands, which have no equivalents in Ladder diagrams. For example, the N
Avoid instruction (inverses the value in the Boolean accumulator) has no equivalent
Ladder instruction.
The following table identifies all List programming instructions that will not reverse
to Ladder.
List Instruction Operand Description
JMPCN %Li Jump Conditional Not
N none Negation (Not)
ENDCN none End Conditional Not
%Q0.4
LD 1
ST %Q0.4
LD 1
%MW5 := 0 [%MW5 := 0]
JMP %L6
>>%L6
Notice that each of the above unconditional List sequences begin with a load
instruction followed by a one, except for the JMP instruction. This combination sets
the Boolean accumulator value to one, and therefore sets the coil (store instruction)
to one and sets%MW5 to zero on every scan of the program. The exception is the
unconditional jump List instruction (JMP %L6) which is executed regardless of the
value of the accumulator and does not need the accumulator set to one.
Ladder List If a List program is reversed that is not completely reversible, the reversible portions
Rungs are displayed in the Ladder view and the irreversible portions are displayed in
Ladder List Rungs.
A Ladder List Rung functions just like a small List editor, allowing the user to view
and modify the irreversible parts of a Ladder program.
Program Documentation
Documenting You can document your program by entering comments using the List and Ladder
Your Program editors (see the TwidoSoft Operation Guide for details on using these program
editors):
l Use the List Editor to document your program with List Line Comments. These
comments may appear on the same line as programming instructions, or they
may appear on lines of their own.
l Use the Ladder Editor to document your program using rung headers found
directly above the rung.
The TwidoSoft programming software uses these comments for reversibility, When
reversing a program from List to Ladder, TwidoSoft uses some of the List comments
to construct a rung header, and the comments inserted between List sequences are
used for rung headers.
Example of List The following is an example of a List program with List Line Comments.
Line Comments ---- ( * THIS IS THE TITLE OF THE HEADER FOR RUNG 0 * )
---- ( * THIS IS THE FIRST HEADER COMMENT FOR RUNG 0 * )
---- ( * THIS IS THE SECOND HEADER COMMENT FOR RUNG 0 * )
0 LD % I0. 0 ( * THIS IS A LINE COMMENT *)
1 OR %I0. 1 ( * A LINE COMMENT IS IGNORED WHEN REVERSING TO LADDER * )
2 ANDM %M10
3 ST M101
---- ( * THIS IS THE HEADER FOR RUNG 1 * )
---- ( * THIS RUNG CONTAINS A LABEL * )
---- ( * THIS IS THE SECOND HEADER COMMENT FOR RUNG 1 * )
---- ( * THIS IS THE THIRD HEADER COMMENT FOR RUNG 1 * )
---- ( * THIS IS THE FOURTH HEADER COMMENT FOR RUNG 1 * )
4 % L5:
5 LD %M101
6 [ %MW20 := %KW2 * 16 ]
---- ( * THIS RUNG ONLY CONTAINS A HEADER TITLE * )
7 LD %Q0. 5
8 OR %I0. 3
9 ORR I0. 13
10 ST %Q0.5
Reversing List When List instructions are reversed to a Ladder diagram, List Line Comments are
Comments to displayed in the Ladder Editor according to the following rules:
Ladder l The first comment that is on a line by itself is assigned as the rung header.
l Any comments found after the first become the body of the rung.
l Once the body lines of the header are occupied, then the rest of the line
comments between List sequences are ignored, as are any comments that are
found on list lines that also contain list instructions.
Example of Rung The following is an example of a Ladder program with rung header comments.
Header
Comments
Reversing When a Ladder diagram is reversed to List instructions, rung header comments are
Ladder displayed in the List Editor according to the following rules:
Comments to l Any rung header comments are inserted between the associated List sequences.
List l Any labels (%Li:) or subroutine declarations (SRi:) are placed on the next line
following the header and immediately prior to the beginning of the List sequence.
l If the List was reversed to Ladder, any comments that were ignored will reappear
in the List Editor.
10
At a Glance
Line Number Line numbers are generated automatically when you enter an instruction. Blank
lines and Comment lines do not have line numbers.
Instruction Code The instruction code is a symbol for an operator that identifies the operation to be
performed using the operand(s). Typical operators specify Boolean and numerical
operations.
For example, in the sample program above, LD is the abbreviation for the instruction
code for a LOAD instruction. The LOAD instruction places (loads) the value of the
operand %I0.1 into an internal register called the accumulator.
There are basically two types of instructions:
l Test instructions
These setup or test for the necessary conditions to perform an action. For
example, LOAD (LD) and AND.
l Action instructions
These perform actions as a result of setup conditions. For example, assignment
instructions such as STORE (ST) and RESET (R).
Introduction List instructions have only one explicit operand, the other operand is implied. The
implied operand is the value in the Boolean accumulator. For example, in the
instruction LD %I0.1, %I0.1 is the explicit operand. An implicit operand is stored in
the accumulator and will be written over by value of %I0.1.
Operation A List instruction performs a specified operation on the contents of the accumulator
and the explicit operand, and replaces the contents of the accumulator with the
result. For example, the operation AND %I1.2 performs a logical AND between the
contents of the accumulator and the Input 1.2 and will replace the contents of the
accumulator with this result.
All Boolean instructions, except for Load, Store, and Not, operate on two operands.
The value of the two operands can be either True or False, and program execution
of the instructions produce a single value, either True or False. Load instructions
place the value of the operand in the accumulator, while Store instructions transfer
the value in the accumulator to the operand. The Not instruction has no explicit
operands and simply inverts the state of the accumulator.
Supported List The following table is a summary of the types of supported List instructions.
Instructions
Type of Instruction Example Function
Bit instruction LD %M10 Reads internal bit %M10
Block instruction IN %TM0 Starts the timer %TM0
Word instruction [%MW10 := %MW50+100] Addition operation
Program instruction SR5 Calls subroutine #5
Grafcet instruction -*-8 Step #8
Test Instructions The following table describes test instructions in List language.
Name Equivalent Function
graphic
element
LD The Boolean result is the same as the status of the
operand.
LDN The Boolean result is the same as the reverse status of the
operand.
LDR The Boolean result changes to 1 on detection of the
P operand (rising edge) changing from 0 to 1.
AND The Boolean result is equal to the AND logic between the
Boolean result of the previous instruction and the status of
the operand.
ANDN The Boolean result is equal to the AND logic between the
Boolean result of the previous instruction and the reverse
status of the operand.
ANDR The Boolean result is equal to the AND logic between the
P Boolean result of the previous instruction and the detection
of the operand’s rising edge (1 = rising edge).
ANDF The Boolean result is equal to the AND logic between the
N Boolean result of the previous instruction and the detection
of the operand’s falling edge (1 = falling edge).
OR The Boolean result is equal to the OR logic between the
Boolean result of the previous instruction and the status of
the operand.
XORF
XORF
N - Negation (NOT)
STN The associated operand takes the reverse value of the test
zone result.
Function Block The following table describes function blocks in List language.
Instructions
Name Equivalent Functions
graphic
element
Timers, counters, For each of the function blocks, there are
registers, and so on. instructions for controlling the block.
A structured form is used to hardwire the block
inputs and outputs directly.
Note: Outputs of function blocks can not be
connected to each other (vertical shorts).
Using Parentheses
Introduction Use parentheses in AND and OR logic instructions to indicate parallel branches in
Ladder diagrams. The open and closed parentheses are associated with
instructions as follows:
l Opening the parentheses is associated with the AND or OR instruction.
l Closing the parentheses is an instruction which is required for each open
parentheses.
Example Using The following diagrams are examples of using a parentheses with an AND
an AND instruction: AND(...).
Instruction %I0.1
%I0.0 %Q0.0
LD %I0.0
AND %I0.1
%I0.2 OR %I0.2
ST %Q0.0
Example Using The following diagrams are examples of using a parentheses with an OR instruction:
an OR OR(...).
Instruction
LD %I0.0
%I0.0 %I0.1 %Q0.0
AND %I0.1
OR( %I0.2
%I0.2 %I0.3
AND %I0.3
)
ST %Q0.0
Modifiers The following table lists modifiers that can be assigned to parentheses.
Modifier Function Example
N Negation AND(N or OR(N
F Falling edge AND(F or OR(F
R Rising edge AND(R or OR(R
[ Comparison See Comparison Instructions, p. 236
LD %I0.1
%I0.1 %I0.2 %I0.3 %I0.4 %Q0.0
AND( %I0.2
AND %I0.3
OR( %I0.5
%I0.5 %I0.6
AND %I0.6
)
%I0.7 %I0.8 AND %I0.4
OR( %I0.7
AND %I0.8
)
)
ST %Q0.0
Introduction The Stack instructions process routing to coils.The MPS, MRD, and MPP
instructions use a temporary storage area called the stack which can store up to
eight Boolean expressions.
Operation of The following table describes the operation of the three stack instructions.
Stack
Instruction Description Function
Instructions
MPS Memory Push onto stack Stores the result of the last logical instruction
(contents of the accumulator) onto the top of
stack (a push) and shifts the other values to the
bottom of the stack.
MRD Memory Read from stack Reads the top of stack into the accumulator.
MPP Memory Pop from stack Copies the value at the top of stack into the
accumulator (a pop) and shifts the other values
towards the top of the stack.
11
At a Glance
Grafcet The following table lists all instructions and objects required to program a Grafcet
Instructions chart:
Graphic Transcription in Role
representation (1) TwidoSoft Language
-*-2 -*- 2
2
%I0.2 3 LD %I0.2
%I0.2 # 3
#
-*-4
4
%I0.3 5 -*- 4
%I0.3 %I0.4 LD %I0.3
#
# 5
%I0.4 6 LD %I0.4
# 6
5 6 #
-*- 5
%I0.5 %I0.6 -*-5
LD %I0.5
%I0.5 7 # 7
#
7 -*- 6
-*-6 LD %I0.6
%I0.6 7 # 7
#
Simultaneous sequences:
8 -*-8
-*- 8
%I0.7 %I0.7 9 LD %I0.7
# # 9
# 10
10
9 10
# -*- 9
%I0.8 %I0.9 -*-9
LD %I0.8
%I0.8 11 # 11
11 12 #
-*- 10
%M0 - * - 10 LD %I0.9
# 12
%I0.9 12
# -*- 11
13 LD %M0
- * - 11 AND %X12
#D 12
%M0 %X12 12
# 13
#D
13 -*- 12
LD %M0
# AND %X11
- * - 12 #D 11
%M0 %X11 11 # 13
#D
13
#
Note: For a Grafcet Chart to be operational, at least one active step must be
declared using the =*=i instruction (initial step) or the chart should be pre-
positioned during preprocessing using system bit %S23 and the instruction S %Xi.
%I0.6 %S21
P S
Preprocessing begins with the first line of the program and ends with the first
occurrence of a "= * =" or "- * -" instruction.
Three system bits are dedicated to Grafcet control: %S21, %S22, and %S23. Each
of these system bits are set to 1 (if needed) by the application, normally in
preprocessing. The associated function is performed by the system at the end of
preprocessing and the system bit is then reset to 0 by the system.
System Bit Name Description
%S21 Grafcet All active steps are deactivated and the initial steps are activated.
Initialization
%S22 Reset Grafcet All steps are deactivated.
%S23 Grafcet Pre- This bit must be set to 1 if %Xi are explicitly written by the
positioning application in preprocessing. If this bit is maintained to 1 by the
preprocessing without any explicit change of the %Xi objects,
Grafcet is frozen (no updates are taken into account).
Sequential Sequential processing takes place in the chart (instructions representing the chart):
Processing l Steps
l Actions associated with steps
l Transitions
l Transition conditions
Example:
=*= 1
005 =*= 1
%I0.2 %I0.3 2 006 LD %I0.2
/ # 007 ANDN %I0.3
008 # 2
%I0.3 %I0.2 3
009 LD %I0.3
/ # 010 ANDN %I0.2
011 # 3
-*- 2 012 -*- 2
013 LD %I0.4
%I0.4 1 014 # 1
015 -*- 3
# 016 LD %I0.5
017 # 1
-*- 3
%I0.5 1
#
Sequential processing ends with the execution of the "= * = POST" instruction or with
the end of the program.
Introduction A TwidoSoft Grafcet program offers two ways to program the actions associated
with steps:
l In the post-processing section
l Within List instructions or Ladder rungs of the steps themselves
Associating If there are security or running mode constraints, it is preferable to program actions
Actions in Post- in the post-processing section of a Grafcet application. You can use Set and Reset
Processing List instructions or energize coils in a Ladder program to activate Grafcet steps
(%Xi).
Example:
%X1 %Q0.1 018 =*= POST
019 LD %X1
020 ST %Q0.1
%X2 %Q0.2 021 LD %X2
022 ST %Q0.2
023 LD %X3
%X2 %Q0.3
024 ST %Q0.3
Associating You can program the actions associated with steps within List instructions or Ladder
Actions from an rungs. In this case, the List instruction or Ladder rung is not scanned unless the step
Application is active. This is the most efficient, readable, and maintainable way to use Grafcet.
Example:
-*- 3
%Q0.5 020 -*- 3
021 LD 1
S 022 S %Q0.5
023 LD %M10
4 024 # 4
# 025 -*- 4
026 LD 1
027 R %Q0.5
-*- 4 028 ...
%Q0.5 029 ...
Overview This part provides detailed descriptions about basic and advanced instructions and
system bits and words for Twido languages.
12
At a Glance
Overview This chapter provides details about instructions and function blocks that are used to
create basic control programs for Twido controllers.
Boolean Instructions
The Boolean result of the test elements is applied to the action elements as shown
by the following instructions.
LD %I0.0
AND %I0.1
ST %Q0.0
Testing Boolean test instructions can be used to detect rising or falling edges on the
Controller Inputs controller inputs. An edge is detected when the state of an input has changed
between "scan n-1" and the current "scan n", and it remains detected during the
current scan.
Rising Edge The LDR instruction (Load Rising Edge) is equivalent to a rising edge detection
Detection contact. The rising edge detects a change of the controlling inputs from 0 to 1.
A positive transition sensing contact is used to detect a rising edge as seen in the
following diagram.
%I0.0
LDR %I0.0 P P: Positive transition sensing contact
Falling Edge The LDF instruction (Load Falling Edge) is equivalent to a falling edge detection
Detection contact. The falling edge detects a change of the controlling input from 1 to 0.
A negative transition sensing contact is used to detect a falling edge as seen in the
following diagram.
%I0.0
LDF %I0.0 N N: Negative transition sensing contact
Edge Detection The following table summarizes the instructions and timing for the Boolean
Timing instructions used to test for rising and falling edges.
Edge Test Ladder Timing
Instruction Diagram
Rising edge LDR %I0.0
Rising edge
%I0.0
P %I0.2 time
Boolean 1 controller
result scan time
Falling edge
%I0.0
%I0.2 time
N
Boolean
result 1 controller
scan time
Using Internal Instructions on a rising or falling edge apply to inputs %I, but it is possible to detect
Bits for Edge edges on any other bit (or Boolean result) using two internal bits.
Detection In the following example, bit %M11 records the rising edge of bit %M0.
Note: On a cold or warm restart, the application detects a rising edge even if the
input has remained at 1. This can be masked by starting the program on LD %S1
and ENDC instructions.
Note: Directly detecting rising and falling edges can only be done using input bits
(%Ii).
Introduction Each Boolean instruction in this section is described using the following information:
l Brief description
l Example of the instruction and the corresponding ladder diagram
l List of permitted operands
l Timing diagram
The following explanations provide more detail on how Boolean instructions are
described in this section.
Examples The following illustration shows how examples are given for each instruction.
%I0.1 %Q0.3
LD %I0.1
ST %Q0.3
%M0 %Q0.2 LDN %M0
ST %Q0.2
%I0.1 %Q0.4
P
LDR %I0.1
ST %Q0.4
%I0.3 %Q0.5
N
LDF %I0.3
ST %Q0.5
Permitted The following table defines the types of permitted operands used for Boolean
Operands instructions.
Operand Description
0/1 Immediate value of 0 or 1
%I Controller input %Ii.j
%Q Controller output %Qi.j
%M Internal bit %Mi
%S System bit %Si
%X Step bit %Xi
%BLK.x Function block bit (for example, %TMi.Q)
%•:Xk Word bit (for example, %MWi:Xk)
[ Comparison expression (for example, [%MWi<1000])
Timing Diagrams The following illustration shows how timing diagrams are displayed for each
instruction.
LD
Introduction Load instructions LD, LDN, LDR, and LDF correspond respectively to the opened,
closed, rising edge, and falling edge contacts (LDR and LDF are used only with
controller inputs).
Permitted The following table lists the types of load instructions with Ladder equivalents and
Operands permitted operands.
List Instruction Ladder Equivalent Permitted Operands
LD 0/1,%I,%Q,%M,%S,%X,%BLK.x,%•:Xk,[
LDN %I,%Q,%M,%S,%X,%BLK.x,%•:Xk,[
LDR %I
P
LDF %I
N
Timing Diagram The following diagram displays the timing for the Load instructions.
Introduction The Store instructions ST, STN, S, and R correspond respectively to the direct,
inverse, set, and reset coils.
%I0.1 %Q0.3
LD %I0.1
ST %Q0.3
%Q0.2
STN %Q0.2
/
S %Q0.4
%Q0.4
S LD %I0.2
R %Q0.4
%I0.2 %Q0.4
R
Permitted The following table lists the types of Store instructions with Ladder equivalents and
Operands permitted operands.
List Instruction Ladder Equivalent Permitted Operands
ST %Q,%M,%S,%BLK.x,%•:Xk
STN %Q,%M,%S,%BLK.x,%•:Xk
S %Q,%M,%S,%X,%BLK.x,%•:Xk
S
R %Q,%M,%S,%X,%BLK.x,%•:Xk
R
Timing Diagram The following diagram displays the timing for the Store instructions.
ST STN S R
Introduction The AND instructions perform a logical AND operation between the operand (or its
inverse, or its rising or falling edge) and the Boolean result of the preceding
instruction.
LD %I0.1
%I0.1 %M1 %Q0.3
AND %M1
ST %Q0.3
%M2 %I0.2 %Q0.2 LD %M2
ANDN %I0.2
ST %Q0.2
%I0.3 %I0.4 %Q0.4 LD %I0.3
P S ANDR %I0.4
S %Q0.4
%M3 %I0.5 %Q0.5 LD %M3
N S ANDF %I0.5
S %Q0.5
Permitted The following table lists the types of AND instructions with ladder equivalents and
Operands permitted operands.
List Instruction Ladder Equivalent Permitted Operands
AND 0/1,%I,%Q,%M,%S,%X,%BLK.x,%•:Xk, [
ANDN %I,%Q,%M,%S,%X,%BLK.x,%•:Xk, [
ANDR %I
P
ANDF %I
N
Timing Diagram The following diagram displays the timing for the AND instructions.
Introduction The OR instructions perform a logical OR operation between the operand (or its
inverse, or its rising or falling edge) and the Boolean result of the preceding
instruction.
%I0.1 %Q0.3
LD %I0.1
OR %M1
%M1
ST %Q0.3
%M2 %Q0.2
LD %M2
ORN %I0.2
%I0.2
ST %Q0.2
%M3 %Q0.4
S LD %M3
%I0.4
ORR %I0.4
P
S %Q0.4
%I0.5 %Q0.5
N S LDF %I0.5
%I0.6 ORF %I0.6
N S %Q0.5
Permitted The following table lists the types of OR instructions with Ladder equivalents and
Operands permitted operands.
List Instruction Ladder Equivalent Permitted Operands
OR 0/1,%I,%Q,%M,%S,%X,%BLK.x,%•:Xk
ORN %I,%Q,%M,%S,%X,%BLK.x,%•:Xk
ORR %I
ORF %I
Timing Diagram The following diagram displays the timing for the OR instructions.
Introduction The XOR instructions perform an exclusive OR operation between the operand (or
its inverse, or its rising or falling edge) and the Boolean result of the preceding
instruction.
Examples The XOR instructions can be used as shown in the following examples.
Permitted The following table lists the types of XOR instructions and permitted operands.
Operands
Instruction list Permitted Operands
XOR %I,%Q,%M,%S,%X,%BLK.x,%•:Xk
XORN %I,%Q,%M,%S,%X,%BLK.x,%•:Xk
XORR %I
XORF %I
Timing Diagram The following diagram displays the timing for the XOR instructions.
XOR
%I0.1
%M1
%Q0.3
Special Cases The following are special precautions for using XOR instructions in Ladder
programs:
l Do not insert XOR contacts in the first position of a rung.
l Do not insert XOR contacts in parallel with other ladder elements (see the
following example.)
As shown in the following example, inserting an element in parallel with the XOR
contact will generate a validation error.
%M10
Introduction The NOT (N) instruction negates the Boolean result of the preceding instruction.
LD %I0.1
OR %M2
ST %Q0.2
N
AND %M3
ST %Q0.3
Timing Diagram The following diagram displays the timing for the NOT instruction.
NOT
%I0.1
%M2
%Q0.2
%M3
%Q0.3
At a Glance
Overview This section provides descriptions and programming guidelines for using basic
function blocks.
Introduction Function blocks are the sources for bit objects and specific words that are used by
programs. Basic function blocks provide simple functions such as timers or up/down
counting.
S D
ADJ Y
%Ci.P 9999
CU
CD F
Bit Objects Bit objects correspond to the block outputs. These bits can be accessed by Boolean
test instructions using either of the following methods:
l Directly (for example, LD E) if they are wired to the block in reversible
programming (see Principles for Programming Basic Function Blocks, p. 208).
l By specifying the block type (for example, LD %Ci.E).
Inputs can be accessed in the form of instructions.
Word Objects Word objects correspond to specified parameters and values as follows:
l Block configuration parameters: Some parameters are accessible by the
program (for example, pre-selection parameters) and some are inaccessible by
the program (for example, time base).
l Current values: For example, %Ci.V, the current count value.
Accessible Bit The following table describes the Basic function blocks bit and word objects that can
and Word be accessed by the program.
Objects
Basic Symbol Range (i) Types of Description Address Write
Function Objects Access
Block
Timer %TMi 0 - 127 Word Current value %TMi.V no
Preset value %TMi.P yes
Bit Timer output %TMi.Q no
Up/Down %Ci 0 - 31 Word Current value %Ci.V no
counter Preset value %Ci.P yes
Bit Underflow output %Ci.E no
(empty)
Preset output reached %Ci.D no
Overflow output (full) %Ci.F no
Introduction Use one of the following methods to program basic function blocks:
l Function block instructions (for example, BLK %TM2): This reversible method of
programming ladder language enables operations to be performed on the block
in a single place in the program.
l Specific instructions (for example, CU %Ci): This non-reversible method enables
operations to be performed on the block’s inputs in several places in the program
(for example, line 100 CU %C1, line 174 CD %C1, line 209 LD %C1.D).
Reversible Use instructions BLK, OUT_BLK, and END_BLK for reversible programming:
Programming l BLK: Indicates the beginning of the block.
l OUT_BLK: Is used to directly wire the block outputs.
l END_BLK: Indicates the end of the block.
Example with The following example shows reversible programming of a counter function block
Wired Outputs with wired outputs.
%I1.1
N R %C8 E BLK %C8
LDF %I1.1
S %M1 %Q0.4 R Input
%I1.2 %M0 ADJ Y D LD %I1.2 Processing
CU %Ci.P 9999 AND %M0
CU
OUT_BLK
CD F
LD D
Output
AND %M1
Processing
ST %Q0.4
END_BLK
Example without This example shows reversible programming of a counter function block without
Output Wiring wired outputs.
%I1.1
N R %C8 E BLK %C8
LDF %I1.1
S R Input
%I1.2 %M0 ADJ Y D LD %I1.2 Processing
%Ci.P 9999 AND %M0
CU
CU
END_BLK
CD F
LD %C8.D
AND %M1 Output
ST %Q0.4 Processing
%C8.D %M1 %Q0.4
Note: Only test and input instructions on the relevant block can be placed between
the BLK and OUT_BLK instructions (or between BLK and END_BLK when
OUT_BLK is not programmed).
%TMi
IN Q
TYPE TON
TB 1min
ADJ Y
%TMi.P 9999
Note: The larger the preset value, the greater the timer accuracy.
Introduction Use the TOF (Timer Off-Delay) type of timer to control off-delay actions. This delay
is programmable using TwidoSoft.
Timing Diagram The following timing diagram illustrates the operation of the TOF type timer.
(1) (1)
(3)
IN
(2)
(5)
Q
%TMi.P
(4)
%TMi.V
Operation The following table describes the operation of the TOF type timer.
Phase Description
1 The current value %TMi.V is set to 0 on a rising edge at input IN, even if the timer
is running.
2 The %TMi.Q output bit is set to 1 when a rising edge is detected at input N.
3 The timer starts on the falling edge of input IN.
4 The current value %TMi.V increases to %TMi.P in increments of one unit for
each pulse of the time base TB.
5 The %TMi.Q output bit is reset to 0 when the current value reaches %TMi.P.
Introduction The TON (Timer On-Delay) type of timer is used to control on-delay actions. This
delay is programmable using the TwidoSoft.
Timing Diagram The following timing diagram illustrates the operation of the TON type timer.
(1)
IN
(3) (5)
Q
%TMi.P (4)
(2)
%TMi.V
Operation The following table describes the operation of the TON type timer.
Phase Description
1 The timer starts on the rising edge of the IN input.
2 The current value %TMi.V increases from 0 to %TMi.P in increments of one unit
for each pulse of the time base TB.
3 The %TMi.Q output bit is set to 1 when the current value has reached %TMi.P.
4 The %TMi.Q output bit remains at 1 while the IN input is at 1.
5 When a falling edge is detected at the IN input, the timer is stopped, even if the
timer has not reached %TMi.P, and %TMi.V is set to 0.
TP Type of Timer
Introduction The TP (Timer - Pulse) type of timer is used to create pulses of a precise duration.
This delay is programmable using the TwidoSoft.
Timing Diagram The following timing diagram illustrates the operation of the TP type timer.
(1)
IN
(2) (6)
(4)
Q
%TMi.P
(3) (5)
%TMi.V
Operation The following table describes the operation of the TP type timer.
Phase Description
1 The timer starts on the rising edge of the IN input. The current value %TMi.V is
set to 0 if the timer has not already started.
2 The %TMi.Q output bit is set to 1 when the timer starts.
3 The current value %TMi.V of the timer increases from 0 to %TMi.P in increments
of one unit per each pulse of the time base TB.
4 The %TMi.Q output bit is set to 0 when the current value reaches %TMi.P.
5 The current value %TMi.V is set to 0 when %TMi.V equals %TMi.P and input IN
returns to 0.
6 This timer cannot be reset. Once %TMi.V equals %TMi.P, and input IN is 0, then
%TMi.V is set to 0.
Introduction Timer function blocks (%TMi) are programmed in the same way regardless of how
they are to be used. The timer function (TON, TOF, or TP) is selected during
configuration.
Examples The following illustration is a timer function block with examples of reversible and
non-reversible programming.
TYPE TON
TB 1min
ADJ Y
%TMi.P 9999
Special Cases The following table contains a list of special cases of programming and configuring
timers.
Special Case Description
Effect of a cold restart (%S0=1) Forces the current value to 0. Sets output %TMi.Q to
0. The preset value is reset to the value defined
during configuration.
Effect of a warm restart (%S1=1) Has no effect on the current and preset values of the
timer. The current value does not change during a
power outage.
Effect of a controller stop Stopping the controller does not freeze the current
value.
Effect of a program jump Jumping over the timer block does not freeze the
timer. The timer will continue to increment until it
reaches the preset value (%TMi.P). At that point, the
Done bit (%TMi.Q) assigned to output Q of the timer
block changes state; however, the associated output
wired directly to the block output is not activated and
not scanned by the controller.
Testing by bit %TMi.Q (done bit) It is advisable to test bit %TMi.Q only once in the
program.
Effect of modifying the preset %TMi.P Modifying the present value by using an instruction or
by adjusting the value only takes effect on the next
activation of the timer.
Timers with a The 1 ms time base is only available on %TM0 and %TM1 timers. The four system
1ms Time Base words %SW76, %SW77, %SW78, and SW79, can be used as "hourglasses." These
four words are decremented individually by the system every millisecond if they
have a positive value.
Multiple timing can be achieved by successive loading of one of these words or by
testing the intermediate values. If the value of one of these four words is less than
0, it will not be modified. A timer can be "frozen" by setting the corresponding bit 15
to 1, and then "unfrozen" by resetting it to 0.
%I0.1
P %SW76:=XXXX
%I0.2 %SW76:X15
%M0
%SW76=0
Introduction The Counter function block (%Ci) provides up and down counting of events. These
two operations can be done simultaneously.
%Ci
R E
S D
ADJ Y
%TMi.P 9999
CU
CD F
Operation The following table describes the main stages of up/down counter operation.
Operation Action Result
Upcount A rising edge appears at the The %Ci.V current value is
upcounting input CU (or incremented by one unit.
instruction CU is activated).
The %Ci.V current value is equal The "preset reached" output bit %Ci.D
to the %Ci.P preset value. assigned to output D changes to state
1.
The %Ci.V current value The output bit %Ci.F (Upcount
changes from 9999 to 0. overflow) changes to state 1.
If the counter continues to count The output bit %Ci.F (Upcount
up. overflow) is reset to 0.
Downcount A rising edge appears at the The current value %Ci.V is
downcounting input CD (or decremented by one unit.
instruction CD is activated).
The current value %Ci.V The output bit %Ci.E (underflow)
changes from 0 to 9999. changes to state 1.
If the counter continues to count The output bit %Ci.E (underflow) is
down. reset to 0.
Up/down count To use both the upcount and downcount functions simultaneously (or to
activate both instructions CD and CU), the two corresponding inputs CU
and CD must be controlled. These two inputs are then scanned in
succession, If they are both at 1, the current value remains unchanged.
Reset Input R is set to state 1(or the R The current value%Ci.V is forced to 0.
instruction is activated). Outputs %Ci.E, %Ci.D and %Ci.F are
at 0. The reset input has priority.
Set If input S is at state 1 (or the S The current value %Ci.V takes the
instruction is activated) and the %Ci.P value and the %Ci.D output is
reset input is at 0 (or the R set to 1.
instruction is inactive).
Special Cases The following table contains a list of special cases of programming and configuring
counters.
Special Case Description
Effect of a cold restart (%S0=1) l The current value %Ci is set to 0.
l Output bits %Ci.E, %Ci.D, and %Ci.F are set to
0.
l The preset value is initialized with the value
defined during configuration.
Effect of a warm restart (%S1=1) of a Has no effect on the current value of the counter
controller stop (%Ci.V).
Effect of modifying the preset %Ci.P Modifying the preset value via an instruction or by
adjusting it takes effect when the block is
processed by the application (activation of one of
the inputs).
Introduction The following example is a counter that provides a count of items up to 5000. Each
pulse on input %I1.2 (when internal bit %M0 is at 1) increments the counter %C8 up
to its final preset value (bit %C8.D=1). The counter is reset by input %I1.1.
Programming The following illustration is a counter function block with examples of reversible and
Example non-reversible programming.
%I1.1
R %C8 E
S
%I1.2 %M0 ADJ Y D
%Ci.P 9999
CU
CD F
%C8.D %Q0.0
Ladder diagram
Introduction The Shift Bit Register function block (%SBRi) provides a left or right shift of binary
data bits (0 or 1).
%SBRi
R
CU
CD
Parameters The Shift Bit Register function block has the following parameters.
Parameter Label Value
Register number %SBRi 0 to 7
Register bit %SBRi.j Bits 0 to 15 (j = 0 to 15) of the shift register can be
tested by a Test instruction and written using an
Assignment instruction.
Reset input (or R On a rising edge, sets register bits 0 to 15 %SBRi.j to
instruction) 0.
Shift to left input (or CU On a rising edge, shifts a register bit to the left.
instruction)
Shift to right input (or CD On a rising edge, shifts a register bit to the right.
instruction)
Operation The following illustration shows a bit pattern before and after a shift operation.
Operation
Initial state 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0 0
Bit 15 Bit 0
CU %SBRi performs a
shift to the left
Bit 15 is lost 1 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0
Bit 15 Bit 0
This is also true of a request to shift a bit to the right (Bit 15 to Bit 0) using the CD
instruction. Bit 0 is lost.
If a 16-bit register is not adequate, it is possible to use the program to cascade
several registers.
Programming In the following example, a bit is shifted to the left every second while Bit 0 assumes
the opposite state to Bit 15.
Reversible
programming
%SBR0.15 %SBR0.0
LDN %SBR0.15
/
ST %SBR0.0
BLK %SBR0
LD %S6
CU
%SBR0 END_BLK
R
%S6 Non-Reversible
CU programming
LDN %SBR0.15
CD ST %SBR0.0
LD %S6
CU %SBR0
Special Cases The following table contains a list of special cases for programming the Shift Bit
Register function block.
Special Case Description
Effect of a cold restart (%S0=1) Sets all the bits of the register word to 0.
Effect of a warm restart (%S1=1) Has no effect on the bits of the register word.
Introduction A Step Counter function block (%SCi) provides a series of steps to which actions
can be assigned. Moving from one step to another depends on external or internal
events. Each time a step is active, the associated bit is set to 1. Only one step of a
step counter can be active at a time.
%SCi
R
CU
CD
Parameters The Step Counter function block has the following parameters.
Parameter Label Value
Step counter number %SCi 0 to 7
Step counter bit %SCi.j Step counter bits 0 to 255 (j = 0 to 255) can be tested
by a Load logical operation and written by an
Assignment instruction.
Reset input (or R On a rising edge, resets the step counter.
instruction)
Increment input (or CU On a rising edge, increments the step counter by one
instruction) step.
Decrement input (or CD On a rising edge, decrements the step counter by one
instruction) step.
Timing Diagram The following diagram illustrates the operation of the Step Counter function block.
CU input
CD input
N inactive 0 1 2 3 2 1 0
BLK %SC0
%SC0.3 LD %SC0.3
OR %I0.3
R
%SC0 LD %I0.2
%I0.3
CU
R END_BLK
LD %SC0.0
%I0.2 ST %Q0.1
CU LD %SC0.1
ST %Q0.2
LD %SC0.2
ST %Q0.3
CD
Non-Reversible
%SC0.0 %Q0.1 programming
LD %SC0.3
OR %I0.3
%SC0.1 %Q0.2 R %SC0
LD %I0.2
CU %SC0
LD %SC0.0
ST %Q0.1
%SC0.2 %Q0.3
LD %SC0.1
ST %Q0.2
LD %SC0.2
ST %Q0.3
Special Cases The following table contains a list of special cases for programming the Step
Counter function block.
Special Case Description
Effect of a cold restart (%S0=1) Initializes the step counter.
Effect of a warm restart (%S1=1) Has no effect on the step counter.
Overview Numerical instructions generally apply to 16-bit words (see Word Objects, p. 27).
They are written between square brackets. If the result of the preceding logical
operation was true (Boolean accumulator = 1), the numerical instruction is executed.
If the result of the preceding logical operation was false (Boolean accumulator = 0),
the numerical instruction is not executed and the operand remains unchanged.
Assignment Instructions
Introduction Assignment instructions are used to load operand Op2 into operand Op1.
Assignment of Operations can be performed on the following bit strings (see Structured Objects,
Bit Strings p. 35):
l Bit string -> bit string (Example 1)
l Bit string -> word (Example 2)
l Word -> bit string (Example 3)
l Immediate value -> bit string
LD 1
%Q0:8:=%MW64:8 [%Q0:8:=%M64:8] (Ex. 1)
%I0.2 LD %I0.2
%MW100:=%I0:16 [%MW100:=%I0:16] (Ex. 2)
Usage rules:
l For bit string -> word assignment: The bits in the string are transferred to the word
starting on the right (first bit in the string to bit 0 in the word), and the word bits
which are not involved in the transfer (length<16) are set to 0.
l For word -> bit string assignment: The word bits are transferred from the right
(word bit 0 to the first bit in the string).
Note: The abbreviation %BLK.x (for example, %C0.P) is used to describe any
function block word.
LD 1
%SW112:=%MW100 [%SW112:=%MW100] (Ex. 1)
%I0.2 LD %I0.2
%MW0[%MW10]:=%KW0[%MW20] [%MW0[%MW10]:=] (Ex. 2)
%KW0[%MW20]
%I0.3
P %MW10:=100 LDR %I0.3 (Ex. 3)
[%MW10:=100]
Note: The abbreviation %BLK.x (for example, R3.I) is used to describe any
function block word. For bit strings %Mi:L, %Si:L, and %Xi:L, the base address of
the first of the bit string must be a multiple of 8 (0, 8, 16, ..., 96, ...).
Assignment of Assignment operations can be performed on the following word tables (see Word
Word Tables Tables, p. 36):
l Immediate value -> word table (Example 1)
l Word -> word table (Example 2)
l Word table -> word table (Example 3)
Table length (L) should be the same for both tables.
LD 1
%MW0:10:=100 [%MW0:10:=100] (Ex. 1)
%I0.2 LD %I0.2
%MW0:10:=%MW11 [%MW0:10:=%MW11] (Ex. 2)
Note: The abbreviation %BLK.x (for example, R3.I) is used to describe any
function block word. For bit strings %Mi:L, %Si:L and %Xi:L, the base address of
the first of the bit string must be a multiple of 8 (0, 8, 16, ..., 96, ...).
Comparison Instructions
Structure The comparison is executed inside square brackets following instructions LD, AND,
and OR. The result is 1 when the comparison requested is true.
Examples of Comparison instructions.
%Q0.3
%MW10>100 LD [%MW10 > 100]
ST %Q0.3
%MW30>=%MW40
Arithmetic Instructions
Introduction Arithmetic instructions are used to perform arithmetic operations between two
operands or on one operand.
The following table lists the types of Arithmetic instructions.
Instruction Function
+ Add two operands
- Subtract two operands
* Multiply two operands
/ Divide two operands
REM Remainder of division of the two operands
SQRT Square root of an operand
INC Increment an operand
DEC Decrement an operand
%M0 LD %M0
%MW0:=%MW10+100 [%MW0:=%MW10 + 100]
%I0.2 LD %I0.2
%MW0:=SQRT(%MW10) [%MW0:=SQRT(%MW10)]
Syntax The syntax depends on the operators used as shown in the table below.
Operator Syntax Operand 1 (Op1) Operands 2 and 3
(Op2 & 3)
+,-,*,/,REM [Op1: = Op 2 Operator Op3] %MWi, %QWi, Immed.value (2),
SQRT (1) [Op1: = SQRT(Op2)] %SWi %MWi, %KWi, %INW,
%IW, %QNW, %QW,
INC, DEC [Operator Op1]
%SWi, %BLK.x
Note: The user program is responsible for managing system bits %S17 and %S18.
These are set to 1 by the controller and must be reset by the program so that they
can be reused (see previous page for example).
%S18
LDN %S18
/ %MW10:=%MW0 [%MW10:=%MW0]
%S18
LD %S18
%MW10:=32767 [%MW10:=32767]
R %S18
%S18
R
If %MW1 =23241 and %MW2=21853, the real result (45094) cannot be expressed
in one 16-bit word, bit %S18 is set to 1 and the result obtained (-20442) is incorrect.
In this example when the result is greater than 32767, its value is fixed at 32767.
Example 2: [%MW2:=%MW0 + %MW1] where %MW0 =65086, %MW1=65333
Word %MW2 contains the number 64883. Bit %S17 is set to 1 and represents the
value 65536. The unsigned arithmetic result is then equal to: 65536 + 64883 =
130419.
Example 3: [%MW2:=%MW0 + %MW1] where %MW0 =45736 (that is, a signed
value of -19800), %MW1=38336 (that is, a signed value of 27200). The two system
bits %S17 and %S18 are set to 1. The signed arithmetic result (+18536) is incorrect.
In unsigned arithmetic, the result (18536 + the value of %S17, which is 84072) is
correct.
Logic Instructions
Introduction The Logic instructions are used to perform a logical operation between two word
operands or on one word operand.
The following table lists the types of Logic instructions.
Instruction Function
AND AND (bit-wise) between two operands
OR Logic OR (bit-wise) between two operands
XOR Exclusive OR (bit-wise) between two operands
NOT Logic complement (bit-wise) of an operand
%M0 LD %M0
%MW0:=%MW10 AND 16#FF00 [%MW0:=%MW10 AND 16#FF00]
LD 1
%MW0:=%KW5 OR %MW10
[%MW0:=%KW5 OR %MW10]
%I0.3
%MW102:=NOT (%MW100) LD %I0.3
[%MW102:=NOT(%MW100)]
Shift Instructions
Introduction Shift instructions move bits of an operand a certain number of positions to the right
or to the left.
The following table lists the types of Shift instructions.
Instruction Function
Logic shift
SHL(op2,i) logic shift of i positions to F 0
the left.
%S17
SHR(op2,i) logic shift of i positions to F 0
the right.
%S17
Rotate shift
ROL(op2,i) rotate shift of i positions
to the left.
F 0
%S17
ROR(op2,i) rotate shift of i positions
F 0
to the right.
%S17
%I0.1
LDR %I0.1
P %MW0:=SHL(%MW10.5)
[%MW0 :=SHL(%MW10.5)]
Syntax The syntax depends on the operators used as shown in the table below.
Operator Syntax Operand 1 (Op1) Operand 2 (Op2)
SHL, SHR [Op1: = Operator (Op2,i)] %MWi, %QWi, %MWi, %KWi, %IW,
ROL, ROR %SWi %QW, %SWi,
%BLK.x
Conversion Instructions
Review of BCD Binary Coded Decimal (BCD) represents a decimal digit (0 to 9) by coding four
Code binary bits. A 16-bit word object can thus contain a number expressed in four digits
(0000 - 9999).
During a conversion, if the value is not BCD, the system bit %S18 is set to 1. This
bit must be tested and reset to 0 by the program.
BCD representation of decimal numbers:
Decimal 0 1 2 3 4 5 6 7 8 9
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Examples:
l Word %MW5 expresses the BCD value "2450" which corresponds to the binary
value: 0010 0100 0101 0000
l Word %MW12 expresses the decimal value "2450" which corresponds to the
binary value: 0000 1001 1001 0010
Word %MW5 is converted to word %MW12 by using instruction BTI.
Word %MW12 is converted to word %MW5 by using instruction ITB.
%M0
LD %M0
%MW0:=BTI(%MW10)
[%MW0 :=BTI(%MW10)]
%I0.2 LD %I0.2
%MW10:=ITB(%KW9) [%MW10 :=ITB(%KW9)]
Syntax The syntax depends on the operators used as shown in the table below.
Operator Syntax Operand 1 (Op1) Operand 2 (Op2)
BTI, ITB [Op1: = Operator (Op2,i)] %MWi, %QWi, %MWi, %KWi, %IW,
%SWi %QW, %SWi,
%BLK.x
Application The BTI instruction is used to process a setpoint value at controller inputs via BCD
Examples encoded thumb wheels.
The ITB instruction is used to display numerical values (for example, the result of a
calculation, the current value of a function block) on BCD coded displays.
END Instructions
Introduction The End instructions define the end of the execution of a program scan.
...................
END END
...................
%I0.2
LD %I0.2
END ENDC If %I0.2 = 1, end of
LD %M2 program scanning
ST %Q0.2
%M2 %Q0.2
If %I0.2 = 0, continues
program scanning
................... until new END instruc-
tion
END END
NOP Instruction
NOP The NOP instruction does not perform any operation. Use it to "reserve" lines in a
program so that you can insert instructions later without modifying the line numbers.
Jump Instructions
Guidelines l Jump instructions are not permitted between parentheses, and they must not be
placed between the instructions AND(, OR(, and a close parenthesis instruction
")".
l The label can only be placed before a LD, LDN, LDR, LDF or BLK instruction.
l The label number of label %Li must be defined only once in a program.
l The program jump is performed to a line of programming which is downstream or
upstream. When the jump is upstream, attention must be paid to the program
scan time. Extended scan time can cause the watchdog timer to expire.
Subroutine Instructions
Introduction The Subroutine instructions cause a program to perform a subroutine and then
return to the main program.
011 SR8:
012 LD 1
013 IN %TM0
014 LD [%TM0.Q]
015 ST %M15
010 RET
%Q0.0 LD %I0.0
ST %Q0.0
SR0
13
At a Glance
Overview This chapter provides details about instructions and function blocks that are used to
create advanced control programs for Twido programmable controllers.
At a Glance
Introduction Advanced function blocks use similar types of dedicated words and bits as the basic
function blocks, but require more programming experience than basic function
blocks. Advanced function blocks include:
l LIFO/FIFO Registers (%R)
l Drum controllers (%DR)
l Fast counters (%FC
l Very fast counters (%VFC)
l Pulse width modulation output (%PWM)
l Pulse generator output (%PLS)
l Shift bit register (%SBR)
l Shift counter (%SC)
l Message control block (%MSG)
Objects The table below contains an overview of the words and bits associated with the
Accessible by various advanced function blocks. Please note that write access in the table below
the Program depends on the "Adjustable" setting selected during configuration. Setting this
allows or denies access to the words or bits by TwidoSoft or the operator interface.
Advanced Associated Words and Bits Address Write
Function Block Access
%R Word Access to register %Ri.I Yes
Word Register output %Ri.O Yes
Bit Register output full %Ri.F No
Bit Register output empty %Ri.E No
%DR Word Current step number %DRi.S Yes
Bit Last step equals current step %DRi.F Yes
%FC Word Current Value %FCi.V No
Word Preset Value %FCi.P Yes
Bit Done %FCi.D No
%VFC Word Current Value %VFCi.V No
Word Preset Value %VFCi.P Yes
Bit Count Direction %VFCi.U NO
Word Catch Value %VFCi.C No
Word Threshold 0 Value %VFCi.SO Yes
Word Threshold 0 Value %VFCi.S1 Yes
Bit Overflow %VFCi.F No
Bit Frequency done %VFCi.M Yes
Bit Reflex Output 0 Enable %VFCi.R Yes
Bit Reflex Output 1 Enable %VFCi.S Yes
Bit Threshold Output 0 %VFCi.TH0 No
Bit Freq. Measure Time Base %VFCi.T Yes
%PWM Word Percentage of pulse at 1 in %PWMi.R Yes
relationship to the total period.
Word Preset period %PWMi.P Yes
%PLS Word Number of Pulses %PLSi.N Yes
Word Preset value %PLSi.P Yes
Bit Current output enabled %PLSi.Q No
Bit Generation done %PLSi.D No
%SBR Bit Register Bit %SBRi.J No
%SC Bit Step counter Bit %SCi.J Yes
Overview All Twido applications are stored in the form of List programs, even if written in the
Ladder Editor, and therefore, Twido controllers can be called List "machines." The
term "irreversibility" refers to the ability of TwidoSoft to represent a List application
as Ladder and then back again. By default, all Ladder programs are reversible.
As with basic function blocks, advanced function blocks must also take into
consideration reversibility rules. The structure of reversible function blocks in List
language requires the use of the following instructions:
l BLK: Marks the block start and the input portion of the function block
l OUT_BLK: Marks the beginning of the output portion of the function block
l END_BLK: Marks the end of the function block
Note: The use of these reversible function block instructions is not mandatory for
a properly functioning List program. For some instructions it is possible to program
in List language without being reversible.
Dedicated Inputs The Fast Counter, Very Fast Counter, PLS, and PWM advanced functions use
and Outputs dedicated inputs and outputs, but these bits are not reserved for exclusive use by
any single block. Rather, the use of these dedicated resources must be managed.
When using these advanced functions, you must manage how the dedicated inputs
and outputs are allocated. TwidoSoft assists in configuring these resources by
displaying input/output configuration details and warning if a dedicated input or
output is already used by a configured function block (see the TwidoSoft Operation
Guide).
The following tables summarizes the dependencies of dedicated inputs and outputs
and specific functions.
When used with counting functions:
Inputs Use
%I0.0.0 %VFC0: Up/Down management or Phase B
%I0.0.1 %VFC0: Pulse input or Phase A
%I0.0.2 %FC0: Pulse input or %VFC0 pre-set input
%I0.0.3 %FC1: Pulse input or %VFC0 capture input
%I0.0.4 %FC2: Pulse input or %VFC1 capture input
%I0.0.5 %VFC1 pre-set input
%I0.0.6 %VFC1: Up/Down management or Phase B
%I0.0.7 %VFC1: Pulse input or Phase A
Using Dedicated TwidoSoft enforces the following rules for using dedicated inputs and outputs.
Inputs and l Each function block that uses dedicated I/O must be configured and then
Outputs referenced in the application. The dedicated I/O is only allocated when a function
block is configured and not when it is referenced in a program.
l After a function block is configured, its dedicated input and output cannot be used
by the application or by another function block.
For example, if you configure %PLS0, you can not use %Q0.0.0 in %DR0 (drum
controller) or in the application logic (that is, ST %Q0.0.0).
l If a dedicated input or output is needed by a function block that is already in use
by the application or another function block, this function block cannot be
configured.
For example, if you configure %FC0 as an up counter, you can not configure
%VFC0 to use %I0.0.2 as capture input.
Note: To change the use of dedicated I/O, unconfigure the function block by setting
the type of the object to "not used," and then remove references to the function
block in your application.
Introduction A register is a memory block which can store up to 16 words of 16 bits each in two
different ways:
l Queue (First In, First Out) known as FIFO
l Stack (Last In, First Out) know as LIFO
%Ri
R E
I F
TYPE FIFO
LIFO Operation
Introduction In LIFO operation (Last In, First Out), the last data item entered is the first to be
retrieved.
FIFO Operation
Introduction In FIFO operation (First In, First Out), the first data item entered is the first to be
retrieved.
Introduction The following programming example shows a memory word (%MW34) being loaded
into a register (%R2.I) at the storage request %I0.2, if register %R2 is not full (%R2.F
= 0). The storage request in the register is made by %M1. The retrieval request is
made by input %I0.3, and %R2.O is loaded into %MW20, if the register is not empty
(%R2.E = 0).
1. A storage request in the register is made by %M1.
2. A memory word (%MW34) is loaded into a register (%R2.I) A storage request at
%I0.2, if register %R2 is not full (%R2.F = 0).
3. A storage request at %I0.2, if register %R2 is not full (%R2.F = 0).
Programming The following illustration is a register function block with examples of reversible and
Example non-reversible programming.
R %R2 E
%M1
I F
%I0.3 %R2.E
%MW20:=%R2.0
%I0.2 %R2.F
%R2.1:=%MW34
%M1
Ladder diagram
Configuration The only parameter that must be entered during configuration is the type of register:
l FIFO (default), or
l LIFO
Special Cases The following table contains a list of special cases of programming and configuring
registers.
Special Case Description
Effect of a cold restart (%S0=1) Initializes the contents of the register. The output
bit %Ri.E associated with the output E is set to 1.
Effect of a warm restart (%S1=1) of a Has no effect on the current value of the register,
controller stop nor on the state of its output bits.
Introduction The Pulse Width Modulation (%PWM) function block generates a square wave
signal on dedicated output channels %Q0.0.0 or %Q0.0.1. The %PWM allows you
to vary the signal width, or duty cycle. Controllers with relay outputs for these two
channels do not support this function due to a frequency limitation.
There are two %PWM blocks available. %PWM0 uses dedicated output %Q0.0.0
and %PMW1 uses dedicated output %Q0.0.1. The %PLS function blocks contend
to use these same dedicated outputs so you must choose between the two
functions.
%PWM0
IN
programmable width
Tp
TB
%PWMi.P
fixed period which is
configurable
T
Parameters The following table lists parameters for the PWM function block.
Parameter Label Description
Time base TB 0.1ms1, 10ms, 1s (default value)
Preset period %PWMi.P 0 < %PWMi.P <= 32767 with time base 10ms or 1sec
0 < %PWMi.P <= 255 with time base 0.57 ms or 0.142 ms
0 = Function not in use
Pulse ratio %PWMi.R This value gives the percentage of the signal in state 1 in
(Duty cycle) a period. The width Tp is thus equal to:
Tp = T * (%PWMi.R/100). The user application writes the
value for %PWMi.R. It is this word which controls the width
modulation. For T definition, see "range of periods" below.
The default value is 0 and values greater than 100 are
considered to be equal to 100.
Pulse IN At state 1, the pulse width modulation signal is generated
generation input at the output channel. At state 0, the output channel is set
to 0.
Note:
1. This time base is not advisable for Twido controllers with relay outputs.
Range of Periods The preset value and the time base can be modified during configuration. They are
used to fix the signal period T=%PWMi.P * TB. The lower the ratios to be obtained,
the greater the selected %PWMi.P must be. The range of periods available:
l 0.142 ms to 36.5 ms in steps of 0.142 ms (27.4Hz to 7kHz)
l 0.57 ms to 146 ms in steps of 0.57 ms (6.84Hz to 1.75kHz)
l 20 ms to 5.45 min in steps of 10 ms
l 2 sec to 9.1 hours in steps of 1 sec
Operation The frequency of the output signal is set during configuration by selecting the time
base TB and the preset %PWMi.P. Modifying the % PWMi.R ratio in the program
modulates the width of the signal. Below is an illustration of a pulse diagram for the
PWM function block with varying duty cycles.
Pulse diagram for the PWM function block:
Input IN
80%
50%
20%
Ratio
Dedicated Output
Programming In this example, the signal width is modified by the program according to the state
and of controller inputs %I0.0.0 and %I0.0.1.
Configuration If %I0.0.1 and %I0.0.2 are set to 0, the %PWM0.R ratio is set at 20%, the duration
of the signal at state 1 is then: 20% x 500 ms = 100 ms.
If %I0.0.0 is set to 0 and %I0.0.1 is set to 1, the %PWM0.R ratio is set at 50%
(duration 250 ms).
If %I0.0.0 and %I0.0.1 are set to 1, the %PWM0.R ratio is set at 80% (duration 400
ms).
Programming example:
%I0.0 %I0.1 LDN %I0.0
/ / %PWM0.R:=20 ANDN %I0.1
[%PWM0.R:=20]
%I0.0 %I0.1 LD %I0.0
/ %PWM0.R:=50 ANDN %I0.1
[%PWM0.R:=50]
%I0.0 %I0.1 LD %I0.0
AND %I0.1
%PWM0.R:=80 [%PWM0.R:=80]
BLK %PWM0
%I0.2 %PWM0 LD %I0.2
IN
IN
END_BLK
TB
%PWMi0.P
Special Cases The following table contains a list of special cases for programming the PWM
function block:
Special Case Description
Effect of a cold restart (%S0=1) Sets the %PWMi.R ratio to 0. In addition, the value
for %PWMi.P is reset to the configured value, and
this will supersede any changes made with the
Animations Table Editor or the optional Operator
Display.
Effect of a warm restart (%S1=1) Has no effect.
Using 0.142ms or 0.57ms time base Forcing output %Q0.0.0 or %Q0.0.1 using a
programming device does not stop the signal
generation.
Introduction The %PWM function block is used to generate a square wave signal on a dedicated
output channels %Q0.0.0 or %Q0.0.1. The %PWM allows you to vary the signal
width, or duty cycle. Controller’s with relay outputs for these two channels do not
support this function due to a frequency limitation.
There are two %PWM blocks available. %PWM0 uses dedicated output %Q0.0.0
and %PMW1 uses dedicated output %Q0.0.1. The %PLS function blocks contend
to use these same dedicated outputs so you must choose between the two.
Representation
%PLS0
IN Q
Programmable
TB Tp
%PLSi.P
Characteristics The table below contains the characteristics of the PLS function block:
Function Object Description
Time base TB 0.142 ms, 0.57 ms, 10ms, 1sec
Preset %PLSi.P %PLS1 output does not stop pulsing when %PLS1.N is reached.
period This is only valid for %PLS0.
0 < %PLSi.P <= 32767 with time base 10ms or 1sec0 < %PLSi.P
<= 255 with time base 0.57 ms or 0.142 ms0 = Function not in use
Number of %PLSi.N The number of pulses to be generated in period T can be limited
pulses 0 < %PLSi.N < 32767. The default value is set to 0.
To produce an unlimited number of pulses, set %PLSi.N to zero.
The number of pulses can always be changed irrespective of the
Adjustable setting.
Adjustable Y/N If set to Y, it is possible to modify the preset value %PLSi.P via the
HMI or Animation Tables Editor. Set to N means that there is no
access to the preset.
Pulse IN At state 1, the pulse generation is produced at the dedicated
generation output channel. At state 0, the output channel is set to 0.
input
Reset input R At state 1, resets the number of pulses of outputs %PLSi.Q and
%PLSi.D to zero.
Current %PLSi.Q At state 1, indicates that the pulse signal is generated at the
pulse dedicated output channel configured.
output
generation
Pulse %PLSi.D At state 1, signal generation is complete. The number of desired
generation pulses has been reached.
done output
Range of Periods The preset value and the time base can be modified during configuration. They are
used to fix the signal period T=%PLSi.P * TB. The lower the ratios to be obtained,
the greater the selected %PLSi.P must be. The range of periods available:
l 0.142 ms to 36.5 ms in steps of 0.142 ms (27.4Hz to 7kHz)
l 0.57 ms to 146 ms in steps of 0.57 ms (6.84Hz to 1.75kHz)
l 20 ms to 5.45 min in steps of 10 ms
l 2 sec to 9.1 hours in steps of 1 sec
Operation The following is an illustration of the pulse diagram of the %PLS function block.
Input IN
Number of
Dedicated Output
%PLSi.Q
%PLSi.D
Special Cases
Special case Description
Effect of cold restart (%S0=1) Sets the %PLSi.P to that defined during configuration
Effect of warm restart Has no effect
(%S1=1)
Effect of a controller stop The output %Q0.0.0 or %Q0.0.1 is set to 0 regardless of the
state of system bit %S8.
Effect of modifying the preset Takes effect immediately
(%PLSi.P)
Using 0.142ms or 0.57ms Forcing output %Q0.0.0 or %Q0.0.1 using a programming
Time base device does not stop the signal generation.
%DRi
R F
U
STEPS 8
Parameters The drum controller function block has the following parameters:
Parameter Label Value
Number %DRi 0 to 3 Compact Controller0 to 7 Modular Controllers
Current step number %DRi.S 0-%DRi.S-7. Word which can be read and written.
Written value must be a decimal immediate value.
When written, the effect takes place on the next
execution of the function block.
Number of steps 1 to 8 (default)
Return to step 0 input R (Reset) At state 1, sets the drum controller to step 0.
(or instruction)
Advance input (or U (Up) On a rising edge, causes the drum controller to
instruction) advance by one step and updates the control bits.
Output F (Full) Indicates that the current step equals the last step
defined. The associated bit %DRi.F can be tested
(for example, %DRi.F=1, if %DRi.S= number of
steps configured - 1).
Control bits Outputs or internal bits associated with the step (16
control bits) and defined in the Configuration Editor.
Step 5 1 1 1 0 0 0
Step 6 0 1 1 0 1 0
Step 7 1 1 1 1 0 0
Operation In the above example, step 5 is the current step, control bits %Q0.1, %Q0.3, and
%Q1.5 are set to state 1; control bits %Q0.6, %Q0.5, and %Q1.0 are set to state 0.
The current step number is incremented on each rising edge at input U (or on
activation of instruction U). The current step can be modified by the program.
Timing Diagram The following diagram shows the timing of the drum controller operation.
Input U:
Input R:
Output %DRi.F
Special Cases The following table contains a list of special cases for drum controller operation.
Special Case Description
Effects of a cold restart Resets the drum controller to step 0 (updating the control bits).
(%S0=1)
Effect of a warm restart Updates the control bits after the current step.
(%S1=1)
Effect of a program jump If the drum controller is not scanned, the control bits are not reset
to 0.
Updating the control bits Only occurs when there is a change of step or in the case of a
warm or cold restart.
Introduction The following is an example of programming and configuring a drum controller. the
first six outputs %Q0.0 to %Q0.5 are activated in succession each time input %I0.1
is set to 1. Input I0.0 resets the outputs to 0.
Programming The following illustration is a drum controller function block with examples of
Example reversible and non-reversible programming.
%I0.0 %Q0.8
%DR1
R F
%I0.1
U
STEPS 6
Ladder diagram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Step 1 : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Step 2 : 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Step 3 : 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Step 4 : 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
Step 5 : 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Step 6 : 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1 : %Q0.0 4 : %Q0.1
2 : %Q0.2 5 : %Q0.3
3 : %Q0.4 6 : %Q0.5
Introduction The Fast Counter function block (%FC) serves as either an up-counter or a down-
counter. It can count the rising edge of digital inputs up to frequencies of 5kHz.
Because the Fast Counters are managed by specific hardware interrupts,
maintaining maximum frequency sampling rates may vary depending on your
specific application and hardware configuration.
Compact controllers can be configured to use a maximum of three fast counters,
while Modular controllers can only use a maximum of two. The Fast Counter function
blocks %FC0, %FC1, and %FC2 use dedicated inputs %I0.0.2, %I0.0.3, and
%I0.0.4 respectively. These bits are not reserved for their exclusive use. Their
allocation must be considered with the use of other function blocks for these
dedicated resources.
%FC0
IN D
TYPE
ADJ
%FC0.P
Parameters The following table lists parameters for the Fast Counter function block.
Parameter Label Description
Direction TYPE Set at configuration, this can be set to either up-count or down-
count.
Preset Value %FCi.P Initial value set between 1 and 65535.
Adjustable Y/N If set to Y, it is possible to modify the preset value %FCi.P and
%FCi.V with the Operator Display or Animatio Tables Editor. If
set to N, there is no access to the preset.
Current Value %FCi.V The current value counts increment or decrement according the
up or down counting function selected. For up counting, the
current value resets to zero and counts up to 65536. For down
counting, the current value resets to the preset value %FCi.P,
and counts down to zero.
Enable Input IN At state 1, the current value is updated according to the pulses
applied to the physical input. At state 0, the current value is held
at its last value.
Reset %FCi.R Used to initialize the block. At state 1, the current value is reset
to 0 if configured as an up-counter, or set to %FCi.P if configured
as a down-counter.The done bit %FCi.D is set back to its default
value.
Done %FCi.D This bit is set to 1 when:%FCi.V reaches the %FCi.P configured
as an up-counter%FCi.V reaches zero when configured as a
down-counter.
This read-only bit is reset only by the setting %FCi.R to 1.
Special Note If configured to be adjustable, then the application can change the preset value
%FCi.P and current value %FCi.V at any time. But, a new value is taken into account
only if the input reset is active or at the rising edge of output %FCi.D. This allows for
successive different counts without the loss of a single pulse.
Operation If configured to up-count, when a rising edge appears at the dedicated input, the
current value is incriminated by one. When the value is equal to the preset value
%FCi.P, the Done output bit %FCi.D is set to 1 and zero is loaded into the current
value %FCi.V.
If configured to down-count, when a rising edge appears at the dedicated input, the
current value is decreased by one. When the value is zero, the Done output bit
%FCi.D is set to 1 and the preset value is loaded into the current value %FCi.P.
Configuration In this example, the application counts a number of items up to 5000 while %I1.1 is
and set to 1. The input for %FC0 is the dedicated input %I0.0.2. When the preset value
Programming is reached, %FC0.D is set on and remains there until %FC0.R is reset by the result
of "ANDing" %I1.2 and %M0.
%I1.1 %Q0.0
IN D BLK %FC0
%FC0
LD %I1.1
IN
TYPE UP LD %I1.2
I1.2 %M0 ADJY AND %MO
R %FC0.P 5000 R
OUT_BLK
LD D
ST %Q0.0
END_BLK
Special Cases The following table contains a list of special cases for programming the %FC
function block:
Special Case Description
Effect of cold restart (%S0=1) Resets all the %FC attributes with the values
configured by the user or user application.
Effect of warm restart (%S1=1) Has no effect.
Effect of controller stop The %FC continues to count with the attribute settings
in effect at the time the controller was stopped.
Introduction The Very Fast Counter function block (%VFC) is configurable using TwidoSoft and
performs any one of the following functions:
l Up/Down Counter
l Up/Down Two-Phase Counter
l Single Up Counter
l Single Down Counter
l Frequency Meter
The %VFC provides counting of digital inputs up to frequencies of 20 kHz. The
Compact controllers can configure one very fast counter, while the Modular
controllers can configure up to two very fast counters.
Dedicated I/O The Very Fast Counter function blocks use dedicated inputs and auxiliary inputs and
Assignments outputs. These inputs and outputs are not reserved for their exclusive use. Their
allocation must be considered with the use of other function blocks for these
dedicated resources. The following table summarizes these assignments:
Main inputs Auxiliary inputs Reflex outputs
%VFC Selected Use First input Second Input Preset Catch First Second
(pulses) IA (pulses or UP/ Input Input Ica Reflex Reflex
DO) IB Ipres Output Output
UP/DOWN %I0.0.1 (Pulses) %I0.0.0 %I0.0.2 %I0.0.3 %Q0.0.2 %Q0.0.3
counter (Indicates UP=1/ Optional Optional Optional Optional
DO=0)
UP/DOWN Two- %I0.0.1 (Pulses) %I0.0.0 (pulse %I0.0.2 %I0.0.3 %Q0.0.2 %Q0.0.3
Phase counter phase B) Optional Optional Optional Optional
Single UP %I0.0.1 (Pulses) Not Used %I0.0.2 %I0.0.3 %Q0.0.2 %Q0.0.3
counter Optional Optional Optional Optional
Single DOWN %I0.0.1 (Pulses) Not Used %I0.0.2 %I0.0.3 %Q0.0.2 %Q0.0.3
counter Optional Optional Optional Optional
Frequency %I0.0.1 (Pulses) Not Used Not Used Not Used Not Used Not Used
counter
UP/DOWN %I0.0.7 (Pulses) %I0.0.6 %I0.0.5 %I0.0.4 %Q0.0.4 %Q0.0.5
counter (Indicates UP=1/ Optional Optional Optional Optional
DO=0)
UP/DOWN Two- %I0.0.7 (Pulses) %I0.0.6 (pulses %I0.0.5 %I0.0.4 %Q0.0.4 %Q0.0.5
Phase counter phase B) Optional Optional Optional Optional
Single UP %I0.0.7 (Pulses) Not Used %I0.0.5 %I0.0.4 %Q0.0.4 %Q0.0.5
counter Optional Optional Optional Optional
Single DOWN %I0.0.7 (Pulses) Not Used %I0.0.5 %I0.0.4 %Q0.0.4 %Q0.0.5
counter Optional Optional Optional Optional
Frequency %I0.0.7 (Pulses) Not Used Not Used Not Used Not Used Not Used
meter
Comments:
UP/DO = UP/DOWN
Opt. Use = Optional use
When not used, the input or output remains a normal digital I/O available to be managed by the
application in the main cycle.
%VFC0
IN F
TYPE
T_OUT0 U
T_OUT1
ADJ
%VFC0.P TH0
S TH1
Parameters The following table lists characteristics for the very fast counter function block.
Function Description Values VFC Run-
Use4 time
Access
Current Value Current value that is increased or 0 -> 65535 CM Read
(%VFCi.V) decreased according to the physical inputs
and the function selected. This value can
be set or reset using Set Input (%VFCi.S).
Preset Value Only used by the up/down counting 0 -> 65535 CM or Read
(%VFCi.P) function and single up or down counting. FM and
Write1
Capture Only used by the up/down counting 0 -> 65535 CM Read
Value function and single up or down counting.
Counting Set by the system, this bit is used by the 0 (Down) CM Read
direction up/down counting function to indicate to 1 (Up)
(%VFCi.U) you the direction of counting. When set to
1, the counting is up and when set to 0 the
counting is down.
As a single phase up or down counter,
%I0.0.0 decides the direction for %VFC0
and %I0.0.6 for %VFC1.
For a two-phase up/down counter, it is the
phase difference between the two signals
that determines the direction. For %VFC0,
%I0.0 is dedicated for IB and %I0.1 for IA.
For %VFC1, %I0.6 is dedicated for IB and
%I0.7 for IA.
Enable Reflex Enable Reflex Ouput 0 0 (Disable) CM Read
Output 0 1 (Enable) and
(%VFCi.R) Write2
Enable Reflex Enable Reflex Output 1 0 (Disable) CM Read
Output 1 1 (Enable) and
(%VFCi.S) Write2
Threshold This word contains the value of threshold 0 -> 65535 CM Read
Value S0 0. The meaning is defined during and
(%VFCi.S0) configuration of the function block. Note Write2
that this value must be less than
%VFCi.S1.
Note:
1. Writable only if Adjust is set to one.
2. Access available only if configured.
3. Read and write access only through the application, not the Operator Display or
Animation Tables Editor.
4. CM = Counting Mode and FM = Frequency Meter Mode.
Counting The very fast counting function works at a maximum frequency of 20 kHz, with a
Function range of 0 to 65535. The pulses to be counted are applied in the following way:
Description
Function Description %VFC0 IA ... IB
IA ... IB IA ... IB
UP/Down Counter The pulses are applied to the physical input, the current %I0.0.1 %I0.0.0 %I0.0.7 %I0.0.6
operation (increase/decrease) is given by the state of the
physical input IB.
UP/Down 2-Phase The two phases of the encoder are applied to physical %I0.0.1 %I0.0.0 %I0.0.7 %I0.0.6
Counter inputs IA and IB.
Single Up Counter The pulses are applied to the physical input IA. (IB is not %I0.0.1 NA %I0.0.7 NA
used).
Single Down The pulses are applied to the physical input IA. (IB is not %I0.0.1 NA %I0.0.7 NA
Counter used)
Notes on Increase or decrease operations are made on the rising edge of pulses, and only if
Function Blocks the counting function is enabled.
There are two optional inputs used in counting mode: ICa and IPres. ICa is used to
capture the current value (%VFCi.V) and stored it in %VFCi.C. The Ica inputs are
specified as %I0.0.3 for %VFC0 and %I0.0.4 for %VFC1 if available.
When IPres input is active, the current value is effected in the following ways:
l For up counting, %VFCi.V is reset to 0
l For down-counting, %VFCi.V is set to %VFCi.P
l For frequency counting, %VFCi.V and VFCi.M are set to 0
Also note that %VFCi.F will be reset to zero. The IPres inputs are specified as
%I0.0.2 for %VFC0 and %I0.0.5 for %VFC1 if available.
Notes on For all functions, the current value is compared to two thresholds (%VFCi.S0 and %
Function Block VFCi.S1). According to the result of this comparison two bit objects (%VFCi.TH0 and
Outputs %VFCi.TH1) are set to 1 if the current value is greater or equal to the corresponding
threshold, or reset to 0 in the opposite case. Reflex outputs (if configured) are set in
accordance with these comparisons. Note that none, 1 or 2 outputs can be
configured.
%VFC.U is an output of the FB, it gives the direction of the associated counter
variation (1 for UP, 0 for DOWN).
Counting
Function
Diagram
IA = up counter input
(Single signal or phase 1)
&
IN %VFCi + %VFCi.U
Single Up The following is an example of using %VFC in a single up counter mode. The
Counter following configuration elements have been set for this example:
Operation %VFC0.P preset value is 17%VFC0.S0, lower threshold value is 14, and %VFC0.S1
upper threshold is 20.
Reflex <%VFC.S0 %VFC0.S0 <= < %VFC0.S1 >= %VFC0.S1
Output
%Q0.0.2 X
%Q0.0.3 X X
IN
S
65535
20
17
14
%VFC0.V 0
TH0
TH1
Reflex
output 0
Reflex
output 1
2 : change %VFC0.S1 to 17
Single Down The following is an example of using %VFC in a single down counter mode. The
Counter following configuration elements have been set for this example:
Operation %VFC0.P preset value is 17%VFC0.S0, lower threshold value is 14 %VFC0.S1,
upper threshold is 20.
Reflex <%VFC.S0 %VFC0.S0 <= < %VFC0.S1 >= %VFC0.S1
Output
%Q0.0.2 X
%Q0.0.3 X X
%VFC0.P = 17
%VFC0.S0 = 14
%VFC0.S1 = 20
1 2 3 4 5
IN
S
65535
20
17
14
%VFC0.V 0
TH0
TH1
Reflex
output 0
Reflex
output 1
2 : change %VFC0.P to 20
3 : change %VFC0.S1 to 17
Up-Down The following is an example of using %VFC in an up-down counter mode. The
Counter following configuration elements have been set for this example:
Operation %VFC0.P preset value is 17%VFC0.S0, lower threshold value is 14 %VFC0.S1,
upper threshold is 20.
Reflex Output <%VFC.S0 %VFC0.S0 <=< %VFC0.S1 %VFC0.S1
%Q0.0.2 X
%Q0.0.3 X X
%VFC0.P = 17
%VFC0.S0 = 14
%VFC0.S1 = 20
1 2 3 4 5
IN
S
65535
20
17
14
%VFC0.V 0
TH0
TH1
Reflex
output 0
Reflex
output 1
2 : change %VFC0.P to 20
3 : change %VFC0.S1 to 17
Frequency Meter The frequency meter function of a %VFC is used to measure the frequency of a
Function periodic signal in Hz on input IA . The frequency range which can be measured is
Description from 10Hz to 20kHz. The user can choose between 2 time bases, the choice being
made by a new object %VFC.T (Time base). A value of 100 = time base of 100 ms
and a value of 1000 = time base of 1 second.
Time Base Measurement range Precision Update
100 ms 100 Hz to 20 Khz 0.05% for 20kHz 10% for 10 times per second
100Hz
1s 10 Hz to 20 Khz 0.005% for 20kHz 10% for Once per second
10Hz
The object %VFC.M (Frequency Measure Valid) is set to 1 to indicate that the
measurement is complete.
IA
Signal to be measured
+
&
VFC Counter
IN %VFCi
%VFCi.F
Overflow
Output
S %VFCi %VFCi.V
Set current Current Value Frequency
value to 0 measured
%VFCi.T %VFCi.M
(Update flag)
Select time
base 1000 ms 100 ms
Frequency Meter The following is a timing diagram example of using %VFC in a frequency meter
Operation mode.
1 2 3 4 5
IN
Time-base
%VFC0.V f1 f2 0 f3 0 f3 f4 f5
%VFC0.M
4 : Change %VFC0.T to 100 ms: this change cancels the current measurement and starts another one.
Special Cases The following table contains a list of special cases for programming the %VFC
function block:
Special case Description
Effect of cold restart (%S0=1) Resets all the %VFC attributes with the values
configured by the user or user application.
Effect of warm restart (%S1=1) Has no effect
Effect of Controller stop The %VFC stops its function and the outputs stay in
their current state.
Introduction A Twido controller can be configured to communicate with Modbus slave devices or
can send and/or receive messages in character mode (ASCII).
TwidoSoft provides the following functions for these communications:
l EXCH instruction to transmit/receive messages
l Exchange control function block (%MSG) to control the data exchanges
The Twido controller uses the protocol configured for the specified port when
processing an EXCH instruction. Each communications port can be configured for
different protocols or the same, and the EXCH instruction or %MSG function block
for each communications port is accessed by appending the port number (1 or 2).
EXCH Instruction The EXCH instruction allows a Twido controller to send and/or receive information
to/from ASCII devices. The user defines a table of words (%MWi:L or %KWi:L)
containing the data to be sent and/or received (up to 64 data words in transmission
and/or reception). The format for the word table is described in the paragraphs about
each protocol. A message exchange is performed using the EXCH instruction.
Introduction The %MSG function block manages data exchanges and has three functions:
l Communications error checking
Error checking verifies that the block length (word table) programmed with the
EXCH instruction is large enough to contain the length of the message to be sent
(compare with length programmed in the least significant byte of the first word of
the word table).
l Coordination of multiple messages
To ensure coordination when sending multiple messages, the %MSG function
block provides the information required to determine when a previous message
is complete.
l Transmission of priority messages
The %MSG function block allows current message transmissions to be stopped
in order to allow the immediate sending of an urgent message.
The programming of the %MSG function block is optional.
%MSG
R D
Parameters The following table lists parameters for the %MSG function block.
Parameter Label Value
Reset input (or R At state 1, reinitializes communication: %MSG.E = 0, and
instruction) %MSG.D = 1.
Comm. done %MSG.D State 1, comm. done, if:
output l End of transmission (if transmission)
l End of reception (end character received)
l Error
l Reset the block
State 0, request in progress.
Fault (Error) %MSG.E State 1, comm. done, if:
output l Bad command
l Table incorrectly configured
l Incorrect character received (speed, parity, etc.)
l Reception table full (not updated)
State 0, message length OK, link OK.
If an error occurs when using an EXCH instruction, bits %MSG.D and %MSG.E are
set to 1, and system word %SW63 contains the error code for Port 1, and %SW64
contains the error code for Port 2. See System Words (%SW), p. 325.
Fault (Error) The error output is set to 1 either because of a communications programming error
Output or a message transmission error. The error output is set to 1 if the number of bytes
(%MSG.E) defined in the data block associated with the EXCH instruction (word 1, least
significant byte) is greater than 128 (80 in hexadecimal).
The error output is also set to 1if a problem exists in sending a Modbus message to
a Modbus device. In this case, the user should check wiring, and that the destination
device supports Modbus communication.
Communications When the Done output is set to 1, the Twido controller is ready to send another
Done output message. Use of the %MSG.D bit is recommended when multiple messages are
(%MSG.D) sent. If it is not used, messages may be lost.
Transmission of Execution of the EXCH instruction activates a message block in the application
Several program. The message is transmitted if the message block is not already active
Successive (%MSG.D = 1). If several messages are sent in the same cycle, only the first
Messages message is transmitted. The user is responsible for managing the transmission of
several messages using the program.
Example of a transmission of two messages in succession:
%I0.0 %MSG.D
P EXCH%MW2:4 LDR %I0.0
AND %MSG.D
%M0 [EXCH %MW2:4]
S S %M0
LD %MSG.D
%MSG.D %M0
AND %M0
EXCH%MW8:3 [EXCH %MW8:3]
R %M0
%M0
R
Reinitializing An exchange is cancelled by activating the input (or instruction) R. This input
Exchanges initializes communication and resets output %MSG.E to 0 and output %MSG.D to 1.
It is possible to reinitialize an exchange if a fault is detected.
Example of reinitializing an exchange:
BLK %MSG
%M0 %MSG
LD %M0
R D R
END_BLK
Special Cases The following table lists special cases for programming the %MSG function block.
Special Case Description
Effect of a cold restart (%S0=1) Forces a reinitialization of the communication.
Effect of a warm restart (%S1=1) Has no effect.
Effect of a controller stop If a message transmission is in progress, the
controller stops its transfer and reinitializes the
outputs %MSG.D and %MSG.E.
At a Glance
Overview This section describes the time management functions for Twido controllers.
Clock Functions
Introduction Twido controllers have a time-of-day clock function, which requires the Real-Time
Clock option (RTC) and provides the following:
l Schedule blocks are used to control actions at predefined or calculated times.
l Time/date stamping is used to assign time and dates to events and measure
event duration.
The Twido time-of-day clock can be accessed by selecting Schedule Blocks from
from the TwidoSoft Software menu. Additionally, the time-of-day clock can be set
by a program. Clock settings continue to operate for up to 30 days when the
controller is switched off, if the battery has been charged for at least six consecutive
hours before the controller is switched off.
The time-of-day clock has a 24-hour format and takes leap years into account.
RTC Correction The RTC Correction value is necessary for the correct operation of the RTC. Each
Value RTC unit has its own correction value written on the unit. This value is configurable
in TwidoSoft by using the Configure RTC option from the Controller Operations
dialog box.
Schedule Blocks
Introduction Schedule Blocks are used to control actions at a predefined month, day, and time.
A maximum of 16 schedule blocks can be used and do not require any program
entry.
Note: Check system bit %S51 to confirm that the Real-Time Clock (RTC) option is
installed see System Bits (%S), p. 318. The RTC option is required for using
schedule blocks.
Enabling The bits of system word %SW114 enable (bit set to 1) or disable (bit set to 0) the
Schedule Blocks operation of each of the 16 schedule blocks.
Assignment of schedule blocks in %SW114:
%SW114
Schedule Schedule
block #15 block #0
By default (or after a cold restart) all bits of this system word are set to 1. Use of
these bits by the program is optional.
Output of If the same output (%Mi or %Qj.k) is assigned by several blocks, it is the OR of the
Schedule Blocks results of each of the blocks which is finally assigned to this object (it is possible to
have several "operating ranges" for the same output).
Example The following table shows the parameters for a summer month spray program
example:
Parameter Value Description
Schedule block 6 Schedule block number 6
Output bit %Qx.y.z Activate output %Qx.y.z
Start month June Start activity in June
End month September Stop activity in September
Start date 21 Start activity on the 21st day of June
End date 21 Stop activity on the 21st day of September
Day of week Monday, Wednesday, Run activity on Monday, Wednesday and
Friday Friday
Start time 21:00 Start activity at 21:00
Stop time 22:00 Stop activity at 22:00
Using the following program, the schedule block can be disabled through a switch
or a humidity detector wired to input %I0.1.
%I0.1 %SW114:X6 LD %I0.1
ST %SW114:X6
%I0.1
21 June
%Q0.2
M W F M W F M W F
Time Dating by Date and time are both available in system words %SW50 to %SW53 (see System
Program Words (%SW), p. 325). It is therefore possible to perform time and date stamping in
the controller program by making arithmetic comparisons between the current date
and time and the immediate values or words %MWi (or %KWi), which can contain
setpoints.
Time/Date Stamping
Introduction System words %SW50 to %SW53 contain the current date and time in BCD format
(see Review of BCD Code, p. 246, which is useful for display on or transmission to
a peripheral device. These system words can be used to store the time and date of
an event (see System Words (%SW), p. 325.
Note: Date and time and also be set by using the optional Operator Display (see
Time of Day Clock, p. 134).
Dating an Event To date an event it is sufficient to use assignment operations, to transfer the
contents of system words to internal words, and then process these internal words
(for example, transmission to display unit by EXCH instruction).
Programming The following example shows how to date a rising edge on input %I0.1.
Example
%I0.1
LDR %I0.0
P %MW12:4 := %SW50:4
[%MW12:4 := %SW50:4]
Date and Time of System words %SW54 to %SW57 contain the date and time of the last stop, and
Last Stop word %SW58 contains the code showing the cause of the last stop, in BCD format
(see System Words (%SW), p. 325).
Introduction You can update the date and time settings by using one of the following methods:
l TwidoSoft
Use the Set Time dialog box. This dialog is available from the Controller
Operations dialog box which is displayed by selecting Controller Operations
from the Controller menu (see the TwidoSoft Operation Guide).
l System words
Use system words %SW50 to %SW53 or system word %SW59.
The date and time settings can only be updated when the RTC option cartridge
(TWDXCPRTC) is installed on the controller.
Using %SW 50 to To use system words %SW50 to %SW53 to set the date and time, bit %S50 must
%SW53 be set to 1, which results in the following:
l Cancels the update of words %SW50 to %SW53 via the internal clock.
l Transmits the values written in words %SW50 to %SW53 to the internal clock.
Programming example:
%S50 %S50
LD %S50
R
R %S50
%I0.1
P %SW50 := %MW10 LDR %I0.1
[%SW50 := %MW10]
[%SW51 := %MW11]
%SW51 := %MW11 [%SW52 := %MW12]
[%SW53 := %MW13]
S %S50
%SW52 := %MW12
%SW53 := %MW13
%S50
S
Words %MW10 to %MW13 will contain the new date and time in BCD format (see
Review of BCD Code, p. 246) and will correspond to the coding of words %SW50 to
53.
The word table must contain the new date and time:
Coding Most significant byte Least significant byte
%MW10 Second Day of the week (1)
%MW11 Hour Minute
%MW12 Month Day
%MW13 Century Year
Using %SW59 Another method of updating the date and time is to use system bit %S59 and date
adjustment system word %SW59.
Setting bit %S59 to 1enables adjustment of the current date and time by word
%SW59 (see System Words (%SW), p. 325). %SW59 increments or decrements
each of the date and time components on a rising edge.
Application The following front panel is created to modify the hour, minutes, and seconds of the
Example internal clock.
+ - Seconds
14
At a Glance
Overview This chapter provides an overview of the system bits and system words that can be
used to create control programs for Twido controllers.
Introduction The following section provides detailed information about the function of system bits
and how they are controlled.
Detailed The following table provides an overview over the system bits and how they are
Description controlled:
System Function Description Init Control
Bit State
%S0 Cold Start Normally at 0. It is set to 1 by: 0 S or U->S
l A power return with loss of data
(battery fault)
l The user program or Animation Table
Editor
l Operator Display
This bit is set to 1 during the first complete
scan. It is reset to 0 by the system before
the next scan.
%S1 Warm Start Normally at 0. It is reset to 1 by: 0 S or U->S
l A power return with saving of data
l The user program or Animation Table
Editor
l Operator Display
It is reset to 0 by the system at the end of
the complete scan.
%S4 Time base: 10 ms Changes in the status of these bits are - S
%S5 Time base 100 ms controlled by an internal clock. They are
%S6 Time base 1 s not synchronized with the controller scan.
%S7 Time base 1 min Example: %S4
5ms 5ms
%S8 Output freeze Initially at 1, it can be set to 0 by the 1 U
program or by the terminal (in the
Animation Table Editor):
l At state 1, clears outputs during NO
CONFIG state.
l At state 0, allows wiring tests during
NO CONFIG state.
Table
Abbreviations
Abbreviation Description
Described
S Controlled by the system
U Controlled by the user
U->S Set to 1 by the user, reset to 0 by the system
S->U Set to 1 by the system, reset to 0 by the user
Introduction The following section provides detailed information about the function of the system
words and how they are controlled.
Detailed The following table provides detailed information about the function of the system
Description words and how they are controlled:
System Function Description Control
Word
%SW0 Controller Modifies controller scan period defined at U
scan period configuration through the user program in the
(periodic task) Animation Table Editor.
%SW6 Controller Controller state: S
state 0 = NO CONFIG
2 = STOPPED
3 = RUN
4 = HALT
%SW7 Controller Bit [0] Backup/restore in progress S
status Bit [1] Controller configuration OK
Bit [3..2] EEPROM status bits:
l 00 = No cartridge
l 01 = 32 KB EEPROM cartridge
l 10 = 64 KB EEPROM cartridge
l 11 = Reserved for future use
Bit [4] Application in RAM different than EEPROM
(1 = yes)
Bit [5] Application in RAM different than cartridge (1
= yes)
Bit [6] Some device tasks are in STOP mode
Bit [7] Controller reserved
Bit [8] Application in write protect mode
Bit [9] Unused
Bit [10] Second serial port installed
Bit [11] Second serial port type (0 = EIA RS-232, 1
= EIA RS-485)
Bit [12] Valid application in internal memory (1 =
yes)
Bit [13] Valid application in cartridge (1 = yes)
Bit [14] Valid application in RAM (1 = yes)
Bit [15] Ready to run
%SW11 Software Initializes to maximum watchdog time. The value U
watchdog time (10 to 500 ms) is defined by the configuration.
Table
Abbreviations
Abbreviation Description
Described
S Controlled by the system
U Controlled by the user
% Prefix that identifies internal memory addresses in the controller that are used to
store the value of program variables, constants, I/O, and so on.
Addresses Internal registers in the controller used to store values for program variables,
constants, I/O, and so on. Addresses are identified with a percentage symbol (%)
prefix. For example, %I0.1 specifies an address within the controller RAM memory
containing the value for input channel 1.
Analog An applied voltage that can be adjusted and converter into a digital value for use by
Potentiometer an application.
Analyze Program A command that compiles a program and checks for program errors: syntax and
structure errors, symbols without corresponding addresses, resources used by the
program that are not available, and if the program does not fit in available controller
memory. Errors are displayed in the Program Errors Viewer.
Animation Table Table created within an language editor or an operating screen. When a PC is
connected to the controller, provides a view of controller variables and allows values
to be forced when debugging. Can be saved as a separate file with an extension of
.tat.
Animation A specialized window in the TwidoSoft application for viewing and creating
Tables Editor Animation Tables.
Application A specialized window in the TwidoSoft that displays a graphical tree-like view of an
Browser application. Provides for convenient configuration and viewing of an application.
Auto Line When inserting or modifying List instructions, this optional setting allows for program
Validate lines to be validated as each is entered for errors and unresolved symbols. Each
element must be corrected before you can exit the line. Selected using the
Preferences dialog box.
Auto Load A feature that is always enabled and provides for the automatic transfer of an
application from a backup cartridge to the controller RAM in case of a lost or
corrupted application. At power up, the controller compares the application that is
presently in the controller RAM to the application in the optional backup memory
cartridge (if installed). If there is a difference, then the copy in the backup cartridge
is copied to the controller and the internal EEPROM. If the backup cartridge is not
installed, then the application in the internal EEPROM is copied to the controller.
Backup A command that copies the application in controller RAM into both the controller
internal EEPROM and the optional backup memory cartridge (if installed).
Cold Start or A start up by the controller with all data initialized to default values, and the program
Restart started from the beginning with all variables cleared. All software and hardware
settings are initialized. A Cold Restart can be caused automatically by a power
failure (Compact controllers only), or by loading a new application into controller
RAM. All Compact controllers or any controller without battery backup always power
up in Cold Start.
Comment Lines In List programs, comments can be entered on separate lines from instructions.
Comments lines do not have line numbers, and must be inserted within parenthesis
and asterisks such as: (*COMMENTS GO HERE*).
Comments Comments are text you enter to document the purpose of a program. For Ladder
programs, enter up to three lines of text in the Rung Header to describe the purpose
of the rung. Each line can consist of 1 to 64 characters. For List programs, enter text
on n unnumbered program line. Comments must be inserted within parenthesis and
asterisks such as: (*COMMENTS GO HERE*).
Compact Type of Twido controller that provides a simple, all-in-one configuration with limited
Controller expansion. Modular is the other type of Twido controller.
Constants A memory unit such as a bit or word whose contents cannot be modified by the
program being executed.
Controller Twido programmable controller. There are two types of controllers: Compact and
Modular.
Cross Generation of a list of operands, symbols, line/rung numbers, and operators used in
References an application to simplify creating and managing applications.
Cross A specialized window in the TwidoSoft application for viewing cross references.
References
Viewer
Date/Clock Allow control of events by month, day of month, and time of day. See Schedule
Functions Blocks.
Drum Controller A function block that operates similar to an electromechanical drum controller with
step changes associated with external events.
Erase This command deletes application storage and has two options: delete the contents
of the controller RAM, the controller internal EEPROM, and an installed optional
backup cartridge; or, only delete the content of an installed optional backup
cartridge.
Executive A 32-Bit Windows application used for downloading a new Firmware Executive
Loader program to a Twido controller.
Expansion Bus Expansion I/O Modules connect to the base controller using this bus.
Expansion I/O Optional Expansion I/O Modules are available to add I/O points to a Twido controller.
Modules (Not all controller models allow expansion).
Fast Counters A function block that provides for faster up/down counting than available with the
Counters function block. A Fast Counter can count up to a rate of 5 KHz.
FIFO First In, First Out. A function block used for queue operations.
Firmware The Firmware Executive is the operating system that executes your applications and
Executive manages controller operation.
Forcing Intentionally setting controller inputs and outputs to 0 or 1 values even if the actual
values are different. Used for debugging while animating a program.
Function Block A program unit of inputs and variables organized to calculate values for outputs
based on a defined function such as a timer or a counter.
Grafcet A program written in Grafcet language consists of steps containing a graphical and
structured description of the operation of sequential automation. Simple graphic
symbols are used to describe the sequence of steps.
Init A command that sets all data values to initial states. The controller must be in Stop
or Error mode.
Initial State The operating state of TwidoSoft that is displayed on the Status Bar when TwidoSoft
is started or does not have an open application.
Instance A unique object in a program that belongs to a specific type of function block. For
example, in the timer format %TMi, i is a number representing the instance.
Instruction List A program written in instruction list language (IL) is composed of a series of
Language instructions executed sequentially by the controller. Each instruction is composed of
a line number, an instruction code, and an operand.
Ladder List Rung Displays parts of a List program that are not reversible to Ladder language.
Latching input Incoming pulses are captured and recorded for later examination by the application.
LIFO Last In, First Out. A function block used for stack operations.
List Editor Simple program editor used to create and edit a List program.
Memory Optional Backup Memory Cartridges that can be used to backup and restore an
Cartridge application (program and configuration data). Two sizes are available: 32K bytes
and 64K bytes.
Memory Usage A portion of the Status Bar in the TwidoSoft main window that displays a percentage
Indicator of total controller memory used by an application. Provides a warning when memory
is low.
Modbus A master-slave communications protocol that allows one single master to request
responses from slaves.
Modular Type of Twido controller that offers flexible configuration with expansion capabilities.
Controller Compact is the other type of Twido controller.
Monitor State The operating state of TwidoSoft that is displayed on the Status Bar when a PC is
connected to a controller in a non-write mode.
Offline Operation An operation mode of TwidoSoft when a PC is not connected to the controller and
the application in PC memory is not the same as the application in controller
memory. You create and develop an application in Offline operation.
Offline State The operating state of TwidoSoft that is displayed on the Status Bar when a PC is
not connected to a controller.
Online Operation An operation mode of TwidoSoft when a PC is connected to the controller and the
application in PC memory is the same as the application in controller memory. You
debug and adjust an application in Online operation.
Online State The operating state of TwidoSoft that is displayed on the Status Bar when a PC is
connected to the controller.
Operand A number, address, or symbol representing a value that a program can manipulate
in an instruction.
Operating States Indicate the status of TwidoSoft and is displayed on the Status Bar. There are four
operating states: Initial, Offline, Online, and Monitor.
PC Personal Computer.
Peer Controller A Twido controller configured as a slave on a Remote Link network. An application
can be executed in the Peer Controller memory and the program can access both
local and expansion I/O data, but I/O data can not be passed to the Master
Controller. The program running in the Peer Controller passes information to the
Master Controller by using network words (%INW and QNW).
PLS Pulse Generation. A function block that generates a square wave with a 50% on and
50% off duty cycle.
Preferences A dialog box with selectable options for setting up the List and Ladder program
editors.
Program Errors Specialized TwidoSoft window used to view program errors and warnings.
Viewer
Programmable A Twido controller. There are two types of controllers: Compact and Modular.
Controller
Protection Refers to two different types of application protection: password protection which
provides access control, and controller application protection which prevents
unauthorized viewing and copying of an application.
PWM Pulse Width Modulation. A function block that generates a square wave with a
variable duty cycle that can be set by a program.
RAM Random Access Memory. Twido applications are downloaded into internal volatile
RAM to be executed.
Real-Time Clock An option that will keep the time even when the controller is not powered for a limited
amount of time.
Reflex Output In a counting mode, the very fast counter’s current value (%VFC.V) is measured
against its configured thresholds to determine the state of these dedicated outputs.
Registers Special registers internal to the controller dedicated to LIFO/FIFO function blocks.
Remote Link High-speed master/slave bus designed to communicate a small amount of data
between a Master Controller and up to seven Remote Controllers (slaves). There
are two types of Remote Controllers that can be configured to transfer data to a
Master Controller: a Peer Controller that can transfer application data, or a Remote
I/O Controller that can transfer I/O data. A Remote link network can consist of a
mixture of both types.
RTU Remote Terminal Unit. A protocol using eight bits that is used for communicating
between a controller and a PC.
Rung A rung is entered between two potential bars in a grid and is composed of a group
of graphical elements joined to each other by horizontal or vertical links.The
maximum dimensions of a rung are seven rows and eleven columns.
Rung Header A panel that appears directly over a Ladder rung and can be used to document the
purpose of the rung.
Scan A controller scans a program and essentially performs three basic functions. First, it
reads inputs and places these values in memory. Next, it executes the application
program one instruction at a time and stores results in memory. Finally, it uses the
results to update outputs.
Scan Mode Specifies how the controller scans a program. There are two types of scan modes:
Normal (Cyclic), the controller scans continuously, or Periodic, the controller scans
for a selected duration (range of 2 - 150 msec) before starting another scan.
Schedule Blocks A function block used to program Date and Time functions to control events.
Requires Real-Time Clock option.
Stop A command that causes the controller to stop running an application program.
Symbol Table A table of the symbols used in an application. Displayed in the Symbol Editor.
Threshold Coils that are controlled directly by the very fast counter (%VFC) according to the
Outputs settings established during configuration.
Timer A function block used to select a time duration for controlling an event.
Very Fast A function block that provides for faster counting than available with Counters and
Counters Fast Counters function blocks. A Very Fast Counter can count up to a rate of 20 KHz.
Warm Restart A power-up by the controller after a power loss without changing the application.
Controller returns to the state which existed before the power loss and completes
the scan which was in progress. All of the application data is preserved. This feature
is only available on modular controllers.
Comparison block F
graphic element, 149
Fast counter function block, 283
Comparison blocks, 146
FIFO
Comparison Instructions, 236
Introduction, 263
Configuring
Operation, 266
A port for ASCII, 82
Function Blocks
A port for Modbus, 93
PWM, 270
A transmit/receive buffer for ASCII, 82
Function blocks
Contacts, 144
Counters, 218
graphic element, 147
Drum controller, 277, 281
Control parameters
graphic element, 149
ASCII, 83
in programming grid, 145
Modbus, 94
Overview of basic function blocks, 206
Controller
Programming basic function blocks, 208
Initialization, 60
Registers, 263
Conversion instructions, 246
Schedule blocks, 308
Counters, 218
Shift Bit Register (%SBR), 223
Programming and configuring, 222
Step counter (%SCi), 226
Timers, 210, 215
D
decrement, 238 G
Direct addressing, 37
Grafcet
divide, 238
associated actions, 183
Documenting your program, 159
examples, 178
Down connector, 147
instructions, 176
Drum controller function block, 277
preprocessing, 180
Drum controllers
sequential processing, 181
Operation, 279
Grafcet methods, 52
Programming and configuring, 281
Graphic elements
Ladder diagrams, 147
E
Edge detection I
Falling, 190
I/O
Rising, 189
Addressing, 31
END Instructions, 249
increment, 238
END_BLK, 157
index overflow, 38
error, 240
Initializing a controller, 60
EXCH, 302
EXCH instruction, 302
Exchange function block, 303
Exclusive OR instructions, 202
Scanning W
Cyclic, 46
Warm restart, 56
Periodic, 48
Word Objects, 257
Shift bit register, 223
Word objects
Shift instructions, 244
Addressing, 30
SHORT, 150
Overview, 27
Software watchdog, 51
Word tables, 35
square root, 238
SR, 253
Stack, 263 X
Stack instructions, 172
Step counter, 226 XOR, 202
Store instructions, 196
subroutine instructions, 253
subtract, 238
Symbolizing, 39
System bits, 318
System words, 325
T
Test Zone, 142
Timers, 211
introduction, 210
Programming and configuring, 215
Time base of 1 ms, 216
TOF type, 212
TON type, 213
TP type, 214
TOF timer, 212
TON timer, 213
TP type timer, 214
Transmitting messages, 302
TwidoSoft
Introduction, 18
U
Unconditional rungs, 158
V
Vertical short, 147
Very fast counters function block, 286