Lab 4 - Washing Machine Controller

APSC 380 : I NTRODUCTION TO M ICROCOMPUTERS
1997/98 W INTER S ESSION T ERM 1
Lab 4 - Washing Machine Controller
Introduction
input modules plugged into the I/O module rack.
The purpose of this experiment is to use the lab computer to control a simulated washing machine machine.
– The interface between the computer and
the motors for the pumps and agitators
consists of an optically isolated DC output module plugged into the I/O module
rack.
Laboratory Apparatus
The signal conditioning board contains specialpurpose liquid-level sensor ICs. When no liquid is present a low level (logic 0) appears at
the output of the module. This logic level is inverted on the interface card so that the computer
receives a logic 1. When liquid is present at the
sensor the computer receives a logic 0.
The diagram below shows a block diagram of the laboratory apparatus.
Laboratory
Computer
Motor
Controller
Board
Hot
Pump
Hot
Tank
Cold
Pump
Cold
Tank
Signal
Conditioning
Board
I/O Module
Rack
Spin/
Agitate
Motor
Wash
Tub
The motor controller board contains the electronics to switch the pump and agitator motors
on and off. When the computer writes a logic
1 to the I/O module it turns on the motor connected to the module.
Drain
Pump
Drain
Tank
Recycle
Pump
The tanks, pumps, motors and sensors simulate
a washing machine.
Low Sensor
High Sensor
The washing machine has four tanks. The leftmost tank is for hot water storage, the next tank
is for cold water storage, the next is a wash tank
and the right-most tank is a drain tank. Note that
overflow from the hot water tank drains into the
cold water tank.
It consists of five major components:
The laboratory computer. Refer to Lab 2 for a
description.
An I/O module rack which provides an interface
between the laboratory computer’s logic-level
parallel I/O card and the circuitry that senses
and drives the I/O devices: the water level sensors, the agitator motor and the pump motors.
This I/O module rack allows different types of
I/O interface modules (input, output, AC and
DC) to be plugged in. Each module is isolated via an optical interface consisting of an
LED and a phototransistor in order to protect
the computer’s circuitry from damage:
Four pumps control the flow of water between
tanks. You will be controlling three of them to
run the washing machine. The fourth pump recycles the water in the drain tank back into the
hot and cold water tanks.
A motor with an attached propeller simulates
the wash-cycle agitator as well as the spin-cycle
motor.
There are two water level sensors (high– and
low–level) in the wash tank and one level sensor
(full–level) in the cold water tank (not shown in
the diagram above).
– The level sensor inputs to the computer
are connected via optically-isolated DC
1
The I/O module can also control two 120 volt
AC outlets and a heater in the hot water tank.
These facilities will not be used in this experiment.
3. Fill the wash tank with hot or cold water depending on the cycle selected. Filling continues
until the high level is sensed in the wash tank.
4. Turn on the agitator motor on for 15 seconds.
During this time the motor should be cycled on
and off with a pattern of 1 second on and 2 seconds off.
The I/O Interface
From the programmer’s point of view the interface
between the I/O modules and the computer consists
of three memory locations. Memory locations 0x51
through 0x53 are mapped to three 8-bit parallel I/O
ports. Each of the available 24 bits is assigned to one
module in the I/O module rack.
The following diagram gives the functions of the
bits at the different I/O addresses:
D7
D6
D5
D4
D3
D2
AC 1
AC 2
Recycle
Pump
Hot
Pump
Cold
Pump
Drain
Pump
D3
D2
D1
Spin/
Agit.
Motor
5. Empty the wash tank into the drain tank until a
low level is sensed in the wash tank.
6. Fill the wash tank with cold water. Filling continues until a high level is sensed in the wash
tank.
7. Repeat 4 above.
D0
Hot T.
Agit.
Motor
8. Repeat 5 above.
address = 0x51
D7
D6
D5
Tub
High
Sensor
Tub
Low
Sensor
Cold T.
High
Sensor
D4
D1
9. Run the spin (agitator) motor continuously for
10 seconds.
D0
10. Go back to 1 to wait for another command.
address = 0x52
D7
D6
D5
D4
D3
D2
D1
D0
If the recycle key (2) is pressed instead of 0 or 1
the washing machine should recycle the water from
the drain tank to the hot water tank until the high
level is sensed in the cold water tank.
The display on the keypad/display card should
indicate the cycle which is being executed (HOT
WASH, COLDWASH, RINSE, SPIN, or RECYCLE).
Module
Disable
address = 0x53
The 8 bits of the port at address 0x51 are connected to 8 output modules. The bits of an output
module can be set by writing the appropriate bit pattern to the appropriate location.
The port at 0x52 is connected to input modules.
Data from input modules can be obtained by reading the appropriate location and “masking in” (using
the bitwise AND operator) the appropriate bit in the
byte.
Location 0x53 has only one active output bit
which controls the power to all of the I/O modules
on the rack. If the bit is set to 1, the I/O modules are
disabled.
Procedure
Design a state machine that implements the washing
machine behavior described above. You need not include the on/off sequences during agitation in your
state machine.
Design and write a C program to operate the washing machine as described above. Your program’s
structure must reflect the design of the state machine
Washing Machine Operation
(see the lecture notes). Use symbolic constants for
the states, the i/o port addresses and the bit-masks.
The washing machine should operate as follows:
Indent your program as per K&R indentation conventions used in previous solutions. Use the keypad
1. Display ”WASH?” on the LED display.
and LED display handler routines you wrote for Lab
2. Wait for the “hot-wash” button (0) or “cold- 2. Use the function sleep() to pause your program
wash” button (1) on the keypad to be pressed.
while running the agitator motor.
2
You will have to prepare a project file, say
lab4.prj, containing the name of your C file and
the file name iolib.lib as in Lab 2. You must
also use the Project Project Name menu
item to set the project name when you start Turbo
C.
Please do not adjust any of the connections on any
of the boards or move the sensors without first consulting with the technician or the TA. You should not
need to do this.
Demonstration
Demonstrate successful operation of your washing
machine control program to one of the lab demonstrators.
Report
Submit the state transition diagram, a table showing the outputs (display and motors) for each state, a
state transition table, and the C program that resulted
in correct operation of the washing machine. Your
table may show the input conditions and outputs using the symbolic constants used in your program.
3