If, Then, Else Statements

...who don't care what other programming languages mean and who keep comparing a plc to a relay logic.
On the other hand, there are those like yourself who don't really KNOW Relay Ladder Logic, and assume that it must be like other computer programming languages. The question was NOT about ANY computer programming language, but was about using PLC ladder logic to SIMULATE relay-type logic. You can only simulate RLL logic with PLC logic, not duplicate it, because in RLL logic, all devices are being evaluated at every instant (not dependent on a scan cycle).

In relay logic, there are only two states, not an infinte number (as you would have with an If-Then-Else statement in most computer languages). Therefore in Relay Logic, "If A" always means "If A is True (1). The only other possibility is that A is not true or false.

Relay logic existed long before any of these other computer languages, so to try and assign extra meaning to an RLL If statement that never existed is false logic.

...my way and Lancie's method makes assumptions that without A then not B.
It is not an assumption in Relay Ladder Logic (we are talking about hard-wired, physical relay coils here). It is pure fact that if a relay has no TRUE input, it will be OFF or NOT TRUE or 0. But you cannot compare this to the crippled IF-THEN statement in most computer languages (which needs additional help to reset the result).
 
Last edited:
crippled?

(*Odd Numbered Passes (Front of Car to Rear Motion*)
110: (*Send Trolley Outboard*)

(*pswa retract*)
accu_move110 (target_debounced := pswa_r_stop_cmd,
direction_fwd := TRUE,
vsd_write_command => pswa_write_command);

(*dswa retract*)
accu_move111 (target_debounced := dswa_r_stop_cmd,
direction_fwd := TRUE,
vsd_write_command => dswa_write_command);

If pswa_r and dswa_r then
wash_arm_front_of_car:= false;
end_if;

If (pswa_r_stopped.q and dswa_r_stopped.q ) then
MachineMotionNxtStep:= 120;
end_if;
 
crippled?

If update_totals Then
For m:= 1 to 12 Do
For d:= 1 to 31 Do
WashHist[m][d][9]:= WashHist[m][d][1] + WashHist[m][d][2] + WashHist[m][d][3] + WashHist[m][d][4] + WashHist[m][d][5] + WashHist[m][d][6] +
WashHist[m][d][7] + WashHist[m][d][8];
End_for;
End_For;
update_totals:= false;
End_if;
 
What I meant was that in most computer program statements, when you turn something ON, you have to add statements to turn it off somewhere else. In Relay Logic that is totally unnecessary. That is, unless you insist on using Set and Reset as Peter did to bring the RLL logic down to the level of computer logic.
 
Last edited:
SeattlePLC, you post very vague and open-ended questions.

"What would a RLL diagram for If A then B else C look like?"
"Hi, I need to create a timing diagram for a couple of timers. I have no idea how to do this. Can anyone help?"

1st, I think you are a student, and it is OK for students to ask questions, but only if you show some effort on your own. Try to answer your own question, and if you reach a stumpling block post your effort when asking.
2nd, when you do post a question, you should take enough care to define the question so it is clear and unambigous.
3rd, you could help when clarifying some of the things that people discuss (because the original post is unclear) rather than stay silent.

Your posts makes a lot of qualified people waste their time for no reason.
 
On the other hand, there are those like yourself who don't really KNOW Relay Ladder Logic, and assume that it must be like other computer programming languages.

RLL and ST are exactly the same: every instruction is compiled to something the PLC can execute. IEC61131 states that different languages can be (partially) converted.

As I stated, the problem between ST and Ladder is not with the languages, the problem is with the different viewpoint of the programmers. It is hard to convince ladder programmer that other languages have their merits too.

Maybe you can convert this perfectly normal ST code to RLL using your way of thinking:
IF button1 THEN
State := 7;
ELSE
State := 9;
END_IF
 
Another reason to use B := A instead of If A then B:= 1 in ST languages.
I personally think that you should use B := A when you mean B := A and If A then B:= 1 when you mean If A then B:= 1 :)
I mean, you should be fully aware what every instuction you use, means, and use it accordingly.

I use the IF to determine if the condition to go from one state to another is satisfied. Using IF and ELSIF you can make sure only one condition is satisfied:

CASE State OF
INIT:
IF PowerOK AND EStopOK AND ResetPulse THEN
State := READY;
END_IF

READY:
IF NOT (PowerOK AND EStopOK) THEN
State := INIT;
ELSIF NOT HomeOK THEN
State := HOME;
ELSIF StartButton THEN
State := MOVEFAST;
ELSIF JogButton THEN
State := MOVESLOW;
ELSIF TeachInButton THEN
State := MOVETEACH;
END_IF

...

This is a way of programming that is not so easy to convert to ladder. And this is the question I'm adressing.
 
I personally think that you should use B := A when you mean B := A and If A then B:= 1 when you mean If A then B:= 1 :)
I mean, you should be fully aware what every instuction you use, means, and use it accordingly.

I use the IF to determine if the condition to go from one state to another is satisfied. Using IF and ELSIF you can make sure only one condition is satisfied:

CASE State OF
INIT:
IF PowerOK AND EStopOK AND ResetPulse THEN
State := READY;
END_IF

READY:
IF NOT (PowerOK AND EStopOK) THEN
State := INIT;
ELSIF NOT HomeOK THEN
State := HOME;
ELSIF StartButton THEN
State := MOVEFAST;
ELSIF JogButton THEN
State := MOVESLOW;
ELSIF TeachInButton THEN
State := MOVETEACH;
END_IF

...

This is a way of programming that is not so easy to convert to ladder. And this is the question I'm adressing.

I understand what you are saying. However, I was responding to the previous poster who indicated that he sometimes forgets to program to turn a bit back off, hence B:=A is better than if A then B:=1 which doesn't turn it back off. Your example is a different situation, however even then state engines can be and frequently are coded quite well with a few Boolean equations instead of If/then/else.
 
This is turning into a bun fight on which language is best , not what the OP was asking ....

All have their advantages... like pipe grips vs a spanner
 
A dozen way to switch ON a lamp

The Plc manufactured create 3 type category of programming language,

1.) ST
2.) Function Chart
3.) Ladder Logic.


To whom or which group manufactured dedicate this type programming?


1.) Electrician group.

2.) Instrument group.

3.) IT group.

Evaluate this group from your view


Maybe my opinion are wrong.
 
I have to agree with Peter's early posts as well as Bit_Bucket_07's post #20. There is nothing in the original post that infers that a single bit is being manipulated in alternate cases. Carrying the abstraction to it's logical conclusion, there is nothing saying that B and C are data types at all. For all we know they are full processes. All the OP states is "If A Then B Else C".

We all need to guard against answering the question WE THINK should be asked as opposed to answering the actual question that is asked.

Keith
 

Similar Topics

Hi I'm starting a new job (so i'm a newbie in ftview programming ) and i have the following problem : I must update some pages in a supervision...
Replies
3
Views
5,285
11 months ago I ordered a 10" Redlion HMI. I was given an April delivery date. April came and went. I waited, and in June I asked our vendor...
Replies
7
Views
2,382
I'm about to have a guy onsite (I'm trying to help troubleshoot remotely) and he doesn't have the proper software. Usually I have the guys install...
Replies
4
Views
1,755
Hey so I have an issue that is driving me insane. I have 6 AB powerflex 527 drives configured in a DLR network over CIP Safety. They go back to a...
Replies
1
Views
1,737
Back
Top Bottom