Feedback request - Routine selection program

mikeexplorer

Supporting Member
Join Date
Nov 2018
Location
Scranton,PA
Posts
179
I would like some feedback on this program I wrote. As some of may know, I am developing a model railroad layout using a Micrologix 1400 PLC to control the trains as a means of learning how to program. (unusual I admit, but it is working)


I have already written several of the supporting subroutines needed in the programs (not shown in attachment due to size limits) that handle things like the remote switches, track power, and so forth.



The next step is building the routine selection system where options are presented on the HMI screen (sample attached) which are various operations to do with the trains. I have looked at several ways to do this, several other websites call it "mission" but at this time it is not known how many routines I will have and probably will never know as I am sure I will think of new things to do with the trains. So I came up with this idea of selecting a routine to run and having the ability to select the next routine I want to run while the current one is running.



I wrote this program and use the RSLogix emulator to run it and it works. Some of the routines can run endless (such as interchanging the main and side track train and running it around the track X number of times) and it will just do that endless. Other routines planned would do an operation and end. (such as take the running train and park it in the side track)

So this routine selection has to have a flag that the endless subroutines would see to tell it that a different routine wants to run and to end its cycle at a proper point.



The subroutines here are just timer cycles, the first two will run endless, once the third timer expires, it resets the sequence steps and restarts the second timer. The other routines will go through the three timer cycles and just end.


Each routine will also set a flag to indicate that its "done" with what it has to do, whether it was a routine that did an operation and ended, or an endless routine that was flagged to end and its now finished with its cycle.


Here is information on the data used for the program:



N7:0 HMI choice for next routine to run
When one of the desired options is pressed, this integer will be set to a number for the desired next routine but no action is taken until a "confirm" flag is set, in case it was accidentally pressed.

N7:1 Next routine to run
N7:2 Current routine running
N7:4 Current routine end flag (non-zero value indicates current routine has ended)
(I am thinking to change this to a bit value and latch/unlatch it)


B3:0/3 HMI Confirm flag for selection of next routine. When this goes high via the HMI this means the user is "confirming" the choice for the next routine to run.


B3:0/1 "End request" flag. When next routine is confirmed, this bit goes high. This will tell the current running routine to end when it completes a cycle. This is set automatically once the "next routine" is selected.

B3:0/0 This is the "OK to run" flag, conditions that have to be met for this flag to be high
(No E-stop, automatic mode, no alarms, etc...)

Each subroutine uses an integer as a sequence step which I do rely on for this project in many of the programs written so far.


The idea of this program is I can expand it as I think of new routines to develop and would require little modification to this program. The only thing missing is maybe a check for the next routine to be out of bounds (a number higher then the number of available routines) but the HMI would be the source for this integer value.


I am just looking for thoughts and feedback on this approach since I have not seen anything similar on other websites.


Mike

HMI Selection screen.jpg
 

Attachments

  • Routine Selection Test 2.pdf
    78.8 KB · Views: 16
This seems like it is similar to some Christmas and Halloween lights I run by modes, then each mode has steps.

I have tried this different ways just to try it.

Here is a (very much edited down) copy of my main Christmas PLC.

SLC5/03, so as long as you're not using the Micro RSL500 you should be able to open it.

Each mode has to set a DONE bit for the next mode to continue. If each mode is in its own subroutine then the subroutine has to go through once not ON and turn everything OFF, then set a SKIP Bit and the DONE bit, for the main routine to continue.
 
It's a really minor thing, but I would consider calling all subroutines unconditionally from the Main [LAD 2] routine, and putting the "do I execute this subroutine?" check early in each subroutine itself; each subroutine would RETurn before it does anything if either B3:0/0 is 0 or N&:2 does not match.



Pros

  • Cleaner main routine: it only does important stuff
    • It is even reasonable to consider having the main routine have only JSRs, and do everything in subroutines
  • Ensure all subroutines are called on the First Pass, in case there is any subroutine-specific initialization required
  • Isolates the value that N7:2 needs to be into the subroutine itself, rather than having that information spread over two or more LAD files.
Cons

  • Less efficient
  • Two-branch OR to trigger the RETurn in the subroutine uses more vertical space than the AND to trigger the JSR in the Main routine
 
This seems like it is similar to some Christmas and Halloween lights I run by modes, then each mode has steps.

I have tried this different ways just to try it.

Here is a (very much edited down) copy of my main Christmas PLC.

SLC5/03, so as long as you're not using the Micro RSL500 you should be able to open it.

Each mode has to set a DONE bit for the next mode to continue. If each mode is in its own subroutine then the subroutine has to go through once not ON and turn everything OFF, then set a SKIP Bit and the DONE bit, for the main routine to continue.


I am using RSlogix Micro so I can't open it. Could you post it as a PDF?


Mike
 
It's a really minor thing, but I would consider calling all subroutines unconditionally from the Main [LAD 2] routine, and putting the "do I execute this subroutine?" check early in each subroutine itself; each subroutine would RETurn before it does anything if either B3:0/0 is 0 or N&:2 does not match.



Pros

  • Cleaner main routine: it only does important stuff
    • It is even reasonable to consider having the main routine have only JSRs, and do everything in subroutines
  • Ensure all subroutines are called on the First Pass, in case there is any subroutine-specific initialization required
  • Isolates the value that N7:2 needs to be into the subroutine itself, rather than having that information spread over two or more LAD files.
Cons

  • Less efficient
  • Two-branch OR to trigger the RETurn in the subroutine uses more vertical space than the AND to trigger the JSR in the Main routine


I am not yet sure if I want this routine selection in the main (Ladder 2) or make it a subroutine. It is not that many rungs of code so I might just integrate it into Ladder 2. Right now I have this much written, these are support routines that will be called by the routines as needed to do the train operations.


DEBOUNCE - As the train wheels travel over a section of track to sense the presence of the train, it is very noisy so this subroutine is a typical TON - TOFF debounce to provide a clean input if the train is in a block of track. I also use this for the photoeye sensors since the small gap between cars can trigger the sensor


TRACK PWR - This sets the six outputs which control the power to the sections of track. I set aside six integer values and when they are non-zero, the output is energized. This also allows me to see where in the program the track power was turned on. For example, if Ladder 8 is running and it turns on track power, I will put "800" in that integer, later in the same ladder if it needs to turn on track power, I will put "810" in it.



AUTOMATIC - this routine runs when the automatic button is pressed. This closes a series of relays that hands control of the railroad layout to the PLC, it is a typical Start-Stop circuit and it is tied to one input to tell the PLC that automatic mode has been enabled. This routine will do whatever is needed then set a flag and not execute again until it is selected again.


THROW SW - This routine handles checking and changing the remote switches to either the throughway or turnout track.



ANALOG - Right now there is nothing here, this will eventually handle the analog part of the layout. I will be able to control the throttle from the PLC and read the track power.


SW READ - This reads the remote switches to determine what position they are in and if they are "latched" Sometimes a switch can be knocked out of a closed position, or something physically jams it. This routine reads that.


MAIN MOVE - Simple routine to scan the mainline block detects and makes sure the train is moving on the mainline. This detects a stall or derailment and will set an alarm.


FWD-REV - Lionel type trains are capable of moving in a forward or reverse direction (Lionel track power is AC, not DC) Original trains used a magnetic drum inside the locomotive to change directions, but the sequence is "Forward - Neutral - Reverse - Neutral" and then repeat. The problem is some newer locomotives will revert to running forward after it sits on the track with no power for say about 10 seconds. So its impossible for the PLC to keep track of the locomotives next direction. This routine will cycle power to the locomotive and check the optical sensors so see which direction the train is moving and compare it to the desired direction until they match.


MANUAL - Routine will run when the manual button is pressed.


PARK - Another issue with trains is once the train moves into a block and the track power is dropped, some will coast for a few seconds before stopping, others will stop on a dime. This routine will sense if the train overshoots (coasts) and will cycle the track power to back it up into the parking block.


MAIN SENSE - I just wrote this routine recently. This will check the train on the mainline and sense what direction it is moving. Unlike the above routine, this does not set any alarm codes but returns data if the train is present, and if it is moving and the direction.


Mike
 

Similar Topics

Hello, I am new to forum and relatively new to ladder, but would appreciate some feedback on my latest project. I am using little Logo smart...
Replies
9
Views
2,053
It's been a long time since I've had to think of P&ID tag nomenclature myself (and not gone along with some scheme devised by someone else). I've...
Replies
1
Views
231
The PMTR has a timeout parameter for run feedback during a start, but once the motor has been running for a while and loses that run feedback (to...
Replies
0
Views
221
Hi all, One of the Kinetix 5500 in a machine is getting a Feedback Device Failure, subcode 66: INTERNAL RESOURCE ACCESS ERROR. Studio 5000 V.34...
Replies
4
Views
915
Hi, I'm trying to understand a couple of things with a feedback signals that are used in a SRP/CS that I'm working with. Quick disclaimer: I'm...
Replies
2
Views
523
Back
Top Bottom