Ladder Logic - 'Simple' Coffee Machine - Optional: Add Milk / Add Sugar

flipd.d.mon

Member
Join Date
Dec 2014
Location
Stafford
Posts
4
I'm just starting to learn Ladder Logic Programming. I'm using Allen Bradley RSLogix 5000.

I've been tasked with developing a 'Simple' Coffee Machine which operates like so:

  • Toggle Push Button to Start
  • Drop Cup (for 10 seconds)
  • Feed Hot Water (for 10 seconds)
  • If required, Add Milk (for 10 seconds)
  • If required, Add Sugar (for 10 seconds)
  • Procedure Complete - Illuminate Complete Light (for 10 seconds)

I have implemented everything except the OPTIONAL add Milk & OPTIONAL add Sugar.

Options are to have a Coffee without either Milk or Sugar. Or have a Coffee with Milk and Not Sugar. Or have a Coffee with Sugar & Not Milk.

I'm considering using Toggle Buttons to select / jump to a Subroutine (choosing the required ingredient make-up). But I'm wondering if there is another way to sequentially go through the procedure?

Thanks.
zUJ5N.png


http://stackoverflow.com/questions/...le-coffee-machine-optional-add-milk-add-sugar
 
I would simply add a pushbutton for each option, then handle these pushbuttons like you did the first one. Lock out the "Add Milk" and "Add Sugar" until the cup is in place. You don't really need a separate subroutine for any of this. Only add subroutines if you simply want to learn how they work. Subroutines will make it more difficult for you to troubleshoot the program, and to find your logic errors.

One thing you need to do is to set up a "Transaction in Process" relay on your first rung that is activated by the Start Pushbutton. This is a relay that should actiavte each following rung, and stay ON until it is turned off by the "Transaction Complete" light. That way, anyone walking up to the machine cannot activate the coffe, milk, or sugar dispensing solenoids without first putting in some money (pressing the start button).

The PLC will scan your rungs sequentially - you don't have to worry about that! Simply use buttons and step relays for any steps that are NOT sequential! The Add Milk and Add Sugar buttons are not sequential events - they may occur or not and may be in any order.

Think about the best way to make the machine work. The coffee machines I have used allow adding the creamer and sugar after the coffee is in the cup. Usually you hold down the button until the addition is made. Do not turn on the Complete light until the opportunity to add the milk and sugar has been selected - or not. The 10-second times for each event are a little unrealistic! Adding water for 10 seconds will overflow most cup sizes. I suspect the 10-second times were selected to allow more student troubleshooting time.

For the milk and sugar, I would activate the buttons when the coffee and water are in the cup, then start a 10-second timer. If the milk and sugar are not selected in that 10 seconds, then the transaction is declared "Complete". If either or both buttons are pressed in the 10-second window, then activate the milk solenoid (OTE) and/or the sugar solenoid another OTE) for some finite time (maybe 2 seconds for milk, 1 second for sugar), then lock out those solenoids for this transaction, to avoid overfilling the cup (and providing too much extra for the price). The last step should be to turn on the Transaction Complete light, and then also turn off the Transaction in Process relay.
 
Last edited:
Thanks for the reply.

I need to make an edit to the original post - that being the options available for the ingredients. I forgot to include an option for both Sugar & Milk to be added together.

So the options should be:



  • To have a Coffee without either Milk or Sugar.
  • Or have a Coffee with Milk and Not Sugar.
  • Or have a Coffee with Sugar & Not Milk.
  • Or have a Coffee with BOTH Sugar & Milk.
 
I'm sure a bunch of ways to do it, but you could use buttons to move an integer into a register for the 4 choices. 0= no selection, 1=no milk or sugar, 2=etc,etc. you could even use 1 button and "add 1" every time it's pressed so it steps through your choices. After water is poured, look at this integer register and take it from there. When all is done-move a 0 into register for next cup.
 
What are your "constructions constraints". What instructions are you allowed to use? Generally speaking you instructor is trying to highlight something you were taught and will expect you to use those things in the logic. If this is just a free-form exercise to see how you think then you can use whatever you like.

The way these machines generally work, you select your options before you hit start. To allow the largest flexibility you would have one button for milk and one for sugar. Allow them to toggle prior to start but once the cycle is started lock out changes.

Is the sequence you listed what was presented to you or did you come up with it yourself? For mixing reasons all the ingredients are typically added together or with small start offsets. But if that is the sequence you are stuck with then that is what you have to do.

I'm a big fan of integer based state machines. They are easy to troubleshoot, easy to monitor and easy to modify. But progressive logic through relay latches works out just as well.

If you want to just add to what you have , add a couple of toggles for milk and sugar above the start rung in rung 0. I would add the logic for the two options after your current rung 5. The logic would be identical to the water add logic including the status bits. Just condition the logic so it only runs if the option is selected. The second option (sugar) would require some extra conditioning because you may or may not have to wait for the first option (milk). The complete light rung (rung 6) would have the options complete status conditioned by whether the option was selected.

Good luck.
Keith
 
Thanks for the replies.

I'm a Software Engineering student - though I'm currently on a year long Work Placement. I have previously been developing with Java, C#, C++ languages - so PLC's & Ladder Logic are all very new to me.

I have been given a couple of 'Free-Form' Exercises to complete, with minimal constraints. The specification I was given for this particular exercise is below:

---------------------------------------------

PLC Exercise 2
‘Simple’ Coffee Machine

Start Button
Sugar On/Off Switch
Milk On/Off Switch

Coffee Cup Drop Output
Hot Water Feed Output
Sugar Feed Output
Milk Feed Output
Complete Light

Wait Start
Drop Cup (Output On For 5 sec)
Feed Hot Water For 10 sec
If Sugar Required, Feed Sugar For 5 sec
If Milk Required, Feed Milk For 5 sec
Light Complete Lamp For 5 sec

Define Inputs
Define Outputs
Define Intermediate Variables

Design

Code (Incl SCADA)

Test


--------------------------------------

Is there anything specific to note about any differences between the use / requirement of Switches for Sugar & Milk addition as opposed to a Push Button?

Thanks for the guidance so far - appreciated.

*EDIT* p.s. -

It has been mentioned that there is different ways to design a Ladder Logic program - these being 'Continuous' or 'Sequential' in design.
I imagine that Sequential may tie into the Integer Based State Machine approach that was mentioned - though I may be wrong. Could anyone elaborate on any of these additional points for me?

There is a discrepancy in the timer durations just so as I can view the changes happening in the program better.
 
Last edited:
The purpose of the exercise is to teach sequencing. How to execute a predefined order of steps, the 'If Add Sugar' and 'If Add Milk' are to teach you how to execute a step that might have different requirements. There are 5 steps -
  1. Drop Cup
  2. Feed Water
  3. Add Sugar
  4. Add Milk
  5. Complete Lamp
Your program should sequence through all five steps. You should always enter the Add Sugar and Add Milk steps in the sequence, the 'If' part of those steps determine if it will take 5 seconds to complete those steps or if they will complete immediately.

You could use a counter to keep track of which step of the process you are in, when a step is complete you increment the counter.
  1. If counter = 0, wait for Start Button. Start Button increments counter
  2. If counter = 1, drop cup. Drop Cup timer increments counter
  3. If counter = 2, feed water. Feed Water timer increments counter
  4. If counter = 3, add sugar. Switch determines if timer or not switch increments counter
  5. Etc
 
Is there anything specific to note about any differences between the use / requirement of Switches for Sugar & Milk addition as opposed to a Push Button?
The description ON/OFF implies to me that the switches are maintained, like a light switch in your house. If this is what is used you just need to know the switch status at the time the milk/sugar function is checked. If momentary pushbutton, you'd need to latch (OTL) the switch status at the start of the cycle and use the latch state later during the milk/sugar addition. If using latches remember to unlatch (OTU).
 
Originally posted by Tark:

The purpose of the exercise is to teach sequencing.

I wouldn't necessarily make that assumption. The exercise may be just as much about turning a specification into a working system. It may be about knowing when to ask questions and get confirmation. Based on the response above it doesn't sound like this is intended to reinforce a specific concept. It seems like it is intended to measure overall capability. While you certainly could interpret the "spec" as indicating the operation is sequential due to the way it is listed, most of the specs I receive are numbered what appears to be sequentially. However, most of the numbering is just for referencing to indicate a line item or section. So just because it is numbered you can't infer it is supposed to be sequential. If that were a universal truth I would have a whole bunch of machines in the field that ran to 1000 FPM AND THEN regulated tension to 0.25 PLI.

Originally posted by Doug-P:

The description ON/OFF implies to me that the switches are maintained,...
While I agree that seems to be what is inferred I don't know if that is what is really required. This one seems a little more direct since the spec talks about a start button and then about an on/off switch. It's just that from a user standpoint that type of control seems pretty odd. the "default" condition of the current selection is contingent on the previous selection, which is not very user friendly.

The moral of the story is, if you question it ask the person who specified it. In your situation I think that shows you are being detail oriented.

I think the "continuous" versus "sequential" question is where Tark and I differ. How you implement a sequence is another discussion. That is where you can talk about integer state machines, shift registers, counters or latched based sequential logic. All of them would result in a sequence they just use different code constructs. No matter what this project will have a certain sequential nature to it that you will need to manage. The only question is if the options need to specifically be sequential or if they can occur concurrent with the water dispensing.

Keith
 
Wait Start
Drop Cup (Output On For 5 sec)
Feed Hot Water For 10 sec
If Sugar Required, Feed Sugar For 5 sec
If Milk Required, Feed Milk For 5 sec
Light Complete Lamp For 5 sec
I agree with Tark. The above is a definite required machine sequence of operation. Words do have commonly-accepted meanings. Ignoring the sequential instructions and allowing operations out-of-sequence is a sure way to lower your grade by at least 1 level. A big part of programming is learning to read and follow your customer directions (whether the "customer" is an instructor, a client, or your boss).

In this case, you only need to have the Start-control DISPENSE-mode internal bit start the cup dispenser, then that starts the water dispenser, then that starts the sugar (if Sugar switch is ON, if not continue), then that starts the milk (if Milk switch is ON, if not continue), then that turns off the DISPENSE bit and turns on the 5-second TOF and Complete lamp.

The Start pushbutton could be a maintained-contact or momentary-contact button. I would make the safe assumption that it is the most commonly used type for a PLC start sequence (momentary-contact so that the system can easily be auto-stopped at the end using a Complete bit). The other switches are maintained-contact On/Off switches. I would add lights that light up "Milk" and "Sugar" word displays when these switches are ON (part of the required SCADA). The Start button could also be a lighted button, with the light being controlled by a internal PLC DISPENSE-mode relay. When the machine is in active dispense mode, the Start-button is lighted, and when it finishes the the Start lamp goes OFF, and the Complete lamp comes ON for 5 seconds (use a TOF off-delay timer).
 
Last edited:
This seems a very active & helpful Forum. Thank you all for your input - it's appreciated.

Like with most / all programming I have done in the past, it seems there is many ways to accomplish the same / similar objective.

It also seems that PLC programming is quite different to what I'm used to - in terms of general approach & being aware of the Scan Cycle.

I'm aware that getting sufficient detail for the Specification is of paramount importance to make sure the finished product is as desired - & fit for purpose. I'll confirm the requirements when my Supervisor is next in the office (currently away on-site).

It might be an idea to attempt this Exercise in various ways then... - I'll make a couple of projects.

Could you recommend any Beginner Tutorials / Manuals that would be beneficial please? - I'm interested in the Continuous & Sequential differences & also the Sequential State Machine concepts.

Thanks again.
 
When you refer to continuous versus sequential and state machines you are really talking about programming concepts. The things you learned in your software engineering classes will serve you well with these concepts.

I am a firm believer that the design concept can be abstracted from the platform. Said another way, make the platform do what your design tells you that you need. Don't modify your design to shoehorn it into your platform. If the platform can't support your design you are on the wrong platform. So if this project seems to be a good fit for a state machine, then design it as a state machine and then implement it in the platform of your choice. Once you have your design concept find the available instructions to allow you to execute it. At the end of the day, almost every activity comes down to add, subtract, multiply, divide, AND, OR, greater than, less than or equal. More complex functions are just a combination of these.

When many of us talk about continuous versus sequential we are referring to process type. Your process is at its heart sequential. A continuous process would be something like speed or temperature control.

Keith
 
I am a firm believer that the design concept can be abstracted from the platform. Said another way, make the platform do what your design tells you that you need. Don't modify your design to shoehorn it into your platform. If the platform can't support your design you are on the wrong platform. So if this project seems to be a good fit for a state machine, then design it as a state machine and then implement it in the platform of your choice.
This echoes a concept I learned of thirty years ago: find the software which does the job you want done then select the hardware. I saw a (non-PLC) project which used the opposite approach and turned out badly.
 

Similar Topics

I am new to PLC programming and recently purchased a demo unit for a WAGO 750-881. I am trying to do a simple test in ladder logic that does the...
Replies
1
Views
2,267
It would be awesome if someone could help me out with this problem. We can only use basic XIC XIO OTE OTL and OTU instructions. I'm not sure on...
Replies
33
Views
8,967
We have an OMRON SYSMAC C40K-CDR-A 2065C Programmable Controller with a blown out input channel #200. All other inputs are free spares and...
Replies
1
Views
4,598
I am an apprentice so i think i can get away with what seems like a stupid question. im writing a program in RSlogix500. basically i cant work...
Replies
5
Views
17,927
This is an assignment for class. I'm about to pull my hair out on this one. All the others have been very easy using timers and counters, but I'm...
Replies
44
Views
18,582
Back
Top Bottom