Step 7 A loop that is written on STL doesn't work.

KarlMarxStadt

Level-1
Beiträge
27
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hello there,
Could someone help me out why a loop that is written on STL doesn't work. As a template I used wide known example from documentation: https://support.industry.siemens.co...-s7-300-and-s7-400-programming?dti=0&lc=en-WW

Page 99. Chapter 6.19.
I can't get if it's working at all. And why MD20 = L#120 and so forth...
So to speak what was done wrong what wasn't done at all? Any advices?

Screenshots with CODE itself, and VAT is attached.

KMS
 

Anhänge

  • screenshots.pdf
    208,9 KB · Aufrufe: 49
Zuletzt bearbeitet:
Hello KarlMarxStadt,

I don't know what your code is supposed to do, but the loop is definitely programmed wrong. You programmed an infinite loop. Your trigger will never leave the loop and the last 4 lines of code are never executed.

You have to put the Conditions to leave the loop, inside the loop!!!

Greetz
 
No,

It is all good. The loop works perfectly.

Code:
MW10   MD20old MD20new
5      1       5
4      5       20
3      20      60
2      60      120
1      120     120

Gruß

@Thruser,
I'm glad to hear that. :D I've got that. It just executed extremely quickly.

So, how to delay properly its execution? E.g. one step 250 ms? So to speak to make visible execution.

KMS
 
Zuletzt bearbeitet:
@Thruser,
I'm glad to hear that. :D I've got that. It just executed extremely quickly.

So, how to delay properly its execution? E.g. one step 250 ms? So to speak to make visble execution.

KMS

Timer in a loop, thats not an good idea.
It's normal, that you can't se the execution, because this will be done in one cycle from the plc.
If you will see more, then you can not use the "loop" from step 7.
But the plc will every time run in a loop, thats what all plc doing.
So you can creat own code, with jumps und timers.
Create an timer, wich will fire all 1 Second for one cycle. (Timer and R-Trigger).
If the trigger shot, make somting in your code, if not, jump over this code.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Timer in a loop, thats not an good idea.
It's normal, that you can't se the execution, because this will be done in one cycle from the plc.
If you will see more, then you can not use the "loop" from step 7.
But the plc will every time run in a loop, thats what all plc doing.
So you can creat own code, with jumps und timers.
Create an timer, wich will fire all 1 Second for one cycle. (Timer and R-Trigger).
If the trigger shot, make somting in your code, if not, jump over this code.

Hmm.

Code:
[COLOR=blue]int[/COLOR] i = 0;
       [COLOR=blue]private[/COLOR] [COLOR=blue]void[/COLOR] timer1_Tick([COLOR=blue]object[/COLOR] sender, [COLOR=#2b91af]EventArgs[/COLOR] e)
       {
 
           i++;
           [COLOR=blue]if[/COLOR] (i == 100)
           {
               timer1.Stop();
           }
            
          
           textBox1.Text = i.ToString();
 
           
 
       }

timer_Tick event it's some kind of CPU cycle. I can set here any interval e.g. 500 ms.
Why Can't I do something similar it the CPU? For example by means of OB? I don't know which one has 100 ms cycle.

You're questioning the usefulness of LOOP usage on STL language. :)


KMS
 
Zuletzt bearbeitet:
Here is a little test programm with a loop (without "Loop")
All 5 Seconds it make one calculation.

Anhang anzeigen Loop_Test.AWL.txt

Delete .txt and import the function block, (Menue --> input, extern) open it and do Menue --> translate.
Call the FB in your programm (with DB) and give a free Start-Flag.

Code:
      CALL  FB     4 , DB4
       Start:=M0.0
 
@Ralle,
I did all you explained and have found that this stuff is IEC timer. By which way it makes calculations. I have no idea...:confused:



IEC_timer.jpg

KMS
 
Zuletzt bearbeitet:
Zuviel Werbung?
-> Hier kostenlos registrieren
An TON-Timer needs a rinsing edge in the input IN to start.
If input in is 5 sec. True (in your case), the output will switch to True.
To restart the timer, switch the variable on Input IN to False and to True again.
You see the timer running, if you give the output ET an variable.
Please click to the timer and then 'F1', so the help will open with the right page.
 
Zuletzt bearbeitet:
Good Morning!

IEC_timer_001.jpg
Yes, It can issue Expired Time in readable format.
But what about adjustable Time between executions of cycles? Is there any possibility to slow down that? That's the point! For instance, 5ms-500ms.
It seems it runs within OB1 cycle.


KMS
 
Zuletzt bearbeitet:
In the plc configuration, you can give under cycle/min cycle time more time, may be 25 ms.
In theis case, the plc will start all 25 ms the cycle.
But that "slow down" all processes in your plc. (stops from motors, switching valves) Timers you can't slow down, 1 Second in 1 Second at all.
It should be also possible, to work with stop points. I nerver used this and this funktion depends on the version of TIA, if I'm right.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
The slowdown of PLC, it isn't a way. :D "We purchased S7-317 2PN (25ns) -4k Euro and had done a slowdown to him to 25ms."
"Because we need to slow down one thread in a program." That sounds great!

I did some study on advanced languages which provided by Siemens.

STL - this is a parody from Siemens on high level languages.

SCL - looks much better. It seems, It have been taken one piece of Pascal (math part) and adapted for CPU needs. Because LAD and FBD are pretty poor in terms of math.
Unfortunately in this piece weren't included such useful Pascal's stuff like:
Code:
methods:

delay(1000);
sleep(1000);

Does anyone knows if SCL for TIA is richer than for Step7?

Probably someone will need a sample with FOR on SCL. Find a screenshot below.

SCL_loop.jpg

P.S. the question is still open.

KMS
 
Zuletzt bearbeitet:
PLC don't need Delay()- or Sleep()-operations. PLC have a wide variation of very easy to use timer-operations.
First you have to learn to understand how PLCs work, then you will see, with SCL you can solve your problems.

Harald
 
PLC don't need Delay()- or Sleep()-operations. PLC have a wide variation of very easy to use timer-operations.
First you have to learn to understand how PLCs work, then you will see, with SCL you can solve your problems.

Harald

if you really know, how PLC works and feel yourself like advanced PLC expert, you would offer something useful, instead of poetry writing...

KMS
 
Zuviel Werbung?
-> Hier kostenlos registrieren
... you would offer something useful, instead of poetry writing...
Harald is an expert on plc-programming indeed, but not so much an expert on poetry writing (as far as I know).
He has written so much in this forum. Ever so precise and well founded.
I'll try and say what Harald wrote to you in other words:
Plc-programs have to be very alert all the time and therefore may never sleep!
The 'philosophy' behind cyclic programming in plcs is quite a different approach to solve real-time computing.
It was develloped more or less independently from the rest of the programming world and has proved to be a useful and safe method, originally needing only a minimum of 'resources'.
Programmers, who have only been using 'high level programming languages', normally find it hard to switch to plc-programming.
But it's easy really, once you accept to part with some habits resp. expectations that are not conform with plc-programming.

Tatty-bye, Heinileini
 
Zuletzt bearbeitet:
if you really know, how PLC works and feel yourself like advanced PLC expert
I do ... :cool: ;)

But what about adjustable Time between executions of cycles? Is there any possibility to slow down that? That's the point! For instance, 5ms-500ms.
Code:
FUNCTION_BLOCK FB3
VAR_INPUT
  EnableFOR : BOOL;
END_VAR
VAR_OUTPUT
  Out : INT;
END_VAR
VAR
  i : INT;
  TON1 : TON;
  tDelay : TIME := T#500ms;
  xDelay : BOOL;
END_VAR

[COLOR="#008000"]//FOR-loop in (multi-tasking) Computer:
//  FOR i := 0 TO 9 BY 1 DO
//    delay(tDelay):
//    Out := i;
//  END_FOR;[/COLOR]

[COLOR="#008000"]//FOR-"loop" in cyclically working PLC:[/COLOR]
[COLOR="#008000"]//a PLC cannot wait inside the loop because PLCs have many things to do in the OB1-cycle[/COLOR]

  TON1(IN := EnableFOR AND NOT xDelay, PT := tDelay);
  xDelay := TON1.Q;

  IF NOT EnableFOR THEN
    i := 0;
  ELSIF xDelay AND i < 9 THEN
    i := i + 1;
  END_IF;

  Out := i;

END_FUNCTION_BLOCK

Harald
 
Hi there,
now, you have proven scientifically that you aren't Lord Byron. ;)

A_sample.jpg

That works great. That's what I need. SCL (Siemens Castrated Language (free Pascal)) rules!

regards,
and thank you very much!

P.S. one small note, I've noticed that brown colored instance DB is not editable by normal way like we usually do that (declaration view). I mean e.g., replacement i: INT with i: DINT in the code and so forth.
I've found only one way to change something inside of DB, that's deleting and creating again of that DB, of course right after changed code.

KMS
 
Zuletzt bearbeitet:
You are wrong!
SCl vs. ST is a Part of IEC61131. That's not only Siemens.

https://de.wikipedia.org/wiki/EN_61131

@Ralle,
One more time look at #12 and any programmer will tell you that SCL language is based on pure Pascal that was castrated and adapted for PLC programming.

Concerned (Siemens Castrated Language). It was my minor fiction! Actually, never mind...:D

KMS
 
Zuletzt bearbeitet:
One more time look at #12 and any programmer will tell you that SCL language is based on pure Pascal that was castrated and adapted for PLC programming.
It is correct, that SCL is inspired by Pascal in some parts, but I wouldn't say that they copied or as you wrote castrated it. As it was mentioned before the concept of a PLC is in many parts totally different to a PC, so it wouldn't have made sense to implement all things/concepts used in other languages. A PLC doesn't wait it works, that's because, if a PLC would wait a change on the inputs couldn't be recognized and outputs wouldn't be set while the program pauses. On PCs there exists an interrupt concept, which works fine on PCs, because they don't have so many components that could cause an interrupt, but a PLC could contain hundreds of inputs, so just try to imagine what will happen, if many of these inputs change there state and each of them will generate an interrupt. Another problem will be caused by analoge inputs which will generate an interrupt on the slightest signal change. All these facts will result in a nearly constantly interruption of the "normal" program, so the PLC wouldn't be able to do its work.
Concerned (Siemens Castrated Language). It was my minor fiction! Actually, never mind...:D
SCL is the name given by Siemens for the structured text language, as other mentioned it before, Siemens isn't the only one using this kind of language. On Codesys based systems (e.g. Beckhoff TwinCAT V2/V3, ABB AC500 Automation Builder) this language is called ST.
 
Zurück
Oben