Advanced Instructions Most PLCs now support more advanced functions such as Floating point math,...

44
Advanced Instructions • Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control and Communications.

Transcript of Advanced Instructions Most PLCs now support more advanced functions such as Floating point math,...

Advanced Instructions

• Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control and Communications.

Scan time

Many processes, especially in machine control, function betterwhen the scan time is small. As the program gets larger thescan time increases. Usually, in larger programs, not all of thelogic needs to be executed every scan. If this is the case, sectionsof ladder logic can be skipped during periods where no activity is occurring in that part of the process.

Jump/Label

• Used to skip over a section of logic to reduce scan time

• 99% of the time you want to jump forward

Jump example

Moving data

Many times we want to be able to either change a preset valueunder program control or turn on/off several outputs with one instruction. The MOVE instruction allows 16 bit chunks of datato be moved around.

Move example

16 bit numbers

Remember that with 16 bits the number of combinations that canbe represented is 216 or 65,536 possible combinations.

We can represent these combinations as any range of numbers, butmore typically the following two ranges are used depending onthe context they are in. 0 through 65,535 or -32768 to +32,767.

Another example would be in representing BCD (Binary Coded Decimal) numbers.In BCD, each decimal digit if represented with 4 bits. 0000=0, while 1001=9. With16 bits, 4 BCD digits can be represented.

BCD numbers

Most operator I/O devices such as thumbwheel entry, numericdisplays, etc use the BCD representation.

Example, 2305 in decimal converts to 4 groups of 4 bit numbers.

2 3 0 50010 0011 0000 0101

Note: It is customary to show the MSB (Most Significant Bit) onthe left side of a binary number. In this course, that will hold true

Care must be exercised when performing math on numbers. Make sure thatBCD numbers have been converted to binary first.

BCD conversions

• Many times, BCD (Binary Coded Decimal) devices are connect to outputs

• The BCD instructions convert to/from binary/BCD

BCD exercise

• Convert 42 BCD to binary

• Convert 1001 0010 to BCD

• What are the valid 4 bit binary values that can be converted to BCD?

MathProgramming languages like Java, C and Pascal are considered “Strongly Typed”. Thismeans that the programmer must specify which type of information a variable will hold.

For example, information can be true/false (1 bit), numeric (integer and real numbers), string, array or custom types. In most PLCs the numeric data is either single precision(16 bit) or double precision (32bit). In PLCs, the math operations usually are different for 16 bit, 32 bit and floating point functions.

In this course we will limit the scope of the math functions used.

Add

Subtract

Multiply

Divide

Math example #1

Math example #1 con’t

Math example #2

Masking

• Some instructions like the Masked Move (MVM) allow the source to be ANDed with a mask so that only the part of the source you want gets through

Remember back in grade school when the teacher gave you a quiz that used a multiple choice answer form. When s/he graded the quiz they would overlay a template with holes cut out so that only areas where the correct answers would show through. This is an example of masking.

We use masking in order to look at or control a portion of a 16 bit number. The binary mask value is ANDedwith the number of interest.

AND

OR

XOR

NOT

Clear

Inequalities

• Greater than

• Less than

• Equal

• Not equal

Inequalities• Are very useful to compare timer/counter accumulated values, etc

• Always be careful with the Equal/Not equal

• In the BASIC programming example below, is the test ever true?

I=0While I<> 5 DO

Begin I=I+2 Print IEnd

The real danger with using inequalities is not so much with counting when things arealways incremented by one, but rather with analog inputs and other situations wherethe increment can be a number other than one.

Greater than

Less than

Equal

Not Equal

Sequencers

Step Out 7 Out 6 Out 5 Out 4 Out 3 Out 2 Out 1 Out 01 1 0 0 0 1 1 0 12 0 1 0 1 1 0 1 03 1 1 1 1 0 0 0 14 0 1 0 0 0 1 1 1

With a sequencer, an entire block of outputs to be controlled together. Many processes are sequential in nature andcan be described in discrete steps. On step #1 the outputs will be set in a certain pattern, in step #2 the pattern willbe different. A truth table, as shown below, can be constructed. There are two types of sequencers, bit shift anddrum. Below is an example of a when a drum sequencer, where multiple outputs are controlled at the same time, would be used.

Each time the sequencer is activated it moves to the next step and will set the outputs to the following pattern

Drum sequencers

Show picture of mechanical drum sequencer with explain

Sequencers

Sequencers

Sequencer example

Sequencer example (con’t)

Bit shiftBit shifting instructions teach a group of binary digits as one large value. And in the sameway that a digital circuit shift register operates, the PLC has instructions to operate on thesevalues. Shift left and Shift right instructions will be used.

Bit shift sequencers are used to track parts on a conveyor or sequence a process throughdifferent steps.

The shift operation can also be looked at as a math function. When values are shifted leftit has the same effect as multiplying by 2. Conversely, when shifting right, the numberis divided by 2.

Point of interest: Most 8 bit microprocessors (8085, Z80, 6502) do not have multiplyinstructions. Multiplication is accomplished by an algorithm of shifting and adding.

Bit shift left

Bit shift left example

Bit shift right

Shifting example

Shifting example (con’t)

• What does this do?

• It is started by input #3

Control structures

As discussed before, the PLC needs both memory and scan time to perform housekeepingtasks. When using a simple one-shot instruction, an additional 1 bit of memory was required to retain the status of was the one-shot fired during the last scan. With timersand counters we had the T4 and C5 files which has the control structures for those devices.With some of the more advanced instructions such as shift registers the CPU requires theuse of a block of memory which is referred to as a Control structure. In AB land, this isfound in a the control file (R6) and again there are 255 structures available. You cannot use the Binary file (B3) or the timer/counter files T4/C5.

Control structures