IF and THEN
Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 4 of 17.
An IF runs statements only while a condition is TRUE:
IF Start THEN
Motor := TRUE;
END_IF;This is a set coil. When Start is not pressed, the statement inside is skipped, and Motor keeps the value it had: nothing turns it off. So a second IF does the reset:
IF NOT Stop THEN
Motor := FALSE;
END_IF;Every IF ends with END_IF;. The IF that comes last wins, the way a reset coil on a lower rung wins over a set coil above it.
Challenge
Easy- With an IF, set
MotorwhenStartis pressed. - With a second IF below it, reset Motor when
Stopis pressed or the overload trips. - Light
RunLampwhile Motor is on.
Try it yourself
// Set the motor with Start
// Reset it with Stop or the overload
// The run lamp
All lessons in Structured Text
1From Rungs to Text
Your First StatementAND, OR and NOTThe Seal-In in TextIF and THENVariables in VARPractice on your own: PLC playground