Skip to content
PROCESIAby Aterra Ingeniería

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 ladderEn SCL
Comparator CMP >LT_101 > 2.5
Normal coilIF ... THEN ... ELSE ... END_IF;
SET and RESET coilsIF ... 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

  1. 1Write or change the code
  2. 2Tap ▶ Run and test it on the plant
  3. 3Tap ✓ Check to review it
Program · OB1 (SCL)

Ctrl + Enter runs. Your code is saved in this browser.

TK-101 tank
FCV-102 3 m2 m1 m0 1.60 m TK-101 · real level LT LT-101 AI CARD 10.4 mA LT_101_RAW 14746 LT_101 (your PLC) — P-101 XL-101 XF-101
Level1.60 m
Watch table

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:

LT_101 := SCALE_X(MIN := 0.0, VALUE := NORM_X(MIN := 0, VALUE := LT_101_RAW, MAX := 27648), MAX := 3.0);

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.

Getting tangled up with scaling? There is a full lesson, with moving rulers and other ranges such as pressure and temperature: Scaling without fear.

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.

A challenge: in exercise 4, what happens to the pilot light XL_101 if the wire breaks just when it was on? It stays stuck on, because in the fault branch nobody writes it. Would you turn it off or leave it? Add the line you decide on.

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.