You are on page 1of 4

EE 404 - Controls Lab #3

Soda Machine Controller using Ladder Logic


Objective: In lab #2, state transition logic was implemented using ladder logic. In this lab, some
of the features of ladder logic, such as adders, counters, etc., are used to design a controller. By
using such features, simpler, more understandable programs can be written.
Problem: Design a controller for a soda machine. The specifications and I/O connections are
SW-1 pulses high when a nickel is added
SW-2 pulses high when a dime is added
SW-3 pulses high when a quarter is added
Once 50 cents are deposited, Out-1 is held high for 5 seconds to dispense a soda.
To return change, Out-2 is pulsed high once every second to return a nickel.
In this experiment, a program that implements this controller is designed. This problem is broken
down into smaller tasks, allowing each step to be debugged and checked before continuing. In
this way, a larger program can be developed with spending less time debugging it.
Step #1: Clear any previous programs by going to F6: Networks, F2: Add Network, F4:
Delete, F4: Delete,... until all screens are blank. Create 6 screens by hitting F2: Add five times.
Program in the following circuit. Verify that Out1 is held hig for 5 seconds whenever 21 goes
high. (When SW-1 goes high for this test due to the last rung.)
( )
( )
00021 00031
00001
00001
00031 00001
00031
50
T0.1
40009
( ) P
10001 00021
Generate a pulse requesting
a Soda each time SW1 goes high.
(Delete for parts 2+)
Hold Out 1 on for 5 seconds
each time Soda pulses high.
Screen 1
Soda
Q1
Q1
5s
5s Q1
5s
Soda
3-1
Step #2: Delete the shaded region from Screen 1 by positioning the cursor over these elements
and hitting the delete key. Move to Screen 2 using the page Down key.
Program in the following circuit. Verify that Out2 is held high for 0.5 seconds every time 22 goes
high. This happens when SW-1 goes high due to the shaded rung of the ladder.
( )
( )
00022 00032
00002
00002
00032 00002
00032
5
T0.1
40008
( ) P
10001 00022
Generate a pulse on CHNG
each time SW1 goes high.
(Delete for parts 3+)
Hold Out 2 on for 0.5 seconds
each time 22 pulses high.
Screen 2
chng
Q2
Q2
1/2s
1/2s
Q2 1/2s
chng
Step #3: Delete the shaded region from Screen #2. Move to Screen 3 using the page down key.
Program in the following circuit. This circuit uses register 40001 to keep track of how much
money has been deposited. When a nickel is added (10001 pulses high or SW-1 goes high), this
register is incremented by 5. (and 10 for a dime, 25 for a quarter.). The subtract block
determines whether 50 or more cents have been deposited.
Verify that the register 40001 is incrementing correctly. Position the cursor over the number
40001 and verify that this count increases by 5, 10, or 25 as SW-1, SW-2, or SW-3 goes high.
Also verify that 42 is high when this counter exceeds 50 cents.
( )
( ) P
P
P
00041
00042 10001
10002
10003
25
40001
ADD
40001
10
40001
ADD
40001
5
40001
ADD
40001
40001
50
SUB
40002
nickel
dime
quarter
>50
=50
Screen 3
3-2
Step #4: Implement a soda machine which does not give change.
Move to screen 4 using the page down key. Implement the following circuit. This circuit pulses
Out1 high if the subtract block detects that 50 cents or more was deposited. After 5 seconds has
elapsed, the counter is cleared by saving 0+0 in 40001. (A crude way to clear a register, but it
works.) Recall from Step #1, 21 is the output which signals Out-1 to go high for 5 seconds. 31 is
a signal which indicates that 5 seconds has elapsed.
Verify that the soda machine waits until 50 or more cents has been accumulated. Once this
happens, Out-1 is pulsed high for 5 seconds and then the counter is cleared.
( )
00041
00042
00021
00031
0
0
ADD
40001
Pulse Out1 high when
>50 or =50 cents are
reached.
Clear the counter
after dispensing the
Soda
Screen #4
>50
=50
5s clear
soda
Step #5: Implement a soda machine which gives change.
Delete screen 4 by going back to the main menu (ESC several times) and then hit F6: Network
F2: Delete.
Move to the new Screen 4 and program in the following ladder logic program.
( )
( )
00041
00022
00022
00042 00021
00041 00022
00031
10
T0.1
40003
40001
5
SUB
40001
0
0
ADD
40001
pulse Out1 high
when change=50
While change>50,
pulse Out2
every 1.0 second
and decrease the
change by 5 cents
After 5 seconds,
set change=0
=50
>50
chng
>50
5s
chng
soda
chng
clear
3-3
This program
Pulses 21 high when exactly 50 cents has been deposited (rung #1). This results in Out1
going high for 5 seconds to dispense the soda from Screen #1.
Pulses 22 high every 1 second while more than 50 cents is deposited. This results in
Out2 going high for 0.5 seconds to return a nickel from Screen #2. (rung #2 and #3)
When a nickel is returned, 5 cents is subtracted from the counter (rung #4)
When 31 pulses signifying that a soda has been dispensed, clear the counter to zero cents
(rung 5).
Verify the operation of the soda machine.
Write-up
To compare this design to other types, design a controller for a soda dispenser using
state-transition logic. Assume that only dimes are used so that 6 states are required (0, 10, 20,
30, 40, 50).
Alternatively, assume that a microcomputer is used to control the soda machine. Write a program
for this controller using any computer language you like. Assume that program variables
NICKEL, DIME, QUARTER are available and equal to 1 if a coin has been deposited and 0 if
not. Your programs outputs are variables CHANGE and SODA which are pulsed high to return
a nickel or a soda respectively.
Assume that the price of soda went up to 60 cents. What would you have to change in your
ladder logic program? What would you have to change with your design using state-transition
logic? What would you change in your microcomputer program?
Comment on which approach (counters vs. state-transition logic) is easier to implement, easier to
modify, and easier to build and debug.
3-4

You might also like