LEARN · PROGRAMMING · SCL 2
SCL: IF, comparisons and 4–20 mA scaling
From contact to number: compare a tank level, write your first IFs, fix a pump that starts and stops non-stop and protect the plant if the transmitter wire breaks. In 7 short steps, with the ladder alongside.
What is new in this lesson
In lesson 1 everything was TRUE or FALSE: contacts and coils. Now a number appears: the tank level in meters, measured by the LT-101 transmitter. Two new things are done with numbers:
| In ladder | En SCL |
|---|---|
Comparator CMP > | LT_101 > 2.5 |
| Normal coil | IF ... THEN ... ELSE ... END_IF; |
| SET and RESET coils | IF ... ELSIF ... END_IF; without ELSE |
| Scaling box | * 3.0 / 27648.0 |
Just like in lesson 1: first you read and try, then you change a number and finally you write. Each exercise shows the ladder rungs, which light up while the plant runs.
Where the number comes from
The transmitter sends a current of 4 to 20 mA. The PLC's analog card converts it into an integer: 0 at 4 mA (empty) and 27648 at 20 mA (full, 3 m). That raw number is LT_101_RAW. Converting it to meters is covered in exercise 6.
See a hint
- 1Write or change the code
- 2Tap ▶ Run and test it on the plant
- 3Tap ✓ Check to review it
Ctrl + Enter runs. Your code is saved in this browser.
Scaling as in TIA Portal
In TIA Portal the usual way to scale is with two instructions: NORM_X takes the raw value to a value between 0 and 1, and SCALE_X takes it to the engineering range. This simulator understands them, so you can try it in exercise 1:
It does the same as the rule of three, but it leaves the card's range and the instrument's range written down, and that is appreciated when the transmitter is replaced by one with a different range.
Card fault values
- 27649 to 32511: overrange, the current went above 20 mA. It can be a short circuit or a miscalibrated transmitter.
- 32767: overflow or broken wire, with wire-break diagnostics enabled.
- −1 to −4864: underrange, less than 4 mA.
That is why the control of a real loop always checks the raw value before using it. If the measurement is not reliable, the plant has to go to a safe state, which here is the pump stopped.
What comes next
In lesson 3: TON and TOF timers. Delayed pump start, an alarm if the tank does not fill in time and a filter so that a wave does not trigger the alarm.
Scale your own LT-101
In Procesia the TK-101 tank has its level transmitter connected to the analog input of your real PLC or PLCSIM. Write this same SCL and watch it work in 3D. Use the full version free for 7 days, no card.