RSLogix 5000 While and For Loops

R

Thread Starter

rpmccly

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

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?
 
C

curt wuollet

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.

Regards
cww
 
C

curt wuollet

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.

Regards
cww
 
S
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.
 
P

Patrick J Beckett

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.
<pre>While TRUE Do
...SCAN INPUTS
...USER CODE
...UPDATE OUTPUTS
Loop</pre>
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.
<pre>If (high_level OR pump_was_started) AND NOT Low_Level then

...pump_was_started = ON

else

...pump_was_started = OFF

end if</pre>
That could then be converted into one rung of ladder.

Hope that helps.

pjb
 
P

Paul Edwards

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.

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