RSlogix Better way to control outputs in sequence

mikeexplorer

Supporting Member
Join Date
Nov 2018
Location
Scranton,PA
Posts
178
I have been learning to program an Allen Bradley PLC by having it control a model railroad layout. Right now I am using a Micrologix 1000 but will soon be upgrading it.

In the course of writing programs for the trains I do depend heavy on sequence. Attached is a routine for parking a train. I also made a video of the program running here.

https://youtu.be/IYy2prl0q7Q

I am using B3:15 as my sequence steps, as each condition is satisfied it sets a bit in B3:15 so only certain rungs would be allowed to be true if the conditions are right. I do plan to change this to using an integer rather then latching bits as this has gotten messy.

If you look over the code, (Ladder 2) ignore the other subroutines as they are not used for this program. You will see I have to latch and unlatch the same output during the course of the program. O:0/9 is the track power for the section of track where the train will be parked. I have come to discover that this is bad programming practice, one, referencing the same output in multiple rungs of code, and second, to use latch and unlatch for outputs in this way.

I need suggestions on a cleaner way to do this. After this program I hit a wall with programming and got stuck and I think this is why. I have read several articles on sequence logic but dealing with the output I still have not figured out since during the sequence, the same output has to be turned on and off depending on what is going on.

I am using B3:20 as my alarm codes, this will also change, bits do get latched in there if an alarm condition exists.

Mike
 
Yes you should change to integers, I prefer it that way anyway.

For handling multiples, I do 'request bits';

e.g.

seq. step 2 requests track power, OTE bit B3:0.0
seq. step 5 requests track power, OTE bit B3:0.1

Have a sub-routine called outputs

In it have
----XIC B3:0.0----- (OTE O:0/9)
|--XIC B3:0.1--|

etc
 
First of all,
Latch bits are a touchy subject, but generally don’t ever use latch bits (or set-reset bits) unless you WANT the information to stay during a power up.
Always use a sealed in coil that drops out if power is removed. That way the sequence will always have to start from the beginning.

Secondly,
You may benefit from this website: Patterns of Ladder Logic

It is mostly RS-logix 5000 based, but the same principals apply. With just those standard patters, you can make almost anything happen.

As far as outputs are concerned, I always have a routine at the end of my programs that is JUST the outputs, right in address order. Use the sequence bits to drive them in auto mode. Use a push button to drive them in manual mode. The first thing you usually want to find in a program is what is driving the output, so make them easy to find. Don't bury the outputs in the other logic.
 
If it is a strict sequence, with no input conditions to deal with, consider a SQO, sequencer. You can also use a timed input to a counter, then compare the count accumulate value to get a stepper.
 
Break the habit now of using jump instructions too.

When you convert to using an integer for keeping up with your steps, number your steps in increments of 10 (e.g. 10,20,30,etc). In case you need to add a step in between somewhere.
 
First of all I would not jump round logic this can lead to outputs staying on.
I agree that integers are the best way. Use a latch for the run signal then use this in each step so a stop will not enable the next step. (of course this depends on the application). Not particularly useful in this application but by using a seq. integer word means you can force it back to another value easily. a good example is a controlled reset back to home position.
I have used a train of flags (bits) for sequences before and indeed Siemens had a standard block for sequence control using flags.
 
This program is about a year old, shortly after this program is when I hit a wall with my programming and stepped back. I do realize that using an integer is a better way to sequence instead of latching bits. That will be one change I will be doing.



I do have a real input I:0/1 which is an actual relay start-stop circuit that is for manual or automatic mode. In manual mode I have control of the switches for track power and turnout switches. When I go to automatic mode, it energizes relays and control is turned over to the PLC.



I can make that the first condition of each rung so all rungs are false if the layout is in manual.



I am also planning to change my alarm codes to an integer also. I need more then 16 codes and for the Cmore HMI panel, the lookup text function works with an integer, this way I can display an alarm code on the HMI such as:


"No train detected on the main line"


I do see the suggestion of using bit values instead of manipulating the outputs instead of latches and unlatches. This is what I want to eliminate as it is not right. It makes sense since I would OTE the bit value and not latch it.



Since this will end up being a large program with many routines, it will take a block of bit values to represent an output.



Mike
 
Sometimes you really have to use latches but one suggestion is that you latch internal bits rather than outputs then at the end of the routines have a block of code that drives the outputs, this serves an excellent way of de-bugging a program for example if an output should be on then in one rung you can see what bits drive it and work back.
There are many other simple tricks like if you need an operation to continue to end of that step i.e. if switched to manual and it was driving forward to a position then it will continue until it gets to that position then will not step on the sequence word until back into auto (Note: before others start talking about safety, yes this must be taken into consideration, What if scenario's if switched back to manual is it OK to "soft Stop" i.e. logical conclusion not to be considered Emergency stop, so on switch from auto to manual stop when sequence reached, E-stop stop immediately), Rather that just auto/manual how about auto/manual then start/stop buttons so that it requires operator intervention twice to start the sequence. this gives the operator more control over his actions. A two step start action reduces the excuse of "it did it on it's own", we often got that where the operator stated he did not abort a process but the only way was for the operator to hold system first then after two seconds press and hold Abort button for 2 seconds.
 
First of all,
Latch bits are a touchy subject, but generally don’t ever use latch bits (or set-reset bits) unless you WANT the information to stay during a power up.
Always use a sealed in coil that drops out if power is removed. That way the sequence will always have to start from the beginning.

Secondly,
You may benefit from this website: Patterns of Ladder Logic

It is mostly RS-logix 5000 based, but the same principals apply. With just those standard patters, you can make almost anything happen.

As far as outputs are concerned, I always have a routine at the end of my programs that is JUST the outputs, right in address order. Use the sequence bits to drive them in auto mode. Use a push button to drive them in manual mode. The first thing you usually want to find in a program is what is driving the output, so make them easy to find. Don't bury the outputs in the other logic.

Thank you for posting that website link, I took a look at it and there is some valuable information that will be helpful in developing this model train layout. Not only for the questions I posted, but I can already see the "mission" section will be useful for the various routines I would want the trains to do, selected from the HMI panel.

Mike
 
Break the habit now of using jump instructions too.

When you convert to using an integer for keeping up with your steps, number your steps in increments of 10 (e.g. 10,20,30,etc). In case you need to add a step in between somewhere.

You make a very good point here and I think I can avoid using the jump statement. I had used it to skip the program if an alarm condition was present. I plan to change the alarm variable type to an integer so I can have more then 16 alarm codes. I could just add a condition in each rung that the rung would only be true if the value of that integer is zero (no alarm)

I can also add in the automatic mode check to keep the rung from being true if it is in manual mode.

Mike
 
First of all I would not jump round logic this can lead to outputs staying on.
I agree that integers are the best way. Use a latch for the run signal then use this in each step so a stop will not enable the next step. (of course this depends on the application). Not particularly useful in this application but by using a seq. integer word means you can force it back to another value easily. a good example is a controlled reset back to home position.
I have used a train of flags (bits) for sequences before and indeed Siemens had a standard block for sequence control using flags.

In the program I posted, there is a subroutine in ladder 7 that right now is messy but works. This is what I call the "forward-reverse" routine. This video explains it and shows it in operation.

https://youtu.be/PCPA4QjvoE0

The routine is messy because I am passing data in B3:26 to tell the subroutine what area I want to utilize this "forward-reverse" routine. I have three areas of track where this would be used. Since I am using a Micrologix 1000 and only the free edition of Rslogix, I am limited by the number of subroutines I can have.

In this routine, when it cycles the track power and the train is not moving in the desired direction, rung 36 resets the sequence bits to make the program do it over (but there is a counter so it it does it 5 times, it generates an alarm code) Changing the sequencer to an integer makes sense and would make it cleaner that if I need to repeat the sequence (did not get the desired result) I move the value, say "40" into the integer and it will allow the routine to repeat from where the condition is EQU to 40.

Mike
 
Sometimes you really have to use latches but one suggestion is that you latch internal bits rather than outputs then at the end of the routines have a block of code that drives the outputs, this serves an excellent way of de-bugging a program for example if an output should be on then in one rung you can see what bits drive it and work back.
There are many other simple tricks like if you need an operation to continue to end of that step i.e. if switched to manual and it was driving forward to a position then it will continue until it gets to that position then will not step on the sequence word until back into auto (Note: before others start talking about safety, yes this must be taken into consideration, What if scenario's if switched back to manual is it OK to "soft Stop" i.e. logical conclusion not to be considered Emergency stop, so on switch from auto to manual stop when sequence reached, E-stop stop immediately), Rather that just auto/manual how about auto/manual then start/stop buttons so that it requires operator intervention twice to start the sequence. this gives the operator more control over his actions. A two step start action reduces the excuse of "it did it on it's own", we often got that where the operator stated he did not abort a process but the only way was for the operator to hold system first then after two seconds press and hold Abort button for 2 seconds.

In designing and building the controls for this layout, I wanted to as best as I can follow machine building practices. This video is when I was testing my forward - reserve routine but does explain the layout and controls.

https://youtu.be/wZ4mSHbnv-g

The button box, STOP is manual mode, START is automatic mode. I have a typical start-stop relay circuit so it is energized in Start (Automatic) mode. This output are connected to actual relays that select between my control panel or PLC control. In manual, the track power and switches are controlled by the panel I build so I can just run the layout as any conventional model train setup. When I set it to automatic mode, the switches and controls are disconnected and the PLC has control.

I also do have an emergency stop circuit utilizing a PNOZ safety relay. In the event the button is pressed, the PNOZ relay will disconnect track power and the 24VDC that controls the outputs from the PLC.

The parts used to build these controls were from a prior job that the company was scrapping equipment and I was allowed to remove any parts I wanted to take home, so I was limited by what I had on hand since purchasing the parts would run into a good amount of money for a personal project. The end result for this project is not only to learn about PLC programming, but to have this control my around the wall layout in my living room.

I have successfully developed a project for work to solve a long standing problem with a plastic sheet line using a PLC for control. This unit monitors conditions on the line and will cut off the heating system and activate an air knife to prevent a plastic fire. Within the first week of implementing this device, it stopped a potential fire from happening. The company now wants to roll out the project to 4 more lines. The program for this is not complicated and does not need sequencing like my train project, but I was glad to see my work on this project was applied for a work project.

Mike
 
Just had a chance to watch your video. This is really cool!

Have you thought about trying to control speed from the PLC? It would be neat to notice a train coming to park, and as it passes a sensor, ramp the speed down and stop at another “park” sensor. Would need to add two more sensors though if you have room.

It’s too bad the blue train won’t remember what direction it was in when it powered off.
 
I agree the best way to control outputs in sequence is with the SQO function
I have used it on many projects
It is challenging the first time you use it but you will catch on quickly
You can have u to 255 steps per SQO that would give you 16 bits per step if you use an integer data type
If you need more bits then that you can use add a second SQO. There are many options there if needed.
You may also look at SQI function for inputs
Check the online help for them

On a side note I looked over you ladder program and a few observations
You have 2 subprograms shown in you structure tree Lad 6 and 7
But I could find no place in your lad 2 where you call the sub programs I may have missed it.
You call then with the JSR function with the number of the subprogram you want to call 6 or 7
With the RS500 the only program that will run on power up is LAD 2 someplace in that ladder you must call the subprogram. If you don’t call it will never run.
I also noticed that you call a JMP to LBL Q2:10 at different places in the ladder program
The LBL Q2:10 is the last rung in the adder program if you call it with( JMP) to it from any point in the program all the ladder rungs between the JMP and LBL are skipped completely and never evaluated
When the program is running after rung 35 (the last rung ) is excited the program will rollover to rung 00
It is possible for the program to run 00 to 09 then jump to 35 and back to 00 and not even scan any of the rungs between is that really what you want to do?
You do the same thing in both LAD 6 and LAD 7
Anytime you do JMP to jump over all the code between the JMP and the LBL it is not evaluated and the outputs are not cleared or set use them very carefully I have seen many programmers get in trouble with them. They spend many hours trying to figure out why the code doesn’t work.
 
Just had a chance to watch your video. This is really cool!

Have you thought about trying to control speed from the PLC? It would be neat to notice a train coming to park, and as it passes a sensor, ramp the speed down and stop at another “park” sensor. Would need to add two more sensors though if you have room.

It’s too bad the blue train won’t remember what direction it was in when it powered off.




Lionel trains back years ago used a drum solenoid so every time the track was energized, it would pull in and advance an internal drum 1/4 turn which would switch the wires going to the internal AC motor. This allowed the locomotive to be able to move forward or reverse since the output from the transformer is AC, not DC like HO scale. The drum has a sequence of Forward, Neutral, Reverse, Neutral, then it would repeat. Newer locomotives use solid state components and DC motors but some of them follow the tradition that it will remember its next sequence no matter how long it does not have track power. Some other units will revert to forward motion if the track power is removed for more then say 20 seconds. So as I explained in the video, its impossible to keep track of the locomotive's next sequence. So if I have a train parked on a section of track and I want it to move, this is why I made this subroutine so cycle the power and watch the sensors to see how it moves and cycle the power until it is moving in the direction I want it to move.



Right now I am using a Micrologix 1000 with the free version of RSlogix, since it has no analog capability it is not possible for it to control the speed of the train or to sense it. I am also limited by the number of I/O on the PLC as it cannot be expanded. It is also a discontinued model and I already had to open it up and replace a few failed relays. It has worked well enough to get me this far and it is a project I want to complete. Because of the limited I/O one problem I have is the track switches. The routine that throws the switches to position has to assume they did throw since there is not enough I/O to actually sense the switch position. On my website here:


https://www.nepaview.com/model-train-plc-project.html


The first block of pictures I modified this solid state interface module to allow a 5V input instead of its normal 24V input. I can tie this into the switch's LED light and actually sense if the switch is in position. If the switch is jammed and does not fully close to position, the LED will be off.



I have decided to upgrade. I did some research and have decided to replace the PLC with a Micrologix 1400 and add three modules for additional I/O. I am also purchasing RSlogix Micro Starter since the free version does not support this unit. The 1000 was also limited in memory. With the routines I wrote so far I already consumed 2/3's of the memory which tells me for all the routines I want to write, there simply is not enough memory.



I did look at other PLC units but having the ability to simulate programs is a need of mine. I can write programs and test them. Also Rslogix has been a very stable software platform. I did look at Connect Components but that software is buggy and gave me nothing but problems. The developer version was also more expensive so it was actually cheaper to go with the Micrologix version verses the Micro series.



The ML1400 also has built in analog so I will now be able to control the speed of the trains. I have already modified a Lionel transformer to interface it. I am still awaiting the new parts to arrive and this also means I have to rebuild the controls from scratch again.



Mike
 

Similar Topics

Hello all, I have a question in regards to RSlogix 5000. I am having issues with the program force closing when I try to make online edits. We...
Replies
0
Views
95
I am having trouble with getting no control of my analog output signal. I am using the SCL function block to control my analog output. The logic...
Replies
11
Views
210
Hello, Haven't been on in a while. I need to generate a bit level pdf of the I/O for RSLogix 500. I can generate a report but it just shows the...
Replies
1
Views
113
Greetings ... someone sent me a request for some student handsouts that I developed ... turns out that I had this hosted on my business website...
Replies
0
Views
109
Thank you for any and all responses/help. I have an RSLogix 5000 v20 and a Cognex In-Sight v5.9 spreadsheet (8502P). I can not figure out how to...
Replies
0
Views
101
Back
Top Bottom