You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
Thread Tools Display Modes
Unread November 30th, 2019, 06:23 PM   #1
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
RSlogix Better way to control outputs in sequence

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
Attached Files
File Type: pdf PARK THROUGHWAY V1.pdf (204.1 KB, 34 views)
  Reply With Quote
Unread November 30th, 2019, 06:31 PM   #2
the_msp
Lifetime Supporting Member
United Kingdom

the_msp is offline
 
the_msp's Avatar
 
Join Date: May 2008
Location: Northern Ireland
Posts: 812
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
__________________
Regards,

Patrick

Connect with Matrix Engineering on Facebook
  Reply With Quote
Unread November 30th, 2019, 07:44 PM   #3
Rson
Member
United States

Rson is offline
 
Join Date: Jun 2017
Location: Michigan
Posts: 204
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.
  Reply With Quote
Unread November 30th, 2019, 11:52 PM   #4
jaden
Member
United States

jaden is offline
 
Join Date: Sep 2009
Location: Pleasant Dale, Nebraska
Posts: 184
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.
  Reply With Quote
Unread December 1st, 2019, 12:44 AM   #5
seth350
Member
United States

seth350 is offline
 
seth350's Avatar
 
Join Date: Jul 2011
Location: Over yonder
Posts: 357
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.
__________________
“Did the Lord say that machines outta take the place of livin’, and what’s the substitute for bread and beans? Do engines get rewarded for their steam?” -John Henry
  Reply With Quote
Unread December 1st, 2019, 04:24 AM   #6
parky
Member
United Kingdom

parky is offline
 
Join Date: Oct 2004
Location: Midlands
Posts: 1,441
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.
  Reply With Quote
Unread December 1st, 2019, 05:55 AM   #7
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
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
  Reply With Quote
Unread December 1st, 2019, 08:22 AM   #8
parky
Member
United Kingdom

parky is offline
 
Join Date: Oct 2004
Location: Midlands
Posts: 1,441
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.
  Reply With Quote
Unread December 1st, 2019, 01:51 PM   #9
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
Quote:
Originally Posted by Rson View Post
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
  Reply With Quote
Unread December 1st, 2019, 01:53 PM   #10
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
Quote:
Originally Posted by seth350 View Post
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
  Reply With Quote
Unread December 1st, 2019, 02:03 PM   #11
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
Quote:
Originally Posted by parky View Post
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
  Reply With Quote
Unread December 1st, 2019, 02:20 PM   #12
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
Quote:
Originally Posted by parky View Post
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
  Reply With Quote
Unread December 1st, 2019, 05:01 PM   #13
seth350
Member
United States

seth350 is offline
 
seth350's Avatar
 
Join Date: Jul 2011
Location: Over yonder
Posts: 357
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.
__________________
“Did the Lord say that machines outta take the place of livin’, and what’s the substitute for bread and beans? Do engines get rewarded for their steam?” -John Henry
  Reply With Quote
Unread December 2nd, 2019, 02:24 AM   #14
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 1,041
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.
  Reply With Quote
Unread December 2nd, 2019, 07:20 AM   #15
mikeexplorer
Member
United States

mikeexplorer is offline
 
Join Date: Nov 2018
Location: Scranton,PA
Posts: 16
Quote:
Originally Posted by seth350 View Post
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
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Sequences xzen LIVE PLC Questions And Answers 34 April 27th, 2016 10:47 PM
Control - Data Type in RSlogix 500 and 5K mrchris76 LIVE PLC Questions And Answers 2 July 3rd, 2014 08:02 PM
Programming a sequence of events with RSLogix 5000 JMoga LIVE PLC Questions And Answers 2 May 30th, 2014 06:11 PM
RSLogix 5000 in Motion Control Andreik LIVE PLC Questions And Answers 2 November 13th, 2011 11:14 PM
Speed control with rslogix 500 nickromano07 LIVE PLC Questions And Answers 5 December 21st, 2008 08:06 PM


All times are GMT -5. The time now is 04:55 PM.


.