Sub routines

Join Date
Apr 2009
Location
Rocky Mount Va. 24151
Posts
9
Hello:

I am new to PLC's as far as writing the programs and have never written a sub routine. I know in a regular ladder you are limited to writing an output once. I understand this does not apply to sub routines. My project is a four floor elevator with all real world conditions, including a load cell, encoder and more. I have my basic main program and will need 6 sub routines. Little lost on the sub routines. Any hints?

Charles
đź“š
 
Thank You For your Prompt response. I will try and break down each operation to individual routines, ex. open close door, arrive at floor, floor requests, encoder and drive functions. I have a lot of real world logic, just new to writing programs.
 
Greetings Charles ...

and welcome to the forum ...

you’re asking a “basic” question – so I’ll give you a “basic” answer ... (in other words, there’s a little more to it than this – but this should help get you started) ...

I have my basic main program and will need 6 sub routines.

that’s probably not correct ... specifically, you do not NEED/REQUIRE subroutines to make your program work ...

analogy: you could write a very lengthy book (a novel for example) all in ONE uninterrupted “chapter” ... that would work perfectly ... but ... novels are usually broken into “chapters” – which makes it more convenient to “organize” the material – and keep up with where you are in the story ...

now then ...

analogy: you could write a very lengthy program (for an elevator as an example) all in ONE uninterrupted “main routine” ... that would work perfectly ... but ... programs are usually broken into “subroutines” – which makes it more convenient to “organize” the material – and to understand and interpret the program ...

and so ...

at their most basic level, you should think of a “subroutine” as something like a “chapter” in a book ... thinking along those lines, it might be very helpful to organize your program into something like this (just for discussion) ...

Subroutine #3 - operator controls
Subroutine #4 - raise the cab
Subroutine #5 - lower the cab
Subroutine #6 - control the doors

and so on ... (IMPORTANT! those aren’t necessarily “answers” – or even “hints” ... I just used those terms as examples for discussion) ...

going further ...

now suppose that you DID organize your material that way – and suppose that it worked perfectly ... here’s my point: you COULD (if you so desired) also put ALL of that same material in the ONE MAIN routine – and not use any “subroutines” at all ... and that’s why I earlier I said that you don’t NEED/REQUIRE any subroutines ...

moving right along ...

now suppose that you want to get a real good handle on how subroutines function ... here’s an exercise that I would highly recommend – that will teach more than reading the book ... put the elevator project on the back burner for a few minutes – and start a brand new program as follows ...

suppose that you have a few inputs (switches or buttons will do nicely) ... and suppose that you have a few outputs (lamps would be perfect) ...

make a few subroutines ... put one switch to control one lamp in the first subroutine ...

like this: ----] [------------( )----

and then follow the same pattern with the other lamps and switches – each in their very own subroutine ... (IMPORTANT! don’t get carried away and use the same output twice – yet) ...

now then ... see if you can get the thing to work ... switch ON = lamp ON ... switch OFF = lamp OFF ...

if it won’t work, check to make sure that you’re “scanning” the subroutines (a VERY common beginner-level problem) ...

next – STOP “scanning” one of the subroutines and watch what happens to that particular lamp ... make SURE that you check the operation with the lamp in the ON condition (as well as OFF) at the instant when you quit scanning the subroutine ...

once you’re CERTAIN that you see what’s happening, then (and only then) create a “double-coil” problem by trying to control the SAME lamp twice – once in two separate subroutines ...

see how far you can go with all of this – post again if you have specific questions ...

also be SURE to tell us what brand and model of PLC you’re using ... that’s incredibly important ...

hope this helps ...
 
Plc Sub routines.

We had planned on using a Micrologix for this unit, but our school did not have one with enough I/O we need 16I and 12 O. I will likely use a Slick 500 I found in a maintenance storage cabinet. First look I believe I will have enough I/O capacity. I will have to read encoder pulse to control the brake and motor output. Thank you for your input, I will attach my work As I progress.

Thanks,

Charles
 

Similar Topics

Hi guys, I am creating a sub routine and was wondering how i can trigger Bit when the sub routine first runs is it just a Open Line ? or is the...
Replies
5
Views
793
Good Morning , I'm working on a project along with a manufacturer. We are both working on a project , and I'm integrating an existing portion...
Replies
8
Views
2,239
Anyone help me please to add subroutines to a program that runs a baler.I want to delay the return stroke after a ram has extended.I've been doing...
Replies
1
Views
1,561
  • Poll
On another thread, the subject of subroutines came up. I do not use them myself. I spoke with everal others that do not either. Perhaps it...
Replies
26
Views
5,168
Reading another thread recently, someone advised upon not making subroutine jumps conditional, i.e. call them every scan, due to the fact that you...
Replies
25
Views
11,462
Back
Top Bottom