How to Use Structured Text to Control Speed of Drive Controls
In the case of wanting to control the speeds of a system you need options and when it comes to choosing standard ladder logic or structure text then it would be in the best interest of stable system controls to use structured text. Using ladder logic is obviously fine but reading code after code or line after line of continuous logic then it starts to run together so it is best to separate logic by programs, routines, and logic types to get the most out of the high priced processors that we use today. Along with this article to give more detail into programming this way, I added 3 helpful videos.
Videos shown in this article are:
- Structure Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 1
- Structure Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 2
- RSLogix 5000 Structure Text Speed Control Case Example
There was a point in my career when I preferred to use just ladder logic to control everything in the programs that I built however with systems getting bigger and programs getting my complex then I found that it is best to have a structure to the way you program, everyone has their own way to go about this but the key, in my opinion, is to find your own method if one is not provided for you then stick to the way you program control logix. Meaning, get a set way that you like to see things or a set layout then just slowly improvement your methods until they get better and better.
With that being said, one of my go to programming ways for instances such as constants, speed controls, and state logic is to use structured text. Whether it be a Case construct, an If…Then..Else construct, Or a While construct.
Without further ado, I would like to go ahead and show some example videos.
In this video, I show you how to set up a basic If, then, else function for simple speed controls which is a system that is designed to use an increase push button to index the speed up or a decrease push button to index the speed down. This does show the ACD file being made from scratch to give a better illustration of what process I am using to accomplish this logic simulation using RSLogix 5000 emulator.
So basically in video 1, I show you how to set up the ACD file and how to program the If, Then, Else function of the logic to be able to control speeds, however, I did not show the speed limiting factor that I will add in video 2 directly below this one. This is the show a quick representation of what can be done in a short amount of time but also gives detailed information in the video without taking up much of your time, I understand how busy we all get at times.
Structured Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 1
The full structure text code for video 1 is:
If S:FS then
SpeedReference :=0;
End_If;
// if speed increase or decrease are press then index in that direction.//
If SpeedIncreasePB Then
SpeedReference := SpeedReference + 1;
Elsif SpeedDecreasePB Then
SpeedReference := SpeedReference – 1;
else SpeedReference := SpeedReference;
End_If;
As far as the code, it is pretty simple in design but as stated is missing the speed limiting factor which will be shown in video 2.
Understanding limits and putting them to use
Controlling limits is part of making a system more reliable in design to block any chance of the system running improperly which could lead to equipment damage or even an injury.
In video 2, I pick back up exactly where I left off from video 1. Showing how to add a speed limiting factor in the system using this If, then, else function of the structure text example that was created in video 1. This speed limiting factor is very important to have as it gives the system a means to not allow the drive or servo an ability to run past a point that could possibly cause equipment damage or make the system run out of the designed method. When it comes to structure text programming, understanding how simple each construct is programmed can help you out when the time comes to fix a controls issue or even just troubleshoot it.
Without further ado here is video 2:
Structured Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 2
The full structure text code that is used in video 2 is:
// Set speed command for the drive using structure text.//
// if processor first scan then move a zero into the speed.//
If S:FS then
SpeedReference :=0;
End_If;
// if speed increase or decrease are press then index in that direction.//
If SpeedIncreasePB Then
SpeedReference := SpeedReference + 1;
Elsif SpeedDecreasePB Then
SpeedReference := SpeedReference – 1;
else SpeedReference := SpeedReference;
End_If;
// if the speed is less than zero then move a zero into the speed reference.//
If SpeedReference < 0 then
SpeedReference := 0;
End_If;
// if the speed is greater than 50 then move a 50 into the speed reference.//
If SpeedReference >= 50 then
SpeedReference :=50;
End_if;
Controlling speeds with a Structure Text Case Function
In a slightly different approach, using a Case function for speed controls can be a lot easier to read and understand but it does have its limits in which it can only do certain tasks so this example will show the structured text case construct in use controlling the speeds that were derived in video 1 and video 2. There is a quick run through of what has been done prior and then get straight into the nuts and bolts of the case function in use for controlling the speed of a system.
The Case construct is meant for simple solution applications that do not require multiple variables or paths that can be done other than being straightforward.
RSLogix 5000 Structured Text Speed Control Case Example
The full structure text code for the Case example in the video above is:
Case SpeedControl_From_HMI of
0: SpeedReference:=0;
1: SpeedReference:=10;
2: SpeedReference:=25;
3: SpeedReference:=50;
4: SpeedReference:=100;
5: SpeedReference:=150;
6: SpeedReference:=200;
7: SpeedReference:=300;
End_Case;
I have worked in the industry for some time now and have seen a lot of people that didn’t seem to know or understand every element of programming that they just started re-writing the program to their own fit which often times led to increased machine downtime along with a lot of frustration.
This is the driving force in why I have tried to put together an ever growing resource of material for anyone to go through, this is by no means saying that I feel like an expert but more lines of saying I have been fortunate to have worked with some of the leader Rockwell software engineers which have shown me quite of number of helpful tricks.
With that being said, why can’t I pay it forward and lend a hand to help others learn from the knowledge that I have been able to get? The answer is simple, yes I can help out so I truly hope what I am doing here add value to your technical ability.
So to keep this article straight to the point and not drag it out I would like to ask if you have any further questions or would like to know more then please feel free to go to my contact page and send me a message, this is the quickest way to contact me and I will get back to you as quick as possible.
Thank you for your time and let me know if I can help any further,
Shane
How to Use Structured Text to Control Speed of Drive Controls
In the case of wanting to control the speeds of a system you need options and when it comes to choosing standard ladder logic or structure text then it would be in the best interest of stable system controls to use structured text.
Using ladder logic is obviously fine but reading code after code or line after line of continuous logic then it starts to run together so it is best to separate logic by programs, routines, and logic types to get the most out of the high priced processors that we use today.
Along with this article to give more detail into programming this way, I added 3 helpful videos.
Videos shown in this article are:
- Structure Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 1
- Structure Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 2
- RSLogix 5000 Structure Text Speed Control Case Example
There was a point in my career when I preferred to use just ladder logic to control everything in the programs that I built however with systems getting bigger and programs getting my complex then I found that it is best to have a structure to the way you program, everyone has their own way to go about this but the key, in my opinion, is to find your own method if one is not provided for you then stick to the way you program control logix.
Meaning, get a set way that you like to see things or a set layout then just slowly improve your methods until they get better and better.
With that being said, one of my go to programming ways for instances such as constants, speed controls, and state logic is to use structured text. Whether it be a Case construct, an If…Then..Else construct, Or a While construct.
Without further ado, I would like to go ahead and show some example videos.
In this video, I show you how to set up a basic If, then, else function for simple speed controls which is a system that is designed to use an increase push button to index the speed up or a decrease push button to index the speed down.
This does show the ACD file being made from scratch to give a better illustration of what process I am using to accomplish this logic simulation using RSLogix 5000 emulator.
So basically in video 1, I show you how to set up the ACD file and how to program the If, Then, Else function of the logic to be able to control speeds, however, I did not show the speed limiting factor that I will add in video 2 directly below this one.
This is the show a quick representation of what can be done in a short amount of time but also gives detailed information in the video without taking up much of your time, I understand how busy we all get at times.
Structured Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 1
The full structure text code for video 1 is:
If S:FS then
SpeedReference :=0;
End_If;
// if speed increase or decrease are press then index in that direction.//
If SpeedIncreasePB Then
SpeedReference := SpeedReference + 1;
Elsif SpeedDecreasePB Then
SpeedReference := SpeedReference – 1;
else SpeedReference := SpeedReference;
End_If;
As far as the code, it is pretty simple in design but as stated is missing the speed limiting factor which will be shown in video 2.
Understanding limits and putting them to use
Controlling limits is part of making a system more reliable in design to block any chance of the system running improperly which could lead to equipment damage or even an injury.
In video 2, I pick back up exactly where I left off from video 1. Showing how to add a speed limiting factor in the system using this If, then, else function of the structure text example that was created in video 1. This speed limiting factor is very important to have as it gives the system a means to not allow the drive or servo an ability to run past a point that could possibly cause equipment damage or make the system run out of the designed method. When it comes to structure text programming, understanding how simple each construct is programmed can help you out when the time comes to fix a controls issue or even just troubleshoot it.
Without further ado here is video 2:
Structured Text Speed Control Using Rslogix 5000 If…Then… Else Example Video 2
The full structure text code that is used in video 2 is:
// Set speed command for the drive using structure text.//
// if processor first scan then move a zero into the speed.//
If S:FS then
SpeedReference :=0;
End_If;
// if speed increase or decrease are press then index in that direction.//
If SpeedIncreasePB Then
SpeedReference := SpeedReference + 1;
Elsif SpeedDecreasePB Then
SpeedReference := SpeedReference – 1;
else SpeedReference := SpeedReference;
End_If;
// if the speed is less than zero then move a zero into the speed reference.//
If SpeedReference < 0 then
SpeedReference := 0;
End_If;
// if the speed is greater than 50 then move a 50 into the speed reference.//
If SpeedReference >= 50 then
SpeedReference :=50;
End_if;
Controlling speeds with a Structure Text Case Function
In a slightly different approach, using a Case function for speed controls can be a lot easier to read and understand but it does have its limits in which it can only do certain tasks so this example will show the structured text case construct in use controlling the speeds that were derived in video 1 and video 2. There is a quick run through of what has been done prior and then get straight into the nuts and bolts of the case function in use for controlling the speed of a system.
The Case construct is meant for simple solution applications that do not require multiple variables or paths that can be done other than being straightforward.
RSLogix 5000 Structured Text Speed Control Case Example
The full structure text code for the Case example in the video above is:
Case SpeedControl_From_HMI of
0: SpeedReference:=0;
1: SpeedReference:=10;
2: SpeedReference:=25;
3: SpeedReference:=50;
4: SpeedReference:=100;
5: SpeedReference:=150;
6: SpeedReference:=200;
7: SpeedReference:=300;
End_Case;
I have worked in the industry for some time now and have seen a lot of people that didn’t seem to know or understand every element of programming that they just started re-writing the program to their own fit which often times led to increased machine downtime along with a lot of frustration.
This is the driving force in why I have tried to put together an ever growing resource of material for anyone to go through, this is by no means saying that I feel like an expert but more lines of saying I have been fortunate to have worked with some of the leader Rockwell software engineers which have shown me quite of number of helpful tricks.
With that being said, why can’t I pay it forward and lend a hand to help others learn from the knowledge that I have been able to get? The answer is simple, yes I can help out so I truly hope what I am doing here add value to your technical ability.
So to keep this article straight to the point and not drag it out I would like to ask if you have any further questions or would like to know more then please feel free to go to my contact page and send me a message, this is the quickest way to contact me and I will get back to you as quick as possible.
Thank you for your time and let me know if I can help any further,
Shane
Speed Controls
RSLogix 5000 Structured Text
Let OnlinePLCSupport.com
be Your Secret Weapon to Keeping up with Technology
I use ladder logic almost exclusively at my work, and totally agree that larger more complicated systems can be very difficult to track. I know Mitsubishi has their SFC system that allows the planning and layout to be seen easier, but most of 5000 is still a cut and dry ladder solution. Informative post, thank you!
Joe,
When it comes to having a good resource to turn to, there often isn’t so unless you pay a high dollar to attend a Rockwell training class so I started a place to get online plc support to have a quick reference of material when people need it.
Having a good reference for structure text is key to understanding any software that we use.
Thank you for the support and comment,
Shane
Really Great Post.
Thanks for all the information and the example videos.
The videos are Great at showing the steps and help to better explain everything. So much information.
Can’t wait to try it out. Thank You.
P.S. Do you have any suggestions on any books for further reading?
And how long have you been in this field?
Will,
Thank you for the kind words, and as I get further into making this site better for everyone to learn then there will be books and such. Right now there is just training material that I made for RSLogix 5000 and FactoryTalk View SE along with servo controls for other devices.
Thanks,
Shane