Ladder Logic HELP !

ruby.n

Member
Join Date
Dec 2009
Location
USA
Posts
48
Hi,

I need to write some code to do the following:

1. When the start button is pressed, select online cleaning
2. If online cleaning is selected, go to sub-routine 'Online 1'
3. In 'Online 1' sub-routine, after Timer1 (10 sec) close Valve 10 for 10 sec.
After that, open Valve 10 and close valve 11 for 10 sec, and so on until valve
19.
4. After Valve 19 opens, wait for Timer2 (20 sec) and then goto 'Online 2'.
5. In 'Online 2' subroutine, after Timer1 (10 sec) close Valve 20 for 10 sec.
After that, open Valve 20 and close valve 21 for 10 sec, and so on until valve
29.
6. And so on, upto 'Online 5' sub-routine.

I need help with Steps 3-6.

I'm confused about the sequencing/looping, the number of timers I need. I want a short, smart way to program this logic...
 
I want a short, smart way to program this logic
The short, smart way isn't always the easiest to debug.

You could use a timer for each valve. Use the start button to latch an internal bit. Use the internal bit to start the first timer. Use the "done" bit of the first timer to start the second timer, etc. Use the "done" bit of the last timer to reset the latched internal, indicating the sequence is complete. You don't necessarily need to use subroutines.

You could also do it with one self-resetting, ten second timer. Each time that timer reaches its preset and resets itself, you could clock a bit shift instruction to turn off one valve and turn on the next.

Now, what if you later decide that some of the valves nedd to be turned on for longer than seconds and others need to be turned on for less? How do you recover from an interrupted sequence? Do you need to start over or can you pick up from where you left off? Will you have any feedback to tell you that a valve actually opened?

It's often pretty easy to get a program to do what you want it to when everything works as expected. The real challenge is to write it so that when things don't behave, it allows the operator to gracefully get the system back to a known state.
 
But do you mean to say that I have to have a different timer between each valve? Can't I use the same timer??
I thought there was some way to do a sequence of repetitive steps easily?

How do I do the following???
"You could also do it with one self-resetting, ten second timer. Each time that timer reaches its preset and resets itself, you could clock a bit shift instruction to turn off one valve and turn on the next."

Yes I will have feedback if the valve is open/close. Also if the valves need a longer time than expected, they change the system to manual control
 
Last edited:
But do you mean to say that I have to have a different timer between each valve? Can't I use the same timer??
You could also do it with one self-resetting, ten second timer. Each time that timer reaches its preset and resets itself, you could clock a bit shift instruction to turn off one valve and turn on the next.
I thought there was some way to do a sequence of repetitive steps easily?
You haven't told us what PLC you're using. If you're using an Allen Bradley PLC, it won't be helpful if I tell you to use a GE Bit Sequencer instruction.
 
Let's take a quick look at sequencial operation in ladder logic in general.

One of the challenge for new ladder programmer is the way ladder are scanned. One have to make a structure so that only certain logic (think of it as steps in a sequence) are active.

There are a zillions way of doing sequence but none of the good one are "easy". Because you always have to worry about starting/restart the sequence, exception logic, etc... if you just do a search for "sequence" on this forum you will find quite a few examples.

yes, you can use the same timer; if you do, you can just change the timer preset depend on which step you are in. Which may or may not be the best way to do it.
 
Ruby, perhaps it would help you to see what you need to do if you would draw up your sequence as a flow chart.

Show each step -- each valve opening, each valve closing. I.e.,

Open Valve 10
Close Valve 10
Open Valve 11
Close Valve 11
etc.

THEN between each of those actions, identify the condition to step from one action to the next. E.g.

Open Valve 10
Timer done
Close Valve 10
Timer done?
Open Valve 11
Timer done
Close Valve 11
Timer done
etc.

From this, I think you should probably be able to write the code. KEEP IT SIMPLE! Personally, I would use a separate timer for each. It makes life much simpler down the road. (Someday, you're going to want one of them to operate with a different cycle than all of the others... Trust me...) Unless you're using a really old PLC, timers are "free" and you have plenty of the built-in.

And, again, you ~could~ use the "same timer" and move in a preset for each step. But make it so Bubba who works on this system on the weekend-night shift can understand it. >> SEPARATE TIMERS!


Like Steve said, the easiest way to trouble-shoot this ~should~ be fairly obvious. Don't over-complicate this logic. It's not worth the headache.
 
Hi ya... Thanks so much. I think maybe I will stick to using separate timers. I did start using separate timers, but with 240 valves I thought it might be better to keep it easy....and less cumbersome. But as you're all suggesting, someday they may wish to change the time slightly and it would mess up the entire program....

But is it practical to use 240 timers??
 
Can only one subroutine be executing at any given time? If so i would think about using amount of timers needed on subroutine and loading needed time values in that subroutine, that way it should be clean for "the other guy" too.

Also aint 800 series used for DCS mainly?
 
If your PLC supports indirect addressing, you can use one timer. But, you will need an integer array sized [240] (lets call it 'TIMER_BANK').

Then right before you trigger the timer, you move the value from the array into the ".pre" of the timer.

So with each run of the timer, you would index a bit by one.

Example: let say you are on valve 10 and it just finished. Your index bit would be 10 (lets call it 'INDEX_BIT'), then you add +1, so now your index is 11.

The step right before you start the timer would then be to MOV (move) the value located in TIMER_BANK[INDEX_BIT] into the '.pre' of the timer.
 
Ya my colleague also suggested doing it this way, with counters and an index of values. This looks much more efficient.
 

Similar Topics

Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
Replies
11
Views
137
Working on project will update after it is completed.
Replies
2
Views
355
Can someone help me piece this problem together. I have a lot of it down I think but cannot seem to get it right. Probably an easy one for most on...
Replies
1
Views
303
Hi everyone, I'm working on a project that involves using a Keyence LR-X100 sensor in Studio 5000 V35 ladder logic to determine the object's...
Replies
4
Views
677
Hey. I am new to PLCs and LogixPro. A friend and I have been trying to build this diagram and instructions using LogixPro500. Could anyone help us...
Replies
15
Views
1,279
Back
Top Bottom