How many scans to complete this Function - TIA

It also depends on WHO are reading the code, it's more common to know LAD then SCL. So to be fair, more people can read "JUMP" instructions in a LAD then can read a for loop in SCL

If someone is not able to read simple FOR (or other loop) he should not work as programmer :-D.
 
Last edited:
But seriously, both parky and drbitboy, do you really argue that JMPs and GOTOs are perfectly fine to use today .. ?


I'll say it again: there are no structured programming languages (or structured constructs), only structured programmers. The grammar/syntax is irrelevant.

TL;DR

I can make code as ugly with FOR and WHILE loops as it is possible to make it ugly with JMPs and GOTOs. If I am writing code, I need to be aware of what every instruction does, when every instruction runs, what are the possible values for every bit in the memory I am using, and what every bit is going to be in each situation I am dealing with.

It is not rational to believe that there is actually a problem with a particular instruction itself.

If you are asking if I use GOTOs when I write code, then the answer is almost never. But if you are asking if I run into situations where a GOTO would be as good as, or even better than, the elitist-preferred FOR/WHILE/REPEAT constructs, then the answer is sometimes.

Certainly in any PLC environment where only ladder is available, brute force vs. JMP is a preference, not an objective choice.

The only things that baffle me about any language (or construct or measurement system, etc.) are its proponents.
 
This addressing !?!?
"Q".Q."Fault Array"["Q".Q.[Pointers[1]]

So much going on in just a PLC address.
Someone is trying to obfuscate his code.
Or is it some kind of test ?

You do know that in TIA you can add SCL networks to LAD and FBD blocks.
Try something like this:
Code:
FOR i:= 99 TO 0 BY -1 DO
   "Alarms".Fault[i] := "Alarms".Fault[i+1] ;
END_FOR

It looks like that because I keep my test bits and registers in a separate DB named Q and within that a structure called Q and all the bits and registers are held in arrays. Didn't really think it was as bad as you suggest though. How would you go about a naming convention for something akin to this?

The real obfuscation (that wasn't the point of the initial post but as you mentioned it...) that was missed was all those rungs could of been replaced with this single move block. (at least so far as I can tell!)

Screenshot-2022-03-13-004113.jpg
 
Last edited:
If you are asking if I use GOTOs when I write code, then the answer is almost never. But if you are asking if I run into situations where a GOTO would be as good as, or even better than, the elitist-preferred FOR/WHILE/REPEAT constructs, then the answer is sometimes.

How do you avoid it, what alternatives would you use in preference to a jump or loop based command?
I often find the need for them in any array handling activities which crop up on almost every job , either for myself in testing and looking at values over time, or for customers wanting logs etc...

cheers
 
what alternatives would you use in preference to a jump or loop based command?


A FOR or WHILE construct, it saves the trouble of creating a unique name for the target of the JMP or GOTO.

But I don't delude myself into believing that by doing that way I am doing something "better." A jump, by any other name, doth stink the same.
 
No difference really in using a "case of" function either..

Different solutions require different methods of programming.
 
No difference really in using a "case of" function either..

Different solutions require different methods of programming.

It is essential that remember that there are always one thousand solutions to any programming problem,
but the only right way is mine.
 
This addressing !?!?
"Q".Q."Fault Array"["Q".Q.[Pointers[1]]

So much going on in just a PLC address.
Someone is trying to obfuscate his code.
Or is it some kind of test ?

You do know that in TIA you can add SCL networks to LAD and FBD blocks.
Try something like this:
Code:
FOR i:= 99 TO 0 BY -1 DO
   "Alarms".Fault[i] := "Alarms".Fault[i+1] ;
END_FOR
OOOO Yuck - FOR loops in control..... Not good programming Can lead to quick execution of code but can also lead to exceeding scan times. IMHO for or while loop is bad practice.
 
It looks like that because I keep my test bits and registers in a separate DB named Q and within that a structure called Q and all the bits and registers are held in arrays.
I see two issues.
1. The naming of variables is a quite personal taste. IMO, the names should be kept as short as possible, while still giving some kind of hint as to the function that the variable is used for. "Q" is a bit too short to my taste. And why Q and then Q again ?
2. Having a pointer to a DB array, where the Index is a part of the same DB can lead to some really funky problems. In STEP7 Classic you can activate a test for array limits, but that would cost both memory and cycle time. Not sure about TIA. When you just want to loop through an array, create a couple of TEMP variables.

Didn't really think it was as bad as you suggest though. How would you go about a naming convention for something akin to this?
The code sample snippet I posted is approximately how I would do it.

OOOO Yuck - FOR loops in control..... Not good programming Can lead to quick execution of code but can also lead to exceeding scan times. IMHO for or while loop is bad practice.
If you have to perform an operation on 100 variables, and there is no canned function to do that, what is your suggestion ?
 
OOOO Yuck - FOR loops in control..... Not good programming Can lead to quick execution of code but can also lead to exceeding scan times. IMHO for or while loop is bad practice.

Same risk like using any backward JUMP or loop in other language.

In TIA portal SCL is preffered language and these days computing power is much cheaper than in past. I made several projects using SCL blocks (e.g. some FIFO buffers, shifting registers, etc) and I have never encountered any significant delay in scan cycle.

Of course if you make programming error which is not handled CPU can go to STOP. But this works same for LAD, FBD, STL, SCL, ...
 
To OP's original question. You can put your code inside FB or FC block. Then on enable input put rising edge trigger of bit. (Enable input true only one scan)


If all code is executed inside block when you trigger it then only one scan is needed for code.
 
Last edited:
It also depends on WHO are reading the code, it's more common to know LAD then SCL. So to be fair, more people can read "JUMP" instructions in a LAD then can read a for loop in SCL

This is absolutely true. Programmers often act like they "own" the equipment; they forget that it is made to spend it's life in service (somewhere away from them and their support, usually).

If someone is not able to read simple FOR (or other loop) he should not work as programmer :-D.

I have over a dozen electricians in my plant that have 15+ years of going online with controllers and scanning ladder for machine issues. They are quite proficient at this. They never were intended to be called programmers, and they are the ones that own this equipment, often 20 years at a time per machine.


I was integrator for quite some time, and now I have a local plant job. It makes you see things entirely differently.
 
This is absolutely true. Programmers often act like they "own" the equipment; they forget that it is made to spend it's life in service (somewhere away from them and their support, usually).



I have over a dozen electricians in my plant that have 15+ years of going online with controllers and scanning ladder for machine issues. They are quite proficient at this. They never were intended to be called programmers, and they are the ones that own this equipment, often 20 years at a time per machine.


I was integrator for quite some time, and now I have a local plant job. It makes you see things entirely differently.


I fully agree ;) ! I also wrote "should not work as programmer". I clearly understand that some maintenance crew is not skilled as full time programmer but with long term experience I do not think it is so unreal to learn how simple cycle is working. My intention is to write mostly in LAD but sometimes using of different language is much more "nice".
 

Similar Topics

When I turn the slider all the ways down, it cannot go below 145 scans. The simulation is going way to fast for me to follow. I see others on...
Replies
2
Views
1,428
Good Evening , We have a number of Powerflex 525 Drives . I took notice for years elsewhere and our plant , that our Powerflex 525 drive...
Replies
0
Views
603
Good Afternoon, Just wondering , are many of you using SAP in your plants ? If so , is it difficult to learn ? Are there many training...
Replies
10
Views
1,396
It better to have too many instead of not enough right?
Replies
26
Views
2,823
Hi all- I have an application where: - I have a fixed system with a pre-determined, static, network (say, 192.168.2.0/24). - That system...
Replies
13
Views
4,194
Back
Top Bottom