Hardware, Memory and the Scan
What a PLC is made of, where the program and the data live, and what the processor does over and over. A PLC takes in inputs, makes decisions from the program and energizes outputs. The difference from a relay panel is that the logic is a program, not wiring.
Built-in I/O, unchangeable. Processor, supply and terminals in one housing. Everything addresses to slot 0.
You choose the cards and where they go. The processor is slot 0, so the first I/O module is slot 1 - count past the processor. The card's slot becomes the middle of its address.
The chassis is not just a shelf to hang cards on. Running along the back of it is the backplane, and the backplane provides power and communication: it feeds every module from the power supply, and it carries the data between the processor and each card. That is what lets a processor in slot 0 read an input card in slot 3 without a single wire running between the two.
Volatile memory (RAM) loses its contents without power, unless a battery keeps it alive. Non-volatile memory (ROM, EEPROM and flash) keeps its contents with no power at all. The user program has to survive an outage, so it is kept in battery-backed RAM or in non-volatile memory.
Organized another way, memory is two halves: program files hold the ladder, and data files hold what the ladder works with: the input and output images, bits, timers, counters and numbers.
Full lesson: The five parts The scan cycle Memory
Discrete and Analog
Discrete is on or off, one bit. Analog varies continuously, so the PLC stores it as a number.
Drag each device into a bin, or tap one and then tap a bin. Nothing is marked until you press Check.
Discrete
Analog
Varies in the positive only: 0 to 5 V or 0 to 10 V.
Varies positive and negative: -5 to +5 V or -10 to +10 V.
| Discrete | Analog | |
|---|---|---|
| Signal | On or off | A range of volts or milliamps |
| In the data table | One bit | One 16-bit word, a number |
| Inputs | Pushbutton, limit switch, proximity sensor, float | Thermocouple, RTD, pressure or level transmitter |
| Outputs | Pilot light, horn, motor starter coil, solenoid | Drive speed reference, proportional valve |
Ranges
| Range | Type |
|---|---|
| 0 to 5 V | Unipolar |
| 0 to 10 V | Unipolar |
| -5 to +5 V | Bipolar |
| -10 to +10 V | Bipolar |
Full lesson: Discrete and analog, unipolar and bipolar
I/O Modules and Wiring
An input card senses the field and tells the processor. An output card switches the load, and the kind of card decides which loads it can switch.
A discrete output card turns a load on and off. What is inside it, between the output terminal and the supply, decides which loads it can switch: a relay contact, a triac or a transistor. Pick a card, then turn the bit on and off. Try a card on the wrong supply too.
A sinking module returns current through its common to the negative. A sourcing module supplies the positive. The pair always has to be one of each.
| Module | Its common goes to | The field side | Pairs with |
|---|---|---|---|
| Sinking input | 0 V | The device brings +24 V to the input terminal | A sourcing device, such as a switch fed from +24 V |
| Sourcing input | +24 V | The device connects the input terminal to 0 V | A sinking device, such as a switch wired to 0 V |
| Sinking output | 0 V | The load runs from +24 V to the output terminal. On, the terminal reads about 0 V. | A load fed from the positive |
| Sourcing output | +24 V | The load runs from the output terminal to 0 V. On, the terminal reads about 24 V. | A load returned to the negative |
Two sinks never complete a circuit, and neither do two sources. Match the pair first, then check the card's own label.
Open it in Basics →Full lesson: Sinking and sourcing
Addressing and the Image Tables
Every bit, timer and number has an address: the file it is in, then where in the file.
I is the file type, an input. 1 is the slot the card is in. 3 is the bit, counted from 0. A 16-point card has bits 0 to 15, so the fifth point down is bit 4.
| Address | File | Reads as |
|---|---|---|
| I:1/3 | Input image | Input, slot 1, bit 3 |
| O:2/0 | Output image | Output, slot 2, bit 0 |
| B3:0/5 | Bit file 3 | Word 0, bit 5. Internal bits, the control relays of a PLC. |
| T4:2/DN | Timer file 4 | Timer 2, its DN bit. Also T4:2.PRE and T4:2.ACC as numbers. |
| C5:1/DN | Counter file 5 | Counter 1, its DN bit. Also C5:1.PRE and C5:1.ACC. |
| N7:10 | Integer file 7 | Word 10, a 16-bit number. N7:10/3 is bit 3 of that word. |
Fixed or modular
A slot of 0 in an I or O address is a fixed PLC, where all the I/O is built in. In a modular rack the CPU is in slot 0, so the I/O cards start at slot 1 and the slot number is part of every address.
This site builds every rack in one order: CPU in slot 0, then the discrete input cards, then discrete outputs, then analog inputs, then analog outputs, with no gaps.
| Slot 0 | Slot 1 | Slot 2 | Slot 3 | Slot 4 |
|---|---|---|---|---|
| CPU | 16 point discrete input I:1/0 to I:1/15 | 16 point discrete output O:2/0 to O:2/15 | Analog input | Analog output |
Two pictures of the same point. The card's light shows the terminal right now. The ladder's highlight shows the image bit, which is as old as the last input scan. They can disagree for a scan, and when they disagree for longer something is wrong.
Open it in Basics →Full lesson: Fixed and modular I/O The scan and the image tables
Examine if Closed and Examine if Open
Two instructions look at a bit. XIC is true when the bit is 1. XIO is true when the bit is 0. That is all they do, and every rung is these in series and parallel in front of an output.
The whole table
| Field device | Input bit | XIC | XIO |
|---|---|---|---|
| Normally open, at rest | 0 | false | true |
| Normally open, actuated | 1 | true | false |
| Normally closed, at rest | 1 | true | false |
| Normally closed, actuated or the wire broken | 0 | false | true |
Choosing one
Choose from what you need the bit to be, not from the symbol on the device. The bit tells you what the field wiring did.
- A normally open start button, run while pressed: XIC.
- A normally closed stop button, run while it is not pressed: XIC. At rest the bit is 1, and a broken wire stops the machine.
- A normally open overtemperature switch that closes when hot, run only while it is not: XIO.
- An XIO on a normally open device nobody has actuated is true from the first scan in RUN.
Series is AND, parallel is OR, XIO is NOT. The other gates are built from those three:
| Gate | In ladder |
|---|---|
| AND | Contacts in series |
| OR | Contacts in parallel |
| NOT | An XIO |
| NAND | XIOs in parallel (any input off turns it on) |
| NOR | XIOs in series (all inputs off turns it on) |
| XOR | Two paths: A and not B, or not A and B |
Full lesson: XIC or XIO Logic gates, three ways to say it
Timers
TON delays turning on, TOF delays turning off, RTO adds up time and remembers it. A timer instruction has no contacts of its own. It sets bits in its timer file element, and other rungs use those bits with XIC and XIO instructions. For a timer at T4:0:
Timer on-delay. It times while its rung is true. If the rung goes false at any point, before or after done, everything resets: all three bits off and the accumulator back to 0.
Energized and Timing read the same: TT comes on the same scan the rung goes true. The only difference is that ACC has started counting.
Timer off-delay. DN comes on with the rung, and the timing starts when the rung goes false. DN holds until the time runs out. If the rung goes true again while it is timing, ACC resets to 0 and DN just stays on.
The columns are in the same order as the off-delay relay table, because the story is the same: on, off, timing, done.
Retentive timer on. It times while the rung is true like a TON, but a false rung only pauses it: ACC holds where it stopped and picks up from there. Once DN is on it stays on, true rung or not, until a RES instruction with the same address clears it.
There is no common timer relay that does this. The closest thing on a panel is an hour meter: it keeps its count with the power off.
Pick a timer, then switch its rung true and false and watch the bits, the accumulator and the relay contacts that do the same thing. The preset is 5 seconds.
Time = preset x time base. The common bases are 1.0 s, 0.1 s, 0.01 s and 0.001 s.
| Base | Preset | Time |
|---|---|---|
| 0.1 s | 45 | 4.5 s |
| 0.01 s | 1200 | 12 s |
| 1.0 s | 90 | 90 s |
| 0.01 s | 250 | 2.5 s |
| 0.001 s | 3200 | 3.2 s |
Timer programs
Three jobs timers do on almost every machine: flash a light, delay a start, and clean up a noisy sensor. Some of them are written more than one way, so flip between the versions and compare. Every ladder here runs live. Push the buttons and watch power move through the rungs.
Full lesson: Timers Timer patterns
Counters
A counter counts false-to-true transitions of its rung, not how long the rung is true. One box in front of an eye for a minute is one count.
| Part | What it does |
|---|---|
| CTU | Adds 1 to ACC on each false-to-true transition of its rung. |
| CTD | Subtracts 1. It does not stop at zero, it goes negative. |
| PRE and ACC | The count you want, and the count so far. Counting carries on past the preset. |
| CU, CD | On while the count-up or count-down rung is true. The counter uses them to tell a new transition from a rung that is still true. |
| DN | On whenever ACC is at or above PRE. |
| OV, UN | Overflow past 32,767 counting up, underflow past -32,768 counting down. |
| RES | Clears ACC and the status bits. A counter is not reset by its rung going false, and it keeps its count through a power loss. |
Full lesson: Counters One-shots and self-resetting counters
Compare and Data
Compare instructions sit on a rung like a contact and are true or false on numbers. Data instructions move and change whole words, 16 bits at a time, not single bits.
| Instruction | True when |
|---|---|
| EQU A, B | A equals B |
| NEQ A, B | A does not equal B |
| LES A, B | A is less than B |
| LEQ A, B | A is less than or equal to B |
| GRT A, B | A is greater than B |
| GEQ A, B | A is greater than or equal to B |
A value that updates in steps can jump past an exact number. Use GEQ or LEQ for "reached or passed", and save EQU for counts that move one at a time.
Try them
LIM, the limit test
LIM has a low limit, a test value and a high limit. The limits themselves count as inside or outside.
- Low limit at or below the high limit: true when Low ≤ Test ≤ High. The usual "is it in the band" test.
- Low limit above the high limit (inverted): true when Test ≥ Low or Test ≤ High. Now it is true outside the band.
A temperature alarm that must come on at 85 or above, or at 25 or below:
MOV copies a value (a number or another word) into a destination word. Like any output instruction it runs on every scan its rung is true. ONS (one-shot) is true for one scan when the conditions in front of it go from false to true, then stays false until they go false and true again. Each ONS needs a bit of its own to remember last scan.
Bags are counted into a case. A selector sets the case size, 6 bags or 12, by moving a preset into the counter. The case full gate closes on the counter's DN, a limit test checks the case weight in grams, and a reset clears the count when the case is pulled.
- Rungs 0 and 1 load the preset: large case (I:1/10 on) moves 12 into C5:2.PRE, otherwise 6.
- Rung 2 counts one per bag. RES clears CU along with ACC, so a bag still sitting on the eye when the case is pulled would be counted again into the next case, which would start at 1 instead of 0. The ONS makes the rung true for one scan per bag, so a bag that sits there is counted once.
- Rung 3 closes the gate when C5:2 reaches its preset.
- Rung 4 turns on O:2/9 only while the weight in N7:2 is 480 to 520 inclusive.
- Rung 5 resets the count.
Number Bases
The final asks two conversions: decimal to binary, and binary to decimal. Both start from the place row.
Building the place row
Both conversions need the places written out first, and you never have to remember them. Start at the ones column and multiply by the base to get the next one going left. That is the whole rule, and it works in every base.
Decimal to binary
Biggest that fits, how many fit, what is left over, repeat. The strip below lays the places out the way you would on paper, each one the previous times the base, and the line under every place says which one it came from. Fill them left to right and watch the leftover come down to nothing.
Binary to decimal
What is the value of the place, how many are there, multiply, add them all up. The digits are given. Fill in what each place is worth in total, then the sum.
Full lesson: Number Bases Practice run
Troubleshooting
120 VAC across two rails. Wire 1 feeds a limit switch, wire 2 carries on to a pressure switch, wire 3 feeds the pilot light and wire 4 returns to neutral. A pushbutton bridges wire 1 straight to wire 3, in parallel with the two switches, so the light comes on either when LS and PS are both made, or when the button is pressed.
- Drag the red and black probes from the meter onto any two terminals.
- Click LS or PS to make or break them, they stay where you put them. The PB is momentary: hold it down.
- The wires are deliberately drawn one colour. The meter is the only thing that tells you what is live, which is the point.
- 1 to 4, everything open. That is the supply, and it is there whether anything is running or not.
- 1 to 2 with LS open, then made. A made contact puts both ends on the same wire.
- 3 to 4 with LS and PS both made. Everything the source gives you lands across the load.
- Now hold the PB instead. Same lamp, different path.
- Line side to line side, 1 to 3: the supply, 480 V, whether the starter is in or out.
- Starter pulled in, across one main contact, 1 to 2: about 0 V. A made contact puts both ends on the same wire.
- Starter pulled in, line side of one pole to load side of another, 1 to 6: 480 V, phase to phase through two made contacts.
Practice Test
Twenty-six questions across everything above, weighted toward bit status, timers, sinking and sourcing, and compare and LIM. Wrong answers explain themselves.
Sinking and sourcing are named on this page from the module's point of view, matching the Sinking vs Sourcing walkthrough in Basics: a sinking module returns current through its common to the negative rail, and pairs with a sourcing field device. Some texts name the same circuit from the field device instead, which flips the word - use the convention your instructor uses in class.