RSLogix 5000 – Structured Text Programming Examples
Thank you for visiting,
My name is Shane Welcher and have put together a few helpful videos to show anyone willing to learn how to program using structured text an easy way to get a base foundation of how things work.
I have over 18 years of working with Rockwell Automation software and I have seen many different processes of when Rockwell changes their control platform in which I have found that is important to understand the core features of programming to give you the cutting edge of any change that happens.
If you have never done any structured text programming before, maybe you have a base understanding of how the different methods work such as a For Do, While Do, If, Else, Then, Case, or calling a JSR from a structured text program or routine. Understanding this language of RSLogix 5000 is only one of the four ways of programming that Rockwell Automation offers in its software.
RSLogix 5000 structured text is not like standard RSLogix 5000 instruction sets such as ladder logic or function blocks but can be used with any of the other programming types to make a system work better.
Also, here is a good resource from the software developers for Rockwell but I will add that it is a lot of reading just to get the value that I show, here is the link to Rockwell Automation Structured Text programming.
To cut straight to the chase, let’s get to the videos that I have made for you about structured text programming.
RSLogix 5000 Structured Text Example for…If..Then…Else..
The video below shows one of the five structured text programs, this will be the using the If, Else, Then construct to give the foundation of how to get a base understanding.
At the end of the video, I will give you a detailed reason why I showed the system the way I did, and believe me when I say if you want to see more then I will be glad to show you a more advanced method but this video is designed to give a base foundation.
In this video, I show the system being written on a Rslogix 5000 software with an emulation of the process. I chose to use a simple state transition to limit the confusion of the logic theory vs the actual If, Then, Else process which is the major point of the video. When it comes to logical theory, the sky s the limit…If you can think it logically then you can program it.
I show the use of the watch feature of structured text programming to give you a troubleshooting tool in which to see the tags updating in real-time as you are programming it or even if you have an existing machine using structured text.
An Example of this is:
IF PB1 Then PB1_Light :=1;
elsif Not PB1 Then PB1_Light :=0;
end_if;
IF PB2 Then PB2_Light :=1;
elsif Not PB2 Then PB2_Light :=0;
end_if;
In this example, whatever the value of the zzzSubstitute_Me tag is then the value of the zzzInstance tag will change to the corresponding value of the statement.
IF zzzSubstitute_Me Then zzzInstance :=1;
elsif Not zzzSubstitute_Me Then zzzInstance :=0;
end_if;
This is again, a very basic example of how this works to give you a base understanding of how the If, Then, Else construct works.
RSLogix 5000 Structured Text Example for a Case Construct
The video below shows the Case construct, the effort is to give a solid foundation of how to get a base understanding. At the end of the video, there will be a description of what the common uses of a Case construct are done and as always….any questions or concerns then please let me know.
After watching the video I want to break down what are some of the common reasons for using a Case construct of structured text programming in RSlogix 5000. The Case construct is most commonly used for a simple and quick transition between state machine logic functions so with that being said if you have a case of an instance then the routine will quickly shift to whatever the case function is indicating.
An example of this is:
Case zzzSubstitute_Me of
0: zzzInstance_of:=0;
1: zzzInstance_of:=10;
2: zzzInstance_of:=20;
3: zzzInstance_of:=30;
4: zzzInstance_of:=40;
5: zzzInstance_of:=50;
6: zzzInstance_of:=60;
7: zzzInstance_of:=70;
End_Case;
In this example, if the zzzSubstitute_Me has a value of 2 then the zzzInstance_of would be 20 but at any given time the zzzSubstitute_Me tag changes then the value of the zzzInstance_of tag. This is again, a very basic logic example of how a Case constructs and is meant to give you a base without causing confusion by adding complex logic added to the Case Logic example.
RSLogix 5000 Structured Text – While…Do Function
The video below shows the While Do construct, the video breaks down the structure of how a While Do construct should be logically laid out from what is acceptable for the RSLogix 5000 software.
At the end of the video, there will be a description of what I used for this example of a While Do construct….any questions or concerns then please let me know.
After watching the video I want to break down the use of a While Do construct of structured text programming in RSLogix 5000. The While Do construct can be used for many different applications and really depends on the preference of who is programming on what they are trying to accomplish so with that being said if you have a While Do instance then the routine will quickly shift to whatever the Do function that is indicating.
An example of this is:
While zzzSubstitute_Me_0 And Not zzzSubstitute_Me_1 Do
zzzInstance_of:=0:
Exit;
End_While;
While zzzSubstitute_Me_1 And Not zzzSubstitute_Me_2 Do
zzzInstance_of:=1:
Exit;
End_While;
While zzzSubstitute_Me_2 And Not zzzSubstitute_Me_3 Do
zzzInstance_of:=2:
Exit;
End_While;
While zzzSubstitute_Me_3 And Not zzzSubstitute_Me_4 Do
zzzInstance_of:=3:
Exit;
End_While;
While zzzSubstitute_Me_4 And Not zzzSubstitute_Me_5 Do
zzzInstance_of:=4:
Exit;
End_While;
While zzzSubstitute_Me_5 And Not zzzSubstitute_Me_6 Do
zzzInstance_of:=5:
Exit;
End_While;
While zzzSubstitute_Me_6 And Not zzzSubstitute_Me_0 Do
zzzInstance_of:=6:
Exit;
End_While;
In the example above, if the value of the tag zzzSubstitute_Me_3 transitions from 0 to 1 meaning it is made and the value of tag zzzSubstitute_Me_4 is a value of 0 and not a value of 1 then the value of the tag zzzInstance_of will equal a value of 3. In a While…Do function it is important to use the Exit command so that you do not eat up your processor time and bog down the system scan rate. This is again, a very basic example of how this works to give you a base understanding of how the While…Do construct works.
If you were to use this same code but replace the tags starting in zzz with your tags then you could run this simple model yourself.
Further explained down to the data type:
While Bool And Not Bool Do
Dint:=0:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=1:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=2:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=3:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=4:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=5:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=6:
Exit;
End_While;
Basically, I wanted to show what data types can be used but are not limited to so that you see what data types are commonly used.
RSLogix 5000 Structured Text Array Use- For…Do…Example
Here is a video that I made to give a small example of a For…Do construct, this construct of structured text is more commonly used with an array with an indirect addressing scheme to solve system values in a very short piece of code.
While this is not the most direct way to allow someone to troubleshoot, it does give the programmer a short and sweet way to get straight to the point with having to write a lot of structured text and in reference to RSLogix 5000 Structured Text array uses.
Plus learning indirect addressing is a very helpful piece, as it is used in a much different application of PLC programming.
So now that you have watched the video, I would like to address the simple but complex way of using the For…Do construct. Using this process has helped me make a cookie-cutter system with the variability of a complex array indexed method of having an outcome very quickly and efficiently without having to write a lot of code.
An example of this is:
If zzzStart Then
For zzzInstance_of:= 0 to 6 Do
zzzSubstitute_Me[zzzInstance_of]:= zzzSubstitute_Me[zzzInstance_of] + 1;
End_For;
If zzzSubstitute_Me[zzzInstance_of]> 6 Then
For zzzInstance_of:=0 to 6 Do
zzzSubstitute_Me[zzzInstance_of]:=0;
End_For;
End_If;
In this example, if the zzzStart value is equal to 1 then the array zzzInstance_of will index from 0 to 6 until it is greater than 6 then it will reset to a value of zero.
Further explained down to the data types:
If bool Then
For Array:= 0 to 6 Do
Array[Dint]:= Array[Dint] + 1;
End_For;
If Array[Dint]> 6 Then
For Dint:=0 to 6 Do
Array[Dint]:=0;
End_For;
End_If;
So if the bool is a value of 1 then the process starts. For array index 0 through 6 add a value of 1 to the array but if greater than 6 then set to a value of zero and continue the progress.
RSLogix 5000 Structured Text ST…JSR…ST…Timer Uses
This section shows the use of structured text for a JSR or jump to subroutine and a standard timer feature. This is a bonus to show several different methods that can be used in structured text programming so you do not feel limited to just using the natural constructs.
You can also program a servo from not running to a fully running system which I can show if you would like but for this video, I have shown the basics of a JSR and a timer to save time.
An example of this is:
JSR(zzzSubRoutine);
zzzTimer.Pre:=5000;
zzzTimer.TimerEnable:=zzzTimer_Control;
TONR(zzzTimer);
zzzTimer.Reset:= zzzTimer.dn;
In this example, the JSR is calling for zzzSubRoutine to be active or start scanning then set the zzzTimer preset to 5000 ms and if the zzzTimer_Control value is set to a 1 then free run the timer. Upon the timer timing, out then reset the timer and start the process over and continue running.
Summary of what has been used so far is a baseline of what can be used to be successful in using each of these constructs in RSLogix 5000 structured text programming.
I will be putting together more programming videos and article upon request, I already have several ideas and will be starting to add more videos to my YouTube channel which is Shane Welcher RSlogix 5000 Programming
I would love to hear what you guys think so far as I am trying to get this website whipped into shape.
Drop me a comment here or on my YouTube channel.
Thanks,
Shane
RSLogix 5000 – Structured Text Programming Examples
Thank you for visiting,
My name is Shane Welcher and have put together a few helpful videos to show anyone willing to learn how to program using structured text an easy way to get a base foundation of how things work.
I have over 18 years of working with Rockwell Automation software and I have seen many different processes of when Rockwell changes their control platform in which I have found that is important to understand the core features of programming to give you the cutting edge of any change that happens.
If you have never done any structured text programming before, maybe you have a base understanding of how the different methods work such as a For Do, While Do, If, Else, Then, Case, or calling a JSR from a structured text program or routine.
Understanding this language of RSLogix 5000 is only one of the four ways of programming that Rockwell Automation offers in their software. RSLogix 5000 structured text is not like standard RSLogix 5000 instruction sets such as ladder logic or function blocks but can be used with any of the other programming types to make a system work better.
Also, a good resource to go to is the software developers for Rockwell but I will add that it is a lot of reading just to get the value that I show here but here is the link to Rockwell Automation Structured Text programming.
To cut straight to the chase, let’s get to the videos that I have made for you about structured text programming.
RSLogix 5000 Structured Text Example for…If..Then…Else
The video below shows one of the five structured text programs, this will be using the If, Else, Then construct to give the foundation of how to get a base understanding.
At the end of the video, I will give you a detailed reason why I showed the system the way I did, and believe me when I say if you want to see more then I will be glad to show you a more advanced method but this video is designed to give a base foundation.
In this video, I show the system being written on a Rslogix 5000 software with an emulation of the process. I chose to use a simple state transition to limit the confusion of the logic theory vs the actual If, Then, Else process which is the major point of the video.
When it comes to logical theory, the sky s the limit…..If you can think it logically then you can program it.
I show the use of the watch feature of structured text programming to give you a troubleshooting tool in which to see the tags updating in real-time as you are programming it or even if you have an existing machine using structured text.
An Example of this is:
IF PB1 Then PB1_Light :=1;
elsif Not PB1 Then PB1_Light :=0;
end_if;
IF PB2 Then PB2_Light :=1;
elsif Not PB2 Then PB2_Light :=0;
end_if;
In this example, whatever the value of the zzzSubstitute_Me tag is then the value of the zzzInstance_of tag will change to the corresponding value of the statement. This is again, a very basic example of how this works to give you a base understanding of how the If, Then, Else construct works.
IF zzzSubstitute_Me Then zzzInstance :=1;
elsif Not zzzSubstitute_Me Then zzzInstance :=0;
end_if;
RSLogix 5000 Structured Text Example for a Case Construct
The video below shows the Case construct, the effort is to give a solid foundation of how to get a base understanding. At the end of the video, there will be a description of what the common uses of a Case construct are done and as always…any questions or concerns then please let me know.
After watching the video I want to break down what are some of the common reasons for using a Case construct of structured text programming in RSlogix 5000.
The Case construct is most commonly used for a simple and quick transition between state machine logic functions so with that being said if you have a case of an instance then the routine will quickly shift to whatever the case function is indicating.
An example of this is:
Case zzzSubstitute_Me of
0: zzzInstance_of:=0;
1: zzzInstance_of:=10;
2: zzzInstance_of:=20;
3: zzzInstance_of:=30;
4: zzzInstance_of:=40;
5: zzzInstance_of:=50;
6: zzzInstance_of:=60;
7: zzzInstance_of:=70;
End_Case;
In this example, if the zzzSubstitute_Me has a value of 2 then the zzzInstance_of would be 20 but at any given time the zzzSubstitute_Me tag changes then the value of the zzzInstance_of tag.
This is again, a very basic logic example of how a Case constructs and is meant to give you a base without causing confusion by adding complex logic added to the Case Logic example.
RSLogix 5000 Structured Text – While…Do Function
The video below shows, the While Do construct, the video breaks down the structure of how a While Do construct should be logically laid out from what is acceptable for the RSLogix 5000 software. At the end of the video, there will be a description of what I used for this example of a While Do construct…any questions or concerns then please let me know.
After watching the video I want to break down the use of a While Do construct of structured text programming in RSlogix 5000.
The While Do construct can be used for many different applications and really depends on the preference of who is programming on what they are trying to accomplish so with that being said if you have a While Do instance then the routine will quickly shift to whatever the Do function that is indicating.
An example of this is:
While zzzSubstitute_Me_0 And Not zzzSubstitute_Me_1 Do
zzzInstance_of:=0:
Exit;
End_While;
While zzzSubstitute_Me_1 And Not zzzSubstitute_Me_2 Do
zzzInstance_of:=1:
Exit;
End_While;
While zzzSubstitute_Me_2 And Not zzzSubstitute_Me_3 Do
zzzInstance_of:=2:
Exit;
End_While;
While zzzSubstitute_Me_3 And Not zzzSubstitute_Me_4 Do
zzzInstance_of:=3:
Exit;
End_While;
While zzzSubstitute_Me_4 And Not zzzSubstitute_Me_5 Do
zzzInstance_of:=4:
Exit;
End_While;
While zzzSubstitute_Me_5 And Not zzzSubstitute_Me_6 Do
zzzInstance_of:=5:
Exit;
End_While;
While zzzSubstitute_Me_6 And Not zzzSubstitute_Me_0 Do
zzzInstance_of:=6:
Exit;
End_While;
In the example above, if the value of the tag zzzSubstitute_Me_3 transitions from 0 to 1 meaning it is made and the value of tag zzzSubstitute_Me_4 is a value of 0 and not a value of 1 then the value of the tag zzzInstance_of will equal a value of 3.
In a While…Do function it is important to use the Exit command so that you do not eat up your processor time and bog down the system scan rate. This is again, a very basic example of how this works to give you a base understanding of how the While…Do construct works.
If you were to use this same code but replace the tags starting in zzz with your tags then you could run this simple model yourself.
Further explained down to the data type:
While Bool And Not Bool Do
Dint:=0:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=1:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=2:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=3:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=4:
Exit;
End_While;
While BoolAnd Not Bool Do
Dint:=5:
Exit;
End_While;
While Bool And Not Bool Do
Dint:=6:
Exit;
End_While;
Basically, I wanted to show what data types can be used but are not limited to so that you see what data types are commonly used.
RSLogix 5000 Structured Text Array Use- For…Do…Example
Here is a video that I made to give a small example of a For…Do construct, this construct of structured text is more commonly used with an array with an indirect addressing scheme to solve system values in a very short piece of code.
While this is not the most direct way to allow someone to troubleshoot, it does give the programmer a short and sweet way to get straight to the point without having to write a lot of structured text and in reference to RSLogix 5000 Structured Text array uses.
Plus learning indirect addressing is a very helpful piece, as it is used in a much different application of PLC programming.
So now that you have watched the video, I would like to address the simple but complex way of using the For…Do construct. Using this process has helped me make a cookie-cutter system with the variability of a complex array indexed method of having an outcome very quickly and efficiently without having to write a lot of code.
An example of this is:
If zzzStart Then
For zzzInstance_of:= 0 to 6 Do
zzzSubstitute_Me[zzzInstance_of]:= zzzSubstitute_Me[zzzInstance_of] + 1;
End_For;
If zzzSubstitute_Me[zzzInstance_of]> 6 Then
For zzzInstance_of:=0 to 6 Do
zzzSubstitute_Me[zzzInstance_of]:=0;
End_For;
End_If;
In this example, if the zzzStart value is equal to 1 then the array zzzInstance_of will index from 0 to 6 until it is greater than 6 then it will reset to a value of zero.
Further explained down to the data types:
If bool Then
For Array:= 0 to 6 Do
Array[Dint]:= Array[Dint] + 1;
End_For;
If Array[Dint]> 6 Then
For Dint:=0 to 6 Do
Array[Dint]:=0;
End_For;
End_If;
So if the bool is a value of 1 then the process starts. For array index 0 through 6 add a value of 1 to the array but if greater than 6 then set to a value of zero and continue the progress.
RSLogix 5000 Structured Text ST…JSR…ST…Timer Uses
This section shows the use of structured text for a JSR or jump to subroutine and a standard timer feature.
This is a bonus to show several different methods that can be used in structured text programming so you do not feel limited to just using the natural constructs.
You can also program a servo from not running to a fully running system which I can show if you would like but for this video, I have shown the basics of a JSR and a timer to save time.
An example of this is:
JSR(zzzSubRoutine);
zzzTimer.Pre:=5000;
zzzTimer.TimerEnable:=zzzTimer_Control;
TONR(zzzTimer);
zzzTimer.Reset:= zzzTimer.dn;
In this example, the JSR is calling for zzzSubRoutine to be active or start scanning then set the zzzTimer preset to 5000 ms and if the zzzTimer_Control value is set to a 1 then free run the timer. Upon the timer timing, out then reset the timer and start the process over and continue running.
Summary of what has been used so far is a baseline of what can be used to be successful in using each of these constructs in RSLogix 5000 structured text programming.
I will be putting together more programming videos and article upon request, I already have several ideas and will be starting to add more videos to my YouTube channel which is Shane Welcher RSlogix 5000 Programming
I would love to hear what you guys think so far as I am trying to get this website whipped into shape.
Drop me a comment here or on my YouTube channel.
Thanks,
Shane
Check out our training center to see what we have to offer
Check out our training center to see what we have to offer
Online PLC Support Training Video Minutes Taught
I love your channel! Your info is so valuable and your videos are so easy to understand. I was very unfamiliar on this subject but once I visited your page I learned a lot about logic controls. Also where can I ask for help? Sometimes I get stuck on certain topics and need assistance. Do you recommend any other sites guides or forums?
Neil,
Glad to help out in any way, if you need further help with RSlogix 5000 or any FactoryTalk issues and you do not have an account with Rockwell Automation then feel free to reach out to me as I will create and make videos to help everyone learn.
Other website and actually a Rockwell Automation account cost several thousands per year but this is the primary reason that I started OnlinePLCSupport.com to aid anyone trying to start having a career in electrical and programming.
I know and understand the struggle of trying to learn how to program without training or the high cost of training and believe me…it is very expensive to do so. I offer free training and very low cost person to personal training to help people grow in the industry that is always growing so it is best for us to stay on top of thing.
Just send me an email and i will be glad to invite you to my low-cost training or if you want, just drop me a line here and I will be glad to make a video training on any subject that you would like to know.
Visit my YouTube channel at https://www.youtube.com/channel/UC3B7gA1HAcbuPZOkBklFwuA
Thanks,
Shane Welcher
Wow, this is a really interesting site. I’m a PC tech by trade, and while I’m pretty adept at the hardware and software side of things, I’ve got no idea how to program and I’ve always wanted to learn. I like the way you explain things, and I think if you were to offer a step-by-step course or eBook or something it would really sell well – I’d certainly buy it!
Jack,
First I would like to say thank you for visiting OnlinePLCSupport.com and for you comment. I aim to make this website a “go-to” place for anyone willing to learn PLC and HMI programming. I am in the works of making a step-by-step training course but will be getting more active with the work as soon as I get back from RSTechEd 2017.
This conference starts June 11th and is always a year’s worth of training wrapped up into a week.
Thanks,
Shane
Great post.
Really well written and you made a technical subject of structured based programming easy to follow.
I write Excel VBA code to create macros on Excel spreadsheets and I use structured programming such as IF THEN ELSE code.
Your post will help other people wanting to know more about programming. The video you created was great as well.
Well done.
Thanks for your post.
Harjit,
Thank you for the comment, and just as you said, I hope that my post helps people learn how to program structured text using RSLogix 5000 or any type of software that uses coding like this. To be honest, a lot of software is highly similar.
I am always glad to help people and feel like this is my way of giving back, there truly is no profit in this but the enjoyment of helping others.
Thanks,
Shane
Hello, I have always wanted to know about software and programming but I have not entered that field of study yet but I plan to do so when I come up with an idea of a video game or an application. Without doubt your information is very interesting I will have in mind to return to the site when I need it 🙂
Alexander,
That is great to hear, just about all software works with the same flow pattern and is all about logic so it is best to start out with just learning how to think logically….meaning if you can think it then you can program it but make sure you do heavy testing to make sure what you are doing doesn’t have any bugs…if so then just work them out.
Much success to you my friend,
Shane
Very cool! I have never done programming before but I would like to as it seems fun and interesting. I always like learning new things on computers and programming would give me that satisfaction. I like how you incorporate videos. You make programming seem fun and easy! Thanks for sharing.
Rob,
Thanks for the comment.
When it comes to programming, it is fun to turn nothing into a running machine or process that runs to help automate something. Working with computers is beginning to become common knowledge between jobs because of autonomy.
For me, this is what I love to do and am always happy to help anyone willing to learn RSLogix 5000 or HMI systems along with servo controls.
Thanks,
Shane
Great work.
Can you tell anything about memory consumption when it come to st?
I think it take a lot of space. Does it use more space that traditional ladder?
Structure text doesn’t use more memory than ladder, in fact it is faster in scanning.
If you are worried about memory usages then use periodic task and then the monitor tool
to determine the CPU utilization.
I hope that helps.
Actually structure text is the fastest programming language in my opinion.
The memory use depends on the tag data.
The most memory consuming data structure by default is an ALMD or ALMA
I wouldn’t worry about structure text using a lot of memory
I have Scale and Limit function used in Codesys
How to Convert it to Studio Logix Structure text statement
DYN_BKPT := SCL (SPDSP_TRK, 0.0, 100.0, V_POINT, 100.0);
Duplicate what you built in Studio 5000, there is no convert tool from software to software
Hi,
This is Tamilslevan from India,
Can you provide some discount for this course.
Sure thing, here is a 25% off discount to help.
Click below to use the discount
The Most Complete PLC Training
Thanks,
Shane