ST, best learning resource

Trying to diversify into Structured Text.
other than brute forcing it by converting some small structures from ladder, which I will anyway.

Is there any decent resources to fully get my head around the syntax. Be nice to learn it properly.
 
Syntax isn’t really the problem to solve.

Every language has its own and a big part of PLC programming in particular is understanding that there are going to be functionally equivalent counterparts among potentially several languages on any given system at once.

The most common example I can think of is the one you may have learned first: assignment.

In ST, this is straightforward:

Code:
a := b; // “a is assigned b”

In LD, it’s expressed:

Code:
MOVE b a

There we assumed that an and b were of some of the INT or REAL types. If they are BOOL, ST has already made easy work of this:

Code:
a := b; // “a is assigned b”

In LD, not so much:

Code:
MOVE b a // “error on rung 0, invalid operand(s)”

Okay, in LD we can replicate the ST bool assignment with a contact and coil:

Code:
XIC a OTE b // seems easy enough

What if we started from an ST if…then…end_if construct?

Code:
if b then
   a := 1; “a is assigned 1”
end_if;

Code:
XIC b OTE a; // super easy, super wrong

Oof, let’s try a latch, instead:

Code:
XIC b OTL a // nailed it

If the ST logic expands in the future:

Code:
if b then
  a := 1; // “a is assigned 1”
else
 a := 0; // “a is assigned 0”
end_if;

Code:
XIC b OTL a // failed it

We need to include complementary logic:

Code:
XIC b OTL a
XIO b OTU b // nailed it

Or the coil can return:

Code:
XIC b OTE a; // easy

Can we simplify the ST knowing that?

Code:
a := b; // yep, “a is assigned b”

A new need brings expanded ST:

Code:
a := b OR c; // nice!

Coil instruction, right?

Code:
XIC b OTE a
XIC c OTE a // not nice at all

Hmmm, let’s bring in branching:

Code:
BST XIC b NXB XIC c BND OTE a // nice!

Is it better with a latch?

Code:
BST XIC b NXB XIC c BND OTL a // not yet!

We need complementary logic again:

Code:
BST XIC b NXB XIC c BND OTL a
XIO b XIO c OTU a // nailed it

Can we restructure ST knowing that?

Code:
if b then
   a := 1;
elsif c then
   a := 1;
end_if; // failed it

We need to expand it:

Code:
if b then
   a := 1;
elsif c then
   a := 1;
else
  a := 0;
end_if; // nailed it

Overly verbose (and slow), let’s clean it up:

Code:
if b OR c then
   a := 1;
else
   a := 0;
end_if; // still not the best, but it works

What if we’re perusing our logic and think, hey this thing would look great in ST:

Code:
BST XIC b NXB XIC c NXB XIC a BND XIO d OTE a

We could try this:

Code:
if b OR c OR a OR NOT d then // oops
   a := 1;
end_if;

Simple mistake, we just need an AND?

Code:
if b OR c OR a AND NOT d then // oops
   a := 1;
end_if;

Okay, we need to establish precedence:

Code:
if (b OR c OR a) AND NOT d then
   a := 1; “a is assigned 1, forever”
end_if; // oops

Ah, we need precedence AND a branch in ST:

Code:
if (b OR c OR a) AND NOT d then
   a := 1; “a is assigned 1”
else
   a := 0; “a is assigned 0”
end_if;

Seems overly verbose again.

Can we do LD “seal-in circuits” in tidy ST?

Code:
a := (b OR c OR a) AND NOT d; // yes

Could it be more easily understood?

Code:
a := (a OR (b OR c)) AND NOT d; // possibly

… and this is just the beginning.

Writing syntax is the easy part.

Writing working code is harder.
 
I sell Arduino PLCs and PLC trainers, you can program them in 6 languages, buy one and then you can compare them as you go... drbitboy helped me write programs in 5 languages for a comparison when I first started selling them

They are a good cheap way to learn and you can see them run
 
Resources for learning ST has been difficult in my experience. Interested to see if anyone provides any.

I am somewhat proficient at this point, but learning other text based languages in school was what got me rolling.
 
If you use CCW, I think Spectrum Controls has some good examples in ST for some of the modules. I've used 2080sc-NTC and 2080sc-IF4U. Both of these have a well developed ST program downloadable to support the modules. I suspect other modules do too.
 
The main reason for ST being one of the mainstream (or at least what they want) is to try & make code portable.
This is fine however, most PLC's have specific functions that are not compatible even down to how they are named or what parameters & the way they work. ST is great for maths & for/next loops but there is no real reason to use it for Boolean operations, in fact it becomes a pain, Siemens STL was very close to ST in many ways. I have used ST code & tried to re-use in another platform & TBH it would have been just as quick to re-write it. As Peter posted, ST was based loosely on Pascal & that is also something I used many times & preferred it to C.
My advice is yes learn it (not difficult) as most IDE's should have simple help that show both the LAD/FBD & ST use.
I believe it is quicker to code bool & other functions in ladder or FBD however, ST is great for maths & for/next loops.
Most maintenance team members will be able to go on-line & see what is happening in LAD/FBD but find it more difficult to understand the ST RLO's, simple graphics that show the status of a rung is far easier than monitoring the equivelent in ST.
One of the last projects I did before retiring I was told that it had to be written in ST by the projects manager of the company, when I asked why his answer was I want it in the latest language (however, to be honest he did not have a clue other than what he had read about the trending in PLC's), No problem but did I get some stick from the maintenace team & after some internal heated meetings (of which I was only part of) the projects manager had been replaced, I was given the task of re-writing in LAD/FBD.
 
Agree with all that has been said here. As someone who has experience (i.e. beyond "Hello World!") in perhaps two dozen languages, my gut feel is that if you have experience in assembly and/or machine code (which is what ladder is, mostly), then the rest is like learning a spoken language: syntax; grammar; vocabulary. You mention the first in Post #1, but the latter is hardest because the other two are so limited and consistent.

If you cannot find anything specific to ST, then perhaps look for something in Python, which seems pretty close*, and there might be something that will give you an idea, and also lead you into OOP and other principles.
 
ST in a PLC program is like a piece of computer programming embedded in your program.

And to learn it, there's nothing better than practicing with computer programming languages like Java, C, C#, Pascal, and even Visual Basic.

I don't recommend Python because I don't like it. ;)
 
Trying to diversify into Structured Text.
other than brute forcing it by converting some small structures from ladder, which I will anyway.

Is there any decent resources to fully get my head around the syntax. Be nice to learn it properly.
You have two things at play here.
  • Learning how to program
  • Learning ST syntax

To learn how solve problems using ST is mostly about how to use a structured programming language. It's the same principle in most languages so any programming experience will be handy. It could be javascript, python, php, c#, visual basic or whatever.

Almost all PLC manufacturers have resources online and courses. But they are mostly about learning the syntax of ST and not learning how to program.

It's the same thing when it comes to ladder. Most resources doesn't actually teach you how to solve problems - they only teach you the tools you can use to solve problems.

When it comes to learning I wouldn't spend a second of my time converting ladder to ST.
If a problem can easily be solved in ladder, why would you use ST?

In Siemens you can switch programming language on a line by line basis. So you can do a couple of lines of ladder and then a write some ST code. I don't know if all manufacturers have that ability but you could at least do it on a block by block basis. Having the ability to switch allows you to use what is appropriate for the job.

My template for picking languages is basically to use ladder for everything that is simple and use ST for everything that is complex.

So a simple machine might be programmed primarily in ladder but all the recipe functions and data manipulation is done in ST.

This example is a simple self latching motor output controlled by a start and stop button. But I'd rather do this in ladder because it's easier to read and easier to see what is happening when running.
Code:
motor:=(start_button or motor) and not stop_button;

Finally I'd like to say if you know how to program there is really no need for any ST resource besides the official documentation from the manufacturer. The syntax is clearly laid out in there. I'm thinking about things like how to write if..then..else or a case statement or how to use arrays.
 
"motor:=(start_button or motor) and not stop_button;"
Not on my shift it's
"motor:=(start_button or motor) and stop_button;"
N/C is preferred.
Yes, that's the old school electrical engineering way of doing things. N/C was not just preferred but a must for hardwired relay logic. But there is no such thing preferred today. You can check BS 60204-1.

We use the "modern" way of doing it, which means positive logic throughout.
So pushbuttons, sensors etc that goes to a normal PLC input will have a positive (24VDC) signal when active/asserted.
So all buttons have the same N/O contact blocks - regardless of what function they have in the program. And then we use real safety circuits where it's needed.

As a side note we also scrapped red for stop buttons many decades ago. And use proper colors for stop on HMIs (never red).

When I encounter negative logic, such as your N/C stop button, I usually name them differently in the program so the name makes sense logically speaking. So your stop button might be called something like not_stop_button in the program.
In electronic schematics you put a line above a signal to indicate that it's negative logic (active low). Electrical drawings has no such standard and I never seen any standard for this in programming either so this is just my personal way of doing it.
 
I get what you are saying, & true for HMI buttons (I do not know an HMI where the button is true i.e. N/C initially).
However, if these are wired buttons a bit of a worry for the operator if a wire drops off the same with end limits in what I call soft stop, so N/C still makes sense I do know that E-stop is different & needs to be safety but still maintain that N/C is a better solution.
 
Trying to diversify into Structured Text.
other than brute forcing it by converting some small structures from ladder, which I will anyway.

Is there any decent resources to fully get my head around the syntax. Be nice to learn it properly.
I have a potential PDF that explains how structured text syntax works in the context of the PLC environment. The only downside is that it primarily focuses on Mitsubishi software. However, the fundamental concepts it covers about structured text remain applicable.





Let me know how you find it. Cheers!
 

Similar Topics

Hello All, I have recently had the opportunity to dabble in TIA portal for the first time. Been working in automation for almost a decade now and...
18
Replies
5,895
Views
What in your opinion along with on the job training are the best training books to learn about plc's. I have access to plenty of PLC's just like...
6
Replies
5,417
Views
Hello everyone, I am currently designing a redundant Ethernet network for an Allen-Bradley ControlLogix system and would appreciate some advice...
4
Replies
191
Views
We have existing logic that is totalizing discrete power pulses from the utility meter, each pulse indicating X amount of power usage. Once per...
14
Replies
513
Views
We are planning to integrate a thermal-transfer barcode label printer into an automated packaging line. The PLC should trigger label printing...
2
Replies
365
Views
Top