Siemens One Button Brain Teaser

Join Date
Jan 2015
Location
Houston, Texas
Posts
31
I'm brand new to PLCs and struggling with a fairly basic problem given to me to solve by a co-worker. I'd appreciate any ideas you folks may have about how to solve it.

Problem: use one button to both start and stop an output (light, motor, whatever). That's it.

I'm using a Siemens 300 simulator.

Thus far it has been suggested that I will need to use PTRIG, ADD, MOVE, and CMP == to accomplish this. I'm baffled.
 
Use a one shot instruction for the input. It is the --[P]-- instruction in LAD. Use the one shot then to determine the set and reset of the output. If one shot and output is off then set output. If one shot and output is on then reset output.

Regards,
Garry
http://www.accautomation.ca
 
This logic is the old alternator, flip-flop, or toggle function. It can be done many ways. Here is one that works in just about any situation.

Alternator Method 1.jpg
 
Last edited:
Many thanks to each of you for your generous help. I'll keep hacking away and see if I can come up with a working solution.

Part of the challenge for me at this early stage is translating general terms into Siemens-specific Step 7 ladder logic code.
 
You could, in theory. If you XOR a value with 1 (true), it will toggle between true and false.

However, I don't think S7 has an XOR command in ladder that only works on one bit. You would have to XOR a whole word. It might make it a little complicated, and certainly wouldn't save you any memory.

Honestly, I would say once you find one good way to do it, keep looking for others. There are a lot of ways to solve this problem, and a few more that look like they might work at first glance, but don't actually work. It is a great programming problem to be creative at, and solving problems creatively will be a great asset later on.
 
As already pointed out to you, there are many, many ways to "toggle" the state of a bit with a single input bit.

Search these hallowed pages for "toggle", "flip-flop", etc.

But there is almost always something missing from the specification.... What should the toggled bit do in the event of a processor power-cycle, or a mode-change from Program to Run mode?

Most of the "logic only" solutions you will see posted will not retain the "on" state of the toggled bit, and will reset when the processor restarts.

Of course that may be desirable for bits that are controlling physical outputs, such as motors or actuators, it is considered bad practice to produce any movement just because the power has been re-applied, or the processor is changed from Program to Run mode.

Conversely, if the toggled bit is something like an operator selection... "Do you want fries with that?"... then it would be wrong for the bit to be reset if the power, or mode, is cycled.

My personal preference is for a toggle action that is always retentive, and it is up to me to reset the ones I don't want retentive, by writing appropriate code to do so. Instinctively I don't want anything that is not in my program changing the state of my bits. This is also totally visible to anyone else reading the code.
 
Last edited:
As already pointed out to you, there are many, many ways to "toggle" the state of a bit with a single input bit.

Search these hallowed pages for "toggle", "flip-flop", etc.

But there is almost always something missing from the specification.... What should the toggled bit do in the event of a processor power-cycle, or a mode-change from Program to Run mode?

Most of the "logic only" solutions you will see posted will not retain the "on" state of the toggled bit, and will reset when the processor restarts.

Of course that may be desirable for bits that are controlling physical outputs, such as motors or actuators, it is considered bad practice to produce any movement just because the power has been re-applied, or the processor is changed from Program to Run mode.

Conversely, if the toggled bit is something like an operator selection... "Do you want fries with that?"... then it would be wrong for the bit to be reset if the power, or mode, is cycled.

My personal preference is for a toggle action that is always retentive, and it is up to me to reset the ones I don't want retentive, by writing appropriate code to do so. Instinctively I don't want anything that is not in my program changing the state of my bits. This is also totally visible to anyone else reading the code.

Excellent point; I hadn't considered safety at all, but I will in the future.
 
ST just works better than Siemens LAD

Try your solution as a Function Block written in ST:
// Remark for program
CONFIGURATION DefaultCfg
VAR_GLOBAL
b_Start_Stop : BOOL; // Global variable to represent a boolean.
b_ON_OFF : BOOL; // Global variable to represent a boolean.
Start_Stop AT %IX0.0:BOOL; // Digital input of the PLC (Address 0.0)
ON_OFF AT %QX0.0:BOOL; // Digital output of the PLC (Address 0.0). (Coil)
END_VAR

PROGRAM : Monitor_Start_Stop;
END_CONFIGURATION

PROGRAM Monitor_Start_Stop // Actual Program
VAR_EXTERNAL
Start_Stop : BOOL;
ON_OFF : BOOL;
END_VAR
VAR // Temporary variables for logic handling
Rising_Edge : BOOL;
Already_Pressed : BOOL;
END_VAR

// Start of Logic
// Catch the Rising Edge One Shot of the Start_Stop input
Rising_Edge := Start_Stop AND NOT Already_Pressed;

// Main Logic for Run_Contact -- Toggle ON / Toggle OFF ---
ON_OFF := (Rising_Edge AND NOT ON_OFF) OR (ON_OFF AND NOT Rising_Edge);

// Rising One Shot logic
Already_Pressed := Start_Stop;
END_PROGRAM
 

Similar Topics

Context: PLC= S7-1212C, HMI=KTP1200 Basic. Hi, The operator has reported that, from time-to-time, when he presses the "Generate Report" button...
Replies
5
Views
486
Hi, Am I being daft (again)? I want to increment a tag (Integer) by 1 each time a button on the HMI is pressed. Before the button press, the...
Replies
22
Views
2,410
Hi I’m trying to work out how to get the alarm button to flash when there is an alarm or do I have it that the alarm page pops up with the alarm...
Replies
15
Views
1,435
On my HMI (KTP1200), I've got this button "Generate Report", which generates a report (CSV) when it's pressed. (see pic) While it's being...
Replies
1
Views
561
Hi, When the HMI (KTP1200 basic) powers up, the user has to enter their credentials to log in. In the screenshot, ADMIN has already logged in...
Replies
3
Views
1,017
Back
Top Bottom