Siemens SCL counter/pulse

cjd1965

Lifetime Supporting Member
Join Date
Apr 2007
Location
UK
Posts
1,659
Hi how would I create a pulse to loop ... pseudo code

if step=1 then
do something
when something done step=2
end_if

if step=2 then
do something
counter + 1 <--------------- want this be 1 shot /pulse
end_if

if counter < 10 then step=1
 
No just want it to increment once (so counter=counter+1 each time it is in the step. basically i am doing a long list of steps, some of which have to loop back to a previous step several times so i am trying to keep track of the occasions it has been in the step with a variable and then comparing to loop back or advance a step
 
Code:
CASE step OF
    1 : Do something
    2 : IF (NOT oldStep)
           THEN
               counter := counter+1;
        END_IF;
        oldStep := true;

        On transition to next step
        oldStep := false;        

    3 : Do something
END_CASE;
 
NO No

Code:
CASE NewState OF
   0:                          // STATE 0
       IF OldState <> NewState
                               // DO OTHER ON ENTRY CODE HERE  
          OldState = NewState   
       END_IF
                               // DO CODE THAT GET EXECUTED EVERY SCAN HERE.  POSSIBLY CHANGE NewState TO THE NEXT STATE     
                              
       IF OldState <> NewState THEN
                               // DO CLEAN UP CODE FOR CURRENT STATE ON EXITING STATE 
 
       END_IF
   1:                          // STATE 1
       IF OldState <> NewState
                               // DO OTHER ON ENTRY CODE HERE  
          OldState = NewState   
       END_IF
                               // DO CODE THAT GET EXECUTED EVERY SCAN HERE.  POSSIBLY CHANGE NewState TO THE NEXT STATE     
                              
       IF OldState <> NewState THEN
                               // DO CLEAN UP CODE FOR CURRENT STATE ON EXITING STATE 
 
       END_IF
   2:                          // STATE 2
       IF OldState <> NewState
                               // DO OTHER ON ENTRY CODE HERE  
          OldState = NewState   
       END_IF
                               // DO CODE THAT GET EXECUTED EVERY SCAN HERE.  POSSIBLY CHANGE NewState TO THE NEXT STATE     
                              
       IF OldState <> NewState THEN
                               // DO CLEAN UP CODE FOR CURRENT STATE ON EXITING STATE 
 
       END_IF
   3:                          // STATE 3
       IF OldState <> NewState
                               // DO OTHER ON ENTRY CODE HERE  
          OldState = NewState   
       END_IF
                               // DO CODE THAT GET EXECUTED EVERY SCAN HERE.  POSSIBLY CHANGE NewState TO THE NEXT STATE     
                              
       IF OldState <> NewState THEN
                               // DO CLEAN UP CODE FOR CURRENT STATE ON EXITING STATE 
 
       END_IF
    // ADD STATES AS NECESSARY
END_CASE
 
Hi thanks for the replies.
I have ripped my code back to use case statments which makes it easier to read. I understand the other ideas for creating a one shot type instruction by using a step flag

Turbo Upo are you working on a big project for this ?

Cheers
 
No, just some practice progs on SCL. havent actually started the sequencer yet. That was my first idea that came to mind. Peters is lot better :D, going to do it like it when I have time to do it. Or maybe better said, when I have time for priority class where those practice programs belong ;) (ppl usually get what they really want, also ppl have time for things they really want to do. That does not exclude that sometimes something needs to be done before something that would be more pleasant to do).

http://www.plctalk.net/qanda/showthread.php?t=54195
 
Last edited:
Hopefully cjd1965 does mind being "pushed" a long

If the state must be executed in a certain amount of time a timer should be started in the ON_ENTRY section of the code. The timer should be checked in the part of the scan that is executed every scan the state is executed. There may a potential fourth IF ON_TIMEOUT THEN section. On a timeout an error code, error message number is written to variable that is read by an HMI and displays an error message. Now when there is a hangup because some limit switch didn't get hit and error message can be displayed that tells the operator why the machine stopped.

Therefore each state could have a
ON_ENTRY
DO_EVERY_SCAN
ON_TIMEOUT
ON_EXIT

Can anybody think of something more?

When you guys are ready I will show you how to do parallel tasking but at this point it is probably easier to use ST inside of SFC.

Note, I am not really a SCL programmer. I just now something about writing state machines. SCL is just the tool.

cjd1965 and/or TurpoUrpo should start a thread about writing ST/SCL state machines. The problem with this thread is that no one will find this information because of the title.
 
How do you do paralell tasking using State machines??

One way is to program a system of state machine and start another state machine with the other and use a interface between these state machines.. But I for one are really curios how you Peter does this??
 
It is easy. Just more of the same piled higher and deeper.

How do you do paralell tasking using State machines??

One way is to program a system of state machine and start another state machine with the other and use a interface between these state machines.. But I for one are really curios how you Peter does this??
Start a new thread
State Machines in SCL or ST
I don't like posting the same thing over and over and over and over again. No one will find this information if it doesn't have a title that people will search for and recognize.

I am getting grumpier and grumpier. Perhaps a fixed section of "The Best of Peter Posts" is needed.
 

Similar Topics

Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,071
Hi All, I need to try and convert some code from Siemens SCL (TIA16) over to Allen Bradley RS5000. I have attached an image of the SCL and what...
Replies
10
Views
4,057
in the scl code written in screenshot Line 1 condition is false but still the program checking the line 2 condition and says it is true i had...
Replies
3
Views
1,760
I am new to PLC programming. Is there a standard way to incorporate alarms / warnings / events such as the exceptions in C++ or Java where you can...
Replies
5
Views
1,979
Hello All, I am new to programming with Tia Portal and I am having difficulty with something that we have found "easy" in other programming...
Replies
3
Views
2,379
Back
Top Bottom