Today is...
Monday, September 24, 2018
Welcome to, the global online
community of automation professionals.
Featured Video...
Featured Video
A demonstration of EtherCAT control of linear motors using the CTC EtherCAT master.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive
RSLogix 5000 While and For Loops
Need to run a while loop in RSLogix 5000 to make a pump stay on until a low level sensor de-energizes.

I am new to programming and need a pump to turn on when the high level sensor energizes and to turn off when the low level sensor de-energizes. I am using the RSLogix 5000 Demo to experiment with it so I don't mess up the actual code on the actual machine. I want to run a while loop that would be as follows:

While Low Sensor & High Sensor Energized
...While Low Sensor Energized
......Pump ON

I only see for loops in 5000 so is that all I can do or are while loops hidden somewhere?

How would this be setup?

Seriously ?

Oh dear.....

By curt wuollet on 4 April, 2011 - 3:44 pm

Why the loop for that? It looks to me to resolve to:

pump on = low sensor on and high sensor on. Am I missing something? That's just a rung.


By curt wuollet on 4 April, 2011 - 3:45 pm

I think I see the problem. Let the PLC do the looping and you do the logic. Think through how a PLC works.

You don't need a loop.


By Steve Myres on 4 April, 2011 - 9:50 pm

Ladder was originally designed to replace systems where the logic was implemented using relays. Think how you would solve this using physical relays (think latching circuit, like a three wire motor control circuit) and you'll have your answer.

Even if you're working in a language other than ladder, the same principle applies.

Okay, I think I see the problem here. You are approaching this from a typical high level language approach. The PLC is not programmed like that. This is why:-

Simplistically, everything is within a 'while TRUE do ...' loop.

While TRUE Do

The PLC monitors the length of time it takes to do one full cycle of the loop and if it takes too long, the PLC faults. It must complete it refresh of the IO within a set time or its pointless. PLC programmers are VERY careful about using any kind of loop structure in their code, to ensure it does not slow the processor down too much.

Loops in a high level language (C, java, basic, etc) may pause the overall execution for .25 of a second with no ill effects. To a PLC a pause of 250ms is a disaster. Imagine not reacting to a fault circuit for that length of time. (Don't flame me, I know that is a lot of number crunching to slow it down that much, but its the principle I'm getting across.)

In your case, as the others have said, we are talking about an if statement with some memory.

If (high_level OR pump_was_started) AND NOT Low_Level then

...pump_was_started = ON


...pump_was_started = OFF

end if

That could then be converted into one rung of ladder.

Hope that helps.


By Paul Edwards on 5 April, 2011 - 5:26 pm

The rung would look something like

High,,,,,,,Low,,,,,,Run Pump
--| |---------|/|--------( )--
--| |----|
Run Pump

Ignore the commas I had to add them to show the verticle rung.

The high trigger the latch and the low resets it.


This is my first project....I know zero about PLC logic.

Anon - Thanks for the help...

cww - Yes, the part your missing is the high sensor goes off before we want the pump to shut off so your rung won't work. Also, I'm not really sure the details of the PLC.

Steve M - good way of thinking, thanks.

pjb - Your right, I'm thinking at the higher level, and I will stay away from the loops.

Paul - Thanks for post, you basically solved it. What we will is use,

,,,,,,,High,,,,,,,,Low,,,,,,Run Pump
-------| |---------| |--------( )--
------| |----|
,,,,Run Pump

I think that would work, I will let you know when it gets put into the machine.

By curt wuollet on 6 April, 2011 - 6:11 pm

That wasn't stated, but logical I suppose.