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 ...