Resources for PLC Training

PLC MEMORY

 

INTRODUCTION

Advanced ladder logic functions allow controllers to perform calculations, make decisions and do other complex tasks. Timers and counters are examples of ladder logic functions. They are more complex than basic input contacts and output coils and they rely upon data stored in the memory of the PLC. The memory of the PLC is organized to hold different types of programs and data.

MEMORY ADDRESSES

The memory in a PLC is organized by data type as shown in See PLC Memory. There are two fundamental types of memory used in Allen-Bradley PLCs - Program and Data memory. Memory is organized into blocks of up to 1000 elements in an array called a file. The Program file holds programs, such as ladder logic. There are eight Data files defined by default, but additional data files can be added if they are needed.

 

PLC Memory

PROGRAM FILES

In a PLC-5 the first three program files, from 0 to 2, are defined by default. File 0 contains system information and should not be changed, and file 1 is reserved for SFCs. File 2 is available for user programs and the PLC will run the program in file 2 by default. Other program files can be added from file 3 to 999. Typical reasons for creating other programs are for subroutines.

When a user creates a ladder logic program with programming software, it is converted to a mnemonic-like form, and then transferred to the PLC, where it is stored in a program file. The contents of the program memory cannot be changed while the PLC is running. If, while a program was running, it was overwritten with a new program, serious problems could arise.

DATA FILES

Data files are used for storing different information types, as shown in See Data Files for an Allen Bradley PLC-5. These locations are numbered from 0 to 999. The letter in front of the number indicates the data type. For example, F8: is read as floating point numbers in data file 8. Numbers are not given for O: and I:, but they are implied to be O0: and I1:. The number that follows the : is the location number. Each file may contain from 0 to 999 locations that may store values. For the input I: and output O: files the locations are converted to physical locations on the PLC using rack and slot numbers. The addresses that can be used will depend upon the hardware configuration. The status S2: file is more complex and is discussed later. The other memory locations are simply slots to store data in. For example, F8:35 would indicate the 36th value in the 8th data file which is floating point numbers.

 

Data Files for an Allen Bradley PLC-5

Only the first three data files are fixed O:, I: and S2:, all of the other data files can be moved. It is also reasonable to have multiple data files with the same data type. For example, there could be two files for integer numbers N7: and N10:. The length of the data files can be from 0 up to 999 as shown in See Locations in a Data File. But, these files are often made smaller to save memory.

 

Locations in a Data File

See Data Files for an Allen Bradley PLC-5 shows the default data files for a PLC-5. There are many additional data types, a full list is shown in See Allen-Bradley Data Types. Some of the data types are complex and contain multiple data values, including BT, C, MG, PD, R, SC, and T. Recall that timers require integers for the accumulator and preset, and TT, DN and EN bits are required. Other data types are based on single bits, 8 bit bytes and 16 bit words.

 

Allen-Bradley Data Types

When using data files and functions we need to ask for information with an address. The simplest data addresses are data bits (we have used these for basic inputs and outputs already). An example of Address bits is shown in See Bit Level Addressing. Memory bits are normally indicated with a forward slash followed by a bit number /n. The first example is from an input card I:000, the third input is indicated with the bit address /02. The second example is for a counter C5: done bit /DN. This could also be replaced with C5:4/15 to get equivalent results. The DN notation, and others like it are used to simplify the task of programming. The example B3/4 will get the fourth bit in bit memory B3. For bit memory the slash is not needed, because the data type is already bits.

 

Bit Level Addressing

Entire words can be addressed as shown in See Integer Word Addressing. These values will normally be assumed to be 2s compliment, but some functions may assume otherwise. The first example shows a simple integer memory value. The next example gets up to inputs (from card 0 in rack zero) as a single word. The last two examples are more complex and they access the accumulator and preset values for a timer. Here a '.' is used as the '/' was used for bit memory to indicate it is an integer. The first two examples don't need the '.' because they are both integer value types.

 

Integer Word Addressing

Data values do not always need to be stored in memory, they can be define literally. See Literal Data Values shows an example of two different data values. The first is an integer, the second is a real number. Hexadecimal numbers can be indicated by following the number with H, a leading zero is also needed when the first digit is A, B, C, D, E or F. A binary number is indicated by adding a B to the end of the number.

 

Literal Data Values

Sometimes we will want to refer to an array of values, as shown in See File Addressing. This data type is indicated by beginning the number with a pound or hash sign '#'. The first example describes an array of floating point numbers staring in file 8 at location 5. The second example is for an array of integers in file 7 starting at location 0. The length of the array is determined elsewhere.

 

File Addressing

Indirect addressing is a method for allowing a variable in a data address, as shown in See Indirect Addressing. The indirect (variable) part of the address is shown between brackets '[' and ']'. If a PLC is looking at an address and it finds an indirect address it will look in the specified memory location, and put that number in place of the indirect address. Consider the first example below I:000/[N7:2], if the value in the integer memory location N7:2 is 45, then the address becomes I:000/45. The other examples are very similar. This type of technique is very useful when making programs that can be adapted for different recipes - by changing a data value in one memory location the program can follow a new set of data.

 

Indirect Addressing

Expressions allow addresses and functions to be typed in and interpreted when the program is run. The example in See Expression Data Values will get a floating point number from file 8, location 3, perform a sine transformation, and then add 1.3. The text string is not interpreted until the PLC is running, and if there is an error, it may not occur until the program is running - so use this function cautiously.

 

Expression Data Values

These data types and addressing modes will be discussed more as applicable functions are presented later in this chapter and book. Floating point numbers, expressions and indirect addressing may not be available on older or lower cost PLCs.

See An Example of Ladder Logic Functions shows a simple example ladder logic with functions. The basic operation is such that while input A is true the functions will be performed. The first statement will move (MOV) the literal value of 130 into integer memory N7:0. The next move function will copy the value from N7:0 to N7:1. The third statement will add integers value in N7:0 and N7:1 and store the results in N7:2.

 

An Example of Ladder Logic Functions

User Bit Memory

Individual data bits can be accessed in the bit memory. These can be very useful when keeping track of internal states that do not directly relate to an output or input. The bit memory can be accessed with individual bits or with integer words. Examples of bit addresses are shown in See Bit Memory. The single blackened bit is in the third word B3:2 and it is the 4th bit 03, so it can be addressed with B3:2/03. Overall, it is the 35th bit, so it could also be addressed with B3/35.

 

Bit Memory

This method can also be used to access bits in integer memory also.

Timer Counter Memory

Previous chapters have discussed the operation of timers and counters. The ability to address their memory directly allows some powerful tools. Recall that by default timers are stored in the T4: file. The bits and words for timers are;

EN - timer enabled bit (bit 15)

TT - timer timing bit (bit 14)

DN - timer done bit (bit 13)

PRE - preset word

ACC - accumulated time word

Counter are stored in the C5: file and they have the following bits and words.

CU - count up bit (bit 15)

CD - count down bit (bit 14)

DN - counter done bit (bit 13)

OV - overflow bit (bit 12)

UN - underflow bit (bit 11)

PRE - preset word

ACC - accumulated count word

As discussed before we can access timer and counter bits and words using the proper notation. Examples of these are shown in See Examples of Timer and Counter Addresses. The bit values can only be read, and should not be changed. The presets and accumulators can be read and overwritten.

 

Examples of Timer and Counter Addresses

Consider the simple ladder logic example in See Door Light Example. It shows the use of a timer timing TT bit to seal on the timer when a door input has gone true. While the timer is counting, the bit will stay true and keep the timer counting. When it reaches the 10 second delay the TT bit will turn off. The next line of ladder logic will turn on a light while the timer is counting for the first 10 seconds.

 

Door Light Example

PLC Status Bits (for PLC-5s and Micrologix)

Status memory allows a program to check the PLC operation, and also make some changes. A selected list of status bits is shown in See Status Bits and Words for Micrologix and PLC-5s for Allen-Bradley Micrologic and PLC-5 PLCs. More complete lists are available in the manuals. For example the first four bits S2:0/x indicate the results of calculations, including carry, overflow, zero and negative/sign. The S2:1/15 will be true once when the PLC is turned on - this is the first scan bit. The time for the last scan will be stored in S2:8. The date and clock can be stored and read from locations S2:18 to S2:23.

 

Status Bits and Words for Micrologix and PLC-5s

The other status words allow more complex control of the PLC. The watchdog timer allows a time to be set in S2:28 so that if the PLC scan time is too long the PLC will give a fault condition - this is very important for dangerous processes. When a fault occurs the program number in S2:29 will run. For example, if you have a divide by zero fault, you can run a program that recovers from the error, if there is no program the PLC will halt. The locations from S2:30 to S2:55 are used for interrupts. Interrupts can be used to run programs at fixed time intervals, or when inputs change.

User Function Control Memory

Simple ladder logic functions can complete operations in a single scan of ladder logic. Other functions such as timers and counters will require multiple ladder logic scans to finish. While timers and counters have their own memory for control, a generic type of control memory is defined for other function. This memory contains the bits and words in See Bits and Words for Control Memory. Any given function will only use some of the values. The meaning of particular bits and words will be described later when discussing specific functions.

 

Bits and Words for Control Memory

Integer Memory

Integer memory is 16 bit words that are normally used as 2s compliment numbers that can store data values from -32768 to +32767. When decimal fractions are supplied they are rounded to the nearest number. These values are normally stored in N7:xx by default, but new blocks of integer memory are often created in other locations such as N9:xx. Integer memory can also be used for bits.

Floating Point Memory

Floating point memory is available in newer and higher cost PLCs, it is not available on the Micrologix. This memory stores real numbers in 4 words, with 7 digits of accuracy over a range from +/-1.1754944e-38 to +/-3.4028237e38. Floating point memory is stored in F8:xx by default, but other floating point numbers can be stored in other locations. Bit level access is not permitted (or useful) for these numbers.

SUMMARY

Program files store users programs in files 2 - 999.

Data files are available to users and will be 0-999 locations long.

Default data types on a PLC-5 include Output (O0:), Input (I1:), Status (S2:), Bit (B3:), Timer (T4:), Counter (C5:), Control (R6:), Integer (N7:) and Float (F8:).

Other memory types include Block Transfer (BT), ASCII (A), ASCII String (ST), BCD (D), Message (MG), PID Control (PD), SFC Status (SC).

In memory locations a '/' indicates a bit, '.' indicates a word.

Indirect addresses will substitute memory values between '[', ']'.

Files are like arrays and are indicated with '#'.

Expressions allow equations to be typed in.

Literal values for binary and hexadecimal values are followed by B and H.

PRACTICE PROBLEMS

1. Can PLC outputs can be set with Bytes instead of bits?

(ans. yes, for example the output word would be adressed as O:000)

2. How many types of memory can a PLC-5 have?

(ans. There are 13 different memory types, 10 of these can be defined by the user for data files between 3 and 999.)

3. What are the default program memory locations?

(ans. Program files 0 and 1 are reserved for system functions. File 2 is the default ladder logic program, and files 3 to 999 can be used for other programs.)

4. How many types of number bases are used in PLC memory?

(ans. binary, octal, BCD, 2s compliment, signed binary, floating point, bits, hexadecimal)

5. How are timer and counter memory similar?

(ans. both are similar. The timer and counter memories both use words for the accumulator and presets, and they use bits to track the status of the functions. These bits are somewhat different, but parallel in function.)

6. What types of memory cannot be changed?

(ans. Inputs cannot be changed by the program, and some of the status bits/words cannot be changed by the user.)

7. Develop Ladder Logic for a car door/seat belt safety system. When the car door is open, or the seatbelt is not done up, a buzzer will sound for 5 seconds if the key has been switched on. A cabin light will be switched on when the door is open and stay on for 10 seconds after it is closed, unless a key has started the ignition power.

 

8. Look at the manuals for the status memory in your PLC.

a) Find the first scan location

b) Describe how to run program 7 when a divide by zero error occurs.

c) Write the ladder logic needed to clear a PLC fault.

d) Describe how to set up a timed interrupt to run program 5 every 2 seconds.

(ans. S2:1/14 for micrologix, S2:1/15 for PLC-5.)

9. Write ladder logic for the following problem description. When button A is pressed a value of 1001 will be stored in N7:0. When button B is pressed a value of -345 will be stored in N7:1, when it is not pressed a value of 99 will be stored in N7:1. When button C is pressed N7:0 and N7:1 will be added, and the result will be stored in N7:2.

 

10. Using the status memory locations, write a program that will flash a light for the first 15 seconds after it has been turned on. The light should flash once a second.

 

11. We are developing a safety system (using a PLC-5) for a large industrial press. The press is activated by turning on the compressor power relay (R, connected to O:013/05). After R has been on for 30 seconds the press can be activated to move (P connected to O:013/06). The delay is needed for pressure to build up. After the press has been activated (with P) the system must be shut down (R and P off), and then the cycle may begin again. For safety, there is a sensor that detects when a worker is inside the press (S, connected to I:011/02), which must be off before the press can be activated. There is also a button that must be pushed 5 times (B, connected to I:011/01) before the press cycle can begin. If at any time the worker enters the press (and S becomes active) the press will be shut down (P and R turned off). Develop the state transition diagram, and then ladder logic for the states. State all assumptions, and show all work.