Ladder Programming
Ladder Programming
Timers
Several timer commands available
• More information can be found in NJ Series Instruction
Manual
• Timer section of Toolbox
• Function Blocks
º TON
º TOF
º TP
º AccumulationTimer
• Functions
º TIMER
Timers
TON, TOF, TP use TIME data type for preset
• Constant or variable
• Maximum value
º 106,571 days
º 23 hours
º 47 minutes
º 16 seconds
º 854.775807 milliseconds
• Accurate to 100ns
Timers
On Delay Timer
• Function block instance must be defined
• When IN is energized, timer begins to time up from
zero to preset value PT
• When current value reaches preset, output Q active
• Current elapsed time available at ET
• When IN signal is removed
º Output turns off
º Elapsed time reset to zero
Timers
On Delay Timer
• Example
Timers
Off Delay Timer
• Function block instance must be defined
• When input In turns on
º Output Q turns on
º ET of timer is reset to zero
• Timing begins when In turns off
• Timer times up from zero to preset
• Output Q turns off when preset reached
Timers
Off Delay Timer
• Example
Timers
Pulse Timer
• Create a one-shot pulse
• Input In turns on
º Output Q turns on
º Timer begins to time
• When preset value is reached, output Q turns off
• Output is always same length, regardless of input
length
Timers
Pulse Timer
• Example
Timers
Accumulation Timer
• Different than other timers discussed
• Retentive, does not automatically reset
• Must use Reset input to reset elapsed time value
• Can be useful as a stopwatch or to time how long a
condition is true
Timers
Accumulation Timer
• A preset can be defined on PT
• The output Q will turn on if this preset value is
reached
• Each time In turns on, the elapsed time ET is
updated as long as In stays on
• ET will continue to accumulate each time In
turns on
• When In turns off, the value in ET is held
• The value is held until reset with the Reset input
Timers
Accumulation Timer
• Example
Timers
TIME Data Type
• Many operator interfaces and OPC products do not
have support for this IEC data type
• May be required to enter a value in a different format
(such as LINT) and convert it to TIME type
º Nanoseconds
‒ NanoSecToTime
º Milliseconds
‒ Multiply by 1,000,000, NanoSecToTime
º Seconds
‒ SecToTime
Timers
TIME Data Type
• To convert TIME data type to integer, use:
º TimeToSec
º TimeToNanoSec
• Example conversion
Timers
Timer
• This function does NOT use the TIME data type
• Preset is integer representing 100ms increments
º 10 x 100ms = 1s
• Times DOWN from preset to zero
• TimerDat is IN/OUT variable
º MUST be declared as type _sTimer
Timers
Timer
• Example
EXERCISE
Counters
Several counter commands available
• More information can be found in NJ Series Instruction
Manual
• Counter section of Toolbox
• Function Blocks
º CTD
º CTU
º CTUD
º All INT based, max value 32,767
Counters
Counters with higher count capabilities
• CTD_DINT
• CTD_LINT
• CTD_UDINT
• CTD_ULINT
Same 4 options for CTU and CTUD
See table in Lesson 2 for value limits of these data
types
Counters
Count Down
• Counts down from preset value to zero
• CD arrow means rising edge signal
• Load input sets counter to preset value
• PV indicates preset value
º Constant number or variable
• Q turns on when counter reaches zero
• CV is current value of counter
Counters
Count Down
Counters
Count Down
• Counter does NOT count while LOAD is on
• Counter does NOT count below zero
Counters
Count Up
• Counts up from zero to preset value
• CU input causes count up
• Reset input resets counter to zero
• other values are as previously discussed
Counters
Count Up
Counters
Bi-Directional Counter
• Counts both up and down
• Combines functions of CTU and CTD
• Signal names as previously discussed
• QU indicates count equal to preset
• QD indicates count equal to zero
º Counted down to zero or immediately after reset
Counters
Bi-Directional Counter
EXERCISE
Data Movement
Variety of functions in Data Movement section of
Toolbox window
Other commands
• TRUNC truncates decimal places (no rounding)
• Round rounds the value per the table above
• RoundUp always rounds up to next integer
Scaling
NJ Firmware 1.05 and Sysmac Studio 1.06