You are on page 1of 94

1

UNIVERSITY OF TORONTO
INSTITUTE FOR AEROSPACE STUDIES
4925 Dufferin Street, Toronto, Ontario, Canada, M3H 5T6







Vial Sorter Machine
Aer201, Team 66
Mohammad Javed, Hui (Sunny) Lin, Maricio Diaz
996654972, 996839998, 996682200
Instructor: Michael Helander
TA: Jason Kereluk
Organization: Department of Engineering
University of Toronto
Date: April 10, 201
2

Team Picture
3

Acknowledgement
On behalf of the members of team 66, Mohammad Javed, Hui (Sunny) Lin and Mauricio Diaz, I would like
to thank:
The three instructors who provided us with assistance throughout the semester.
Jason Kereluk for being an outstanding TA, and frankly one of few who believed that we would be able
to succeed in our design project. His feedback was much appreciated.
Nadeesha Amarasinghe whos eleventh hour helped saved us.
Alex Piggot, Edward Lee Kim-Koon and Danish Arshad for various advice and help throughout the
semester.
Finally, every other AER 201 team who shared the painful process of creating an autonomous machine
in the space of 3 and half months.

4

Abstract
A Request for Proposal stated the need for a vial sorter that could sort vials according to
if they were PET or HDPE; and if they are PET, whether they are capped or uncapped. The
prototype designed involved the use of a rocking funnel into which the vials were inserted. The
vials individually entered the sensing station next; where three infrared LEDs were shined onto
the vial, one on top, one in the middle and one at the bottom. Infrared sensors on the other side
detected different voltages depending on the type of vial. The PIC microcontroller, which
controlled all electromechanical components, determined what type the vial was. It then turned
the bins underneath the station according to that vial type. A solenoid-lever mechanism was used
to dispense the vial into the bin. This process was repeated until the Microcontroller determined
that there were no vials left.
The results from this design project were fairly successful, with one perfect run and a run
with one vial sorted wrongly in the Public Demonstration. While better materials could have
been used and the program could have been optimized, the vial sorter did meet the majority of
the criteria set for it (see Section 4) and thus was deemed a success.

5

Table of Contents
Page(s)
1. Symbols and Abbreviations 5
2. Introduction 7
3. Perspective 7
3.1 Theory 7
3.1.2 Infrared LEDs and Sensors Limitations 8
3.2 Survey 9
4. Objectives, Constraints, and Acceptance Criteria in Decision Making 10
Functional Overview 12
5. Budget 14
6. Division of the Problem 15
7. Circuits Subsystem 16
7.1 Assessment of Problem 16
7.2 Solution 16
7.3 Suggestions for Improvement 21
8. Electromechanical Subsystem 22
8.1 Assessment of Problem 22
8.2 Solution 22
8.3 Suggestion of Improvement 23
9. Microcontroller Subsystem 24
9.1 Assessment of Problem 24
9.2 Solution 25
9.3 Suggestions for Improvement 30
9.4 Tables 31
9.5 Code 32
10. Integration 35
11. System Improvement Suggestions 41
12. Accomplished Schedule 43
13. Conclusions 44
14. Description of Overall Machine 46
15. Standard Operations Procedure 49
16. Appendices 50
16.1 Appendix A- Code 50
16.2 Appendix B- Circuits 74
16.3 Appendix C- Gantt Chart 79
16.4 Appendix D- Data Sheets 81
17. References and Bibliography 92

6

1. Symbols and abbreviations
Symbols
Symbol Definition

Motor

NAND gate
Component of 74HC00N IC chip

Resistor

AND gate
Component of 74HC08 IC chip

Transistor

Capacitor

Diode

Battery

Ground

Voltage Regulator

110V AC outlet plug


7

1.2 Abbreviations

Abbreviation Meaning
Cct Circuit
AC Alternative Current
DC Direct Current
V Volts
A Amperes or Amps
mA Milliamps
IC (chip) Integrated Circuit
NPN Describes a transistor into which the current flows
from collector to emitter when the base is
activated. The letters N and P refer to the type
of dopants utilized to transform certain parts of
the transistor into semiconductors.
K Refers to the resistance of a resistor.
Means Kilo-Ohm (1000 Ohms)
M Refers to the resistance of a resistor.
Means Mega-Ohm (1000000 Ohms)
F Refers to the capacitance of a capacitor.
Means Micro-Farad
nF Refers to the capacitance of a capacitor.
Means Nano-Farad
NO Normally Open. Refers to a microswitch
connection.
NC Normally Closed. Refers to a microswitch
connection.
GND Ground
PIC Peripheral Interface Controller (referred generally
to the microcontroller component
EEPROM Electrically Erasable Programmable Read-Only
Memory
RAM Random Access Memory
LCD Liquid Crystal Display
I/O ports Input Output ports


8

Figure 1: A blue funnel being used to
create a small laminar stream of liquid
from the large beaker
2. Introduction

In the world of biomedical engineering, the use of vials in everyday operation is
extremely essential. They are used to store a variety of items; from blood to pharmaceutical
drugs. These small vessels have become the most widely used storage item in the laboratory. For
example, every time one buys pharmaceutical drugs, they come stored in a lip-cap vial. If one
goes to the doctors office to give any samples of bodily fluid, it is always given inside vials.
Over the years, different materials have been used to create a variety of vials, with each being for
a different purpose. Therefore it is essential to be able to differentiate these various vials. The
Request for Proposal given to Team 66 was to create a vial sorter which could differentiate
between two types of vials; HDPE and PET and whether the PET vials were capped or
uncapped.
The vial sorter which was designed by Team 66 was a fairly simple design and was
energy efficient; since it did not use more than one mechanical component at a time. In addition,
the sorter was an easy to use machine, it was able to sort much more than 15 vials, and was fairly
compact. All of these various other features allowed the design to be potentially used in an actual
laboratory. In the following sections, the design will be explained in greater detail and broken
down into three subsystems; the electrical circuits subsystem, the electromechanical subsystem,
and the microcontroller subsystem.

3. Perspective

When designing the vial sorter, many different theories and ideas were tested and
included. In the following sections, some of the different ideas which were eventually used are
explained as to where the inspiration came from and also the different limitations on the methods
used in the sorter. These different ideas include the funnel used to separate the vials individually,
the rocking motion used to move the funnel and how the sensors and LEDs were used to
differentiate between vials. Actual industrial vial sorters, however, were not used as inspirations
since most of them involved more mechanical movements than was thought necessary for this
particular design project. Despite this disparity, the vial sorters will still be discussed in the
section 6.2 Survey since it provides a good background on the design of current vial sorters in
the industry.

3.1 Theory

From the beginning of this project, one idea
which was consistently part of the groups design was a
funnel used to separate the vials. The inspiration for
this design choice stems from its use primarily in
creating laminar flow of liquid from a high volume of
liquid in a container into a small stream of liquid.
Nevertheless, the funnel as shown in Figure 1 is not
something which was viable in the design of a vial
sorter. Therefore, a triangular funnel with an opening
on the side was designed since it was more conducive
in separating vials then the vertical funnel in Figure 1.
This funnel can be seen in Figure 2.
9

Figure 2: The triangular funnel
designed to separate vials. At the red
circle represents the opening through
which the vials exit
Figure 3: rotary motion being converted into linear motion.
The funnel designed, however, is not enough to ensure the
smooth movement of vials into the sensing station. Thus the
group needed to design something which would be able to move
the funnel so the vials would exit the funnel quickly. The
different ideas which were considered were creating a vibrating
motion or a rocking motion. The inspiration for vibrating funnel
came from actual funnels which have vibrators. These funnels,
like the project, were used to separate solid objects. Nevertheless,
after some experimentation it was decided that the rocking motion
was more suitable.
In order to make the rocking motion, it was decided that a
DC motor would be used, which meant that the circular motion of
the DC motor needed to be translated into vertical movement.
There were many different techniques which could have been
used, one of which was rotary to linear conversion 1 (see Figure
3).

Nevertheless the group had some reservations about this design mainly because the
conversion was not conducive to lifting the weight of multiple vials and the conversion was
susceptible to slipping. Therefore another design was considered, one based on the movement of
a steam engine (see Figure 4).




Figure 4: A piston powered steam engine.
10

Figure 5: The red rectangle highlights the reverse steam engine mechanism which converts
the circular movement of the Dc motor into rocking motion to move the funnel up and down.
As one can see from Figure 4, the variability in the pressure makes the piston move
horizontally which in turn is converted into circular motion on the wheel. This idea was used in
reverse in order to create rocking motion to move the funnel. In the design, the circular motion
was converted into vertical movement as can be seen in Figure 5 below.














3.1.2 Infrared LEDs and Sensors Limitations

The mechanism used to differentiate vials were IR LEDs and Sensors, which will be
described in greater detail in the Circuits Subsystem. This mechanism works on creating a
voltage difference between the different materials, i.e. uncapped and capped PETs and between
HDPE and PET. While this mechanism works for this particular case, there are some limitations
on this mechanism especially if more than two different materials need to be differentiated.
Specifically, if a translucent material between HDPE (opaque material) and PET (transparent
material) is needed to be sorted as well, it could be prone to problems. This is due to the fact that
the diffractions due to extensive scratches on the bodies of PET vials can force them to be sorted
as HDPE vials, despite the seemingly large difference in voltage between the two types of
material. Therefore, if a material between HDPE and PET needed to also be differentiated, it
could cause many errors. This is limitation which is cannot be overcome using IR LEDs and
Sensors to sort between vials.

3.2 Survey

Before arriving at the final design for the vial
sorter, a survey of manufacturers which make
laboratory tools, such as BioMicroLab, was done to
learn more about the best approach to fulfill the request
given.
Figure 6: XL100 Vial Handler

11

A popular vial sorter in the market is the XL-series Vial Handler created by BioMicroLab
Inc. The XL-series Vial Handler is fully automated and it can sort all kinds of medical tubes
from micro tubes, plastic vials to glass vials at speeds up to 900 tubes per hour.
The XL-series Vial Handler can sort the vials depending on
their weight, size as well as the 1D/2D barcode that is attached on
the tubes. The XL-series Vial Handler also includes an option for
capping and decapping of the tubes. One major drawback of the
XL-series Vial Handler is the price. The prices for XL-series
easily go beyond $20,000 up to $50,000 [2].
Another popular vial sorter is the HCTS2000 High speed
closed tube sorter created by DNA BioMed. This sorter is
generally used to cut down the cost of the vial sorting employees in
manufacturing companies. This vial sorter can quickly sort the
vials at speeds up to 2000 tubes per hour. Nevertheless, to purchase
a sorter such as this, it requires the user to go through a long process at the end of which the
company gives a quote for the sorter [3].

4. Objectives, Requirements and Constraints

4.1 Objectives

The goal was to create a proof-of-concept prototype for the vial sorter which could
successfully sort vials into the three respective types, dispense in less than 3 minutes, and record
the results as well. The entire lists of objectives is listed below

1. Display the time before the user begins the sorting.
2. Correctly sort the 15 vial in less than 3 minutes.
3. Dispense the vials into three separate bins.
4. Correctly display the respective amount of vials of each type on the LCD screen.
5. Store the results in permanent memory for future access.
6. Conserve power by not having simultaneous processes and use passive mechanisms to help
sorting, e.g. gravity.
7. Allow more than 15 vials to be sorted.
8. Allow for vials to be inserted as sorting process is taking place.
9. Place dispenser bins conveniently for the user.
10. Inform the user when sorting is finished with a light signal.
11. Use of components which have the least chance of failure after extensive use.

4.2 Requirements and Constraints

Request for Proposal #3 [1] calls for the design and manufacture of a vial sorting machine
prototype. The purpose of the machine is to sort standard 20mL laboratory vials according to
whether they are made of polyethylene terephthalate (PET) or high-density polyethylene (HDPE)
as well as whether PET vials are capped or uncapped.



Figure 7: HTCS2000 Tube Sorter

12

Machine Requirements:

1. Plugs into standard AC outlet
2. Accept bulk loading of vials
3. Sort vials into 3 categories: capped PET, uncapped PET, HDPE
4. Sort a maximum of 15 vials in under 3 minutes
5. Deliver sorted vials in separate containers, each holding up to 10 vials
6. Operation started by the user via a keypad
7. After each run, inform user about operating statistics on an LCD per user request through a
keypad; operating time, total vials sorted, vials sorted in each category
8. Must have an emergency stop button

Machine Constraints per RFP #3:

1. Fits within a (.75m)^3 envelope
2. Does not exceed a mass 10 kg
3. Cost does not exceed 200 CAD
4. Must plug into 110V AC, 60Hz 3-pin outlet
5. Must be fully autonomous, with user start
6. Vial containers must be easily removable and identifiable
7. Must display a message on LCD when the machine finishes sorting
8. Must have less than 2 minutes of calibration between runs
9. Must not be hazardous; vibration, noise, mechanical, electrical
10. Prototype must be built between January 20th 2010 and April 7th 2010

Acceptance Criteria in Decision Making

The requirements and constraints set out above serve as acceptance criteria in decision
making. The chosen design was the one determined to best satisfy these requirements and
constraints.

13

Functional Overview
14

5. Budgeting
Below is a table summarizing the cost breakdowns of materials used to build our machine.
Iteam Cost
2x regular sponge $0.99
Matboard $8.00
1 wood $0.50
Acrylic plastic $0.25
Sheet metal $1.00
Cardboard $0.50
Magnet $1.99
Fuji SM55 Stepper motor $3.99
Small 12V pulling solenoid $0.99
Zheng 12V 50RPG Gear head DC motor $11.99
Plastic board $0.99
wood $2.99
1 Velcro $1.99
Brown switch $0.99
3x SFH4550 IR LED $1.41
3x LTR516AD IR receiver $2.07
2x green solder board $2.00
2x brown solder board $1.00
1 DPDT RTE24005F relay $2.14
3x 2 by 7 sockets $0.99
1x ribbon cable $3.00
15

6x 1N4001 protection diodes $1.80
6x TIP142 $10.32
2x 6 pin sockets $1.50
3x 2 pin sockets $1.40
1x heat sink $0.72
4x metal circuit peg $5.00
ATX switching power supply $15.00
24 wires $2.88
1W LED $4.00
DevBugger board $50.00
16x resistors $3.20
1x STP16NF06FP MOSFET $1.90
TOTAL $146.08


16

6. Division of the Problem
The main problems associated with the design was divided methodically amongst the
subsystems in order to ensure faster results and decrease overlap in decision making during the
early stages of the design process. This allowed each member to implement their own solutions
to various problems without having to stress over its impacts on the other subsystem. In cases of
drastic problems, a more coordinated approach was taken, examples of which can be seen in the
problems encountered in the Circuits Subsystem, which required a coordinated approach to the
solution. Overall, the key design problems were divided as such:
Electromechanical member
1. Designing a funnel in which the vials do not clog and the funnel is still movable using a DC
motor.
2. Storage bins with the ability to move using only a Stepper motor.
3. Creating a mechanism to move the funnel vertically using a DC motor
4. Creating an energy efficient mechanism to eject the vials from the sorting station into the
bins.
5. Designing a plate on which the storage bins can be placed into which the vials are dispensed
and are accessible to the user.
PIC Microcontroller member:
1. Detecting if a vial has arrived.
2. Differentiating between vials.
3. Orienting the bins below the sensing station in order to ensure ejection in the correct vial
bin.
Circuits member:
1. Creating circuits to transmit signals from the PIC to the electromechanical components,
including the DC motor, the solenoid, and the stepper motor.
2. Designing IR LED-Sensor circuit in order to create different voltages according to the type
of vial in the sensing station.



17

7. Circuit Subsystem
7.1 Assessment of the problem
The purpose of the circuit subsystem is to bridge the gap between the structural
component of the machine and the programming component of the machine. Circuits must be
built to transmit signals from the PIC microcontroller to allow the controlling of the
electromechanical components such as the DC motor, stepper motor and the solenoid. A
MOSFET circuit was initially planned to transmit the PIC signal to the electromechanical
components. When the PIC sent out a 5V signal to the MOSFET, the gate of the MOSFET
opened turning on the desired actuator circuit.
The circuit subsystem must also include a circuit that can differentiate between the
different types of vials. An IR LED-sensor circuit was designed and built to differentiate
between the different types of vials so that the PIC microcontroller can move the actuating parts
accordingly to sort them. The voltage of the IR receiver circuit changed accordingly to each type
of vials. These voltages were directly sent to the PIC microcontroller for the program to
differentiate between the vials.
The circuit subsystem must also include an emergency switch button that can stop all the
actuating circuits when pressed. The emergency switch button must be implemented to
guarantee the safety of the users from any danger that the machine may impose.

7.2 Solutions

DC motor circuit

The DC motor was used to run the
rocker that oscillated the V-shaped funnel
up and down. The DC motor is a high
torque 12V, 50 RPM, Gear head motor. A
high torque motor was because it takes a lot
of torque to oscillate a funnel filled with
vials. The 50 RPM was chosen so that the
V-shaped funnel would oscillate once in 1.2
seconds. It was found through
experimentations with the V-shaped funnel
that a period of 1.2 seconds for rocking was
effective in feeding the vials into the machine.
The initial DC motor circuit is shown in Figure 3a). It is attached to a MOSFET so that
the DC motor can be turned on and off by the PIC. A MOSFET was used for the same reason as
the initial sensor circuit. It was wanted for the PIC to be able to control the on and off of the DC
motor for two reasons; minimizing power consumptions and stability during the vial sensing.
The Analog-to-digital converter on the PIC is very sensitive and any significant vibration of the
machine caused by the oscillation of the funnel may cause the deviation the voltage readings of
the receiver.
The final DC motor circuit as shown in Figure 3b) uses a TIP instead of the MOSFET.
The MOSFET was replaced with the TIP because the MOSFET was very sensitive to static and it
broke very frequently. The DC motor circuit requires 130 mA of current to operate.
Figure 8: Zheng Gear head DC motor

.

18


Solenoid circuit

The initial circuit for the solenoid is shown in
figure 4a). The solenoid is attached to the MOSFET
so that the PIC can control the on and the off and the
solenoid. There is also a 1N4001 protection diode
connected in parallel with the solenoid to protect the
MOSFET from breaking due to any backward current
from the solenoid.
To fix the MOSFET issue, it was decided to
take out the MOSFET because it broke very frequently
like the other circuits as shown above. However,
through experimentation it was found out that the
voltage drop across the TIP was approximately 5V. This meant that the solenoid was not
receiving enough currents in order to drive it. To fix this issue, the solenoid circuit design was
changed as shown in figure 4c). The final circuit uses TIP to turn on the relay to drive a separate
solenoid circuit. When the relay closes, the gate for the solenoid circuit also closes, allowing a
full 12V drop across the solenoid. The RTE24005F relay was relay because it is double pull
double throw relay and it can take up to 4A. It was important to select a relay that can take up to
4A because the solenoid draws as much as 3A when it is activated.
The double pull double throw relay could have been replaced with a single pull double
throw relay. The other pole of the relay is completely useless. Using a single pull double throw
relay would reduce the cost and would take less space on the solder board.

Stepper motor circuit

The Fuji SM55 stepper motor was used because stepper
motors are accurate. The stepper motor was attached to the
hexagonal bucket, which was what the vials are put into after
sorting. The bucket requires 120 rotations, which the stepper
motion can provide in 16 steps (48 steps for a full revolution).
Although the SM55 motor is a cheap motor that is not one of the
most extremely accurate stepper motors, it was enough for the
machine because it only dealt with approximate 120 rotations,
which didnt require extreme accuracy. Stepper motors work by
turning successive magnetic poles on, which rotates the shaft of the
motor. The speed of the rotation of the stepper motor can be
controlled by changing the speed at which the magnetic poles are
turned on. The direction of the motor can be controlled by changing the orientation in which the
magnetic poles are turned on. The way to run a stepper motor is shown in the table below

Figure 9: Small 12V pulling solenoid


.

Figure 9: Fuji SM55 Stepper
motor
.

19

.




The stepper motor was planned to be controlled using the PIC microcontroller connected
to a 2-to-4 demultiplexer, resistor and a MOSFED as shown in figure 6a). In the initial circuit,
the demultiplexer was taken out of the circuit as shown in figure 6b) because a slight change in
the PIC programming code was made to directly send out 4 signals from the PIC to the four
MOSFETs to pulse the stepper motor. When the PIC sends out a signal, the gate of the
MOSFET opens and a 0V signal is sent to that specific wire, which activates that magnetic pole.
In the middle of the circuit testing process, a design change was made to use the Driver Board
Version 2.0 because the MOSFETs on the stepper motor driver kept on breaking. The Driver
Board was also planned to replace the DC motor circuit as shown in figure 3a) because it can run
the DC motor as well. However, the Driver Board Version 2.0 was found to be unreliable on
many occasions such as the sudden stop of the turning of the stepper motor and the failure to turn
the DC motor. Due to the unreliability of the Driver Boards, a new stepper motor circuit was
created.
The final stepper motor circuit uses four TIPs as shown in figure 6c). This circuit is
essentially just the MOSFETs in figure 6b) replaced with TIPs. As stated previously, the TIP is
much less sensitive to the static than the MOSFETs, which provided a more reliable way to turn
the stepper motor. The stepper motor circuit uses as much as 470 mA to operate because thats
how much current is required to turn on a single magnetic dipole.

Sensor circuit

The sensor circuit was designed to differentiate between the
3 types of vials; UPET (uncapped PET), CPET (capped PET) and
HDPE vials.
The initial sensor circuit involved 3 infrared LEDs and 3
receivers connected in parallel as shown in figure 1a). Figure 1a)
only shows one pair of infrared LED and
receiver but the actual circuit composed of
3 pairs of infrared LEDs and receivers
connected in parallel. The LEDs used in
the circuit are the SFH4550. The
SFH4550 was chosen because it emits
light in the wavelength range of infrared
radiation.
Choosing an infrared emitter was important because IR
receivers wouldnt want the background noises such as the ambient
lights to interfere with their readings. The SFH4550 was also chosen
for the emitter because of its small half angle of 3 . Having a half
angle of 3 minimized the amount of light diffusion. This was important in the design because
the 3 LEDs that composed the overall sensor mechanism were placed at approximately 3 cm
apart. A small diffusion angle guaranteed that the LEDs respective coupling receiver will not be
influenced by light sources that are coming from the other LEDs. The LEDs are placed 3 cm
RED BROWN ORANGE BLACK Yellow
12V 0V 12V 12V 12V
12V 12V 0V 12V 12V
12V 12V 12V 0V 12V
12V 12V 12V 12V 0V
Table 1: Stepper motor signals for turning the motor
.

Figure 10: SFH4550
Infrared LED
Figure 11: LTR516AD
Infrared light receiver
20

apart because one at each end is required to detect the presence of
the cap and one in the middle to differentiate between the translucent
and the transparent vial. One LED in each end was required because
the vials can be in two different orientations at the sensor stage as
shown in the figure on the left.
For the receiver, LTR516AD was used because of its wide light
receiving angle of 120. This angle guaranteed that the light emitted
by its respective coupling LED would be detected.
The following table summarizes the voltage readings on the
receiver for each of the corresponding types of vials. These voltage
readings were directly sent into the PIC input to be converted into
digital signals.

The initial sensor
circuit was connected to
the MOSFET
(STP16NF06FP) because the turning on and off of the
sensor circuit to optimize power consumption using
output signals from the PIC was wanted. The PIC
would output a 5V signal into the MOSFET, which
opened the gate of the MOSFET turning on the sensor
circuit. When the PIC was done with the sensing the sensor circuit would be turned off by
sending a 0V signal through the PIC to minimize power consumption. The MOSFETs was used
instead of a TIP because MOSFETs do not generate a lot of heat. The MOSFETs are voltage
driven and instead of currents, which meant low power dissipation from the MOSFETS. The 5.1
Kilo Ohm resistor next to the PIC was determined using the rules of thumb for connecting the
PIC circuit to the MOSFET so that the backward current will not burn the PIC. The resistances
for connected in series with the infrared LEDs and the receivers were determined using the
equation, R = (V
source
1.6)/I
F
. V
source
is 5V, V
LED
is 4V and the I
F
is 30mA. From this, the
resistance for the LED circuit was calculated to be 100 Ohm. This sensor circuit required less
than 300 mA in current to operate.
Later in the design process, sensor circuits design was changed as shown in figure 1b.
The actual sensor circuit composes of 3 pairs of infrared LEDs and receivers connected in
parallel. This was done because the MOSFET that was used to control the lights kept on
breaking. The MOSFET is very sensitive to static and it broke very frequently. Even moving
the circuit around the air caused the MOSFET to pick up the static in the air which caused it to
break. After the MOSFET broke, the gate was usually closed which meant that the infrared
lights could never turn on. In order to resolve this issue, the MOSFET was taken away and a
design change was made to directly connect the sensor circuit to the power supply. This means
that the sensor circuit is turned on as long as the power supply is on. This also made the
programming task easier because the PIC no longer needed to send signals to turn the lights on
and off. The voltage regulator used to convert 12V into 5V as shown in figure 1a) was also
taken out of the circuit because the ATX switching power supply that was bought included a 5V
power outlet.



Vial Type Voltage (V)
Cap 3.66
PET body - 0.25
HDPE body 1.00
PET Threading 2.00
Figure 11: Two possible
orientation of the vials when
coming into the sensing station.
The rays in the image represent
the LEDs.
Table 2: Different voltages received from
the different material types
21


Other Circuit Components

Indication light circuit
The indication light is used to tell the user that the machine has finished sorting the vials.
A 1W green LED was chosen because 1W is extremely bright. The brightness of the 1W green
LED is enough to tell the users who are far away that the sorting job is accomplished. The 23
Ohm resistance was calculated using the equation R = (V
source
- V
LED
)/I. The source voltage is
5V and the current that passes through the LED is 150 mA. The LED can take up to as much as
330 mA but it was decided that 330 mA would make the LED too bright for the users. The final
circuit for the indication light is shown in figure 5. A MOSFET was used in the circuit to control
the turning on and off of the light. It never had to be replaced with a TIP because the MOSFET
used for the indication light circuit never broke.

Power Supply

The initial power supply that was bought to power
the machine was 12V wall mount power supply. A wall
mount power supply was wanted because of its small size
and ease of use. However, it was found that the wall
mount that was bought can only supply 650 mA. The
solenoid circuit draws as much as 3A, so the wall mount
is not nearly enough to activate the solenoid.
The final power supply is an ATX power supply design to
supply powers to computers. This power supply was
chosen because it can supply more than 3A.
Furthermore, it has many terminals and many different
voltages to choose from. The table below shows the voltage through each of the power supply
wire.
Red Yellow White Blue Green Black
Voltage +5V +12V -5V -12V Power on Ground
Current +30A 9A 1A 0.5A 0A 0 A


In order to for the outlet power to reach the power supply, the green wire must be
connected with any of the ground (black wires).

Emergency stop switch
The emergency stop button was implemented to stop the entire machine (cut off its
power) except for the PIC microcontroller. To implement this, a switch was put right after the
main power line for all the actuator circuits (DC motor, stepper motor and solenoid). The
DevBugger board was connected to a parallel power line that was independent of the main power
line. After pressing the emergency stop button, the switch opens and creates an open circuit,
which will shut down the entire machine. However, the DevBugger board doesnt shut off
because the power supply for the DevBugger board is independent of the power supply for the
rest of the machine.

Figure 12: ATX switching power supply
Table 3: Voltages through each power supply
22

7.3 Suggestions for Improvement

The circuit subsystem of the machine can be improved in many different ways.

1. Streamlining the organization of the circuit elements on the solder board
Currently, the machine utilizes 4 solder boards. If the circuit elements are organized
appropriately, the entire circuit for the machine can fit on 3 solder boards. This reduces the
amount of space occupied by the circuit as well as the mess caused by it.
2. Cleaning the wiring of the circuits
The current machine has wires stretching everywhere. The wiring can be organized in a
cleaner fashion. By doing this, the debugging on the machine would be made much easier.
3. Using a Single Pull Double Throw relay for the solenoid circuit
The current solenoid circuit uses Double Pull Double Throw relay.
One of the poles of the relay is unused. This DPDT relay can be replaced with a SPDT
relay, which reduces the overall cost of the machine as well the space that the relay
occupies on the solder board.































23

8. Electromechanical Subsystem
8.1 Assessment of the Problem
1. design of a non clogging ramp which releases vials in a controlled and predictable
fashion and is light enough to be raised by the DC motor
2. design and implementation of a crank to convert rotational motion from DC motor to
linear motion to rock the ramp up and down
3. design and implementation of a removable method to affix the vial bin to the stepper
motor
4. design and implementation of a lever to allow the solenoid to launch vials whilst
conserving power
8.2 Solutions
1. In order to stop the exit hole of the ramp from clogging, it was decided to rock the ramp up
and down. This ensures that if the vials clog the ramp then the next time the ramp reaches its
maximum height the vials will be in a slightly different orientation, eliminating the probability of
an infinite clog.
The opening of the ramp was a much calibrated shape and size; too large and the exit of vials
becomes unpredictable, too small and the opening will clog easily. The hole was empirically
enlarged until it was estimated that enlarging it further would result in loss of predictability.
In theory very little force should be required to accelerate the ramp if the only energy required is
for acceleration. However, this would require the crank to have a counterweight to counteract the
full weight of the ramp. This would also require frictionless operation of the crank. This not
being the case, force is required to first cancel the force of gravity of the ramp, and additionally
to provide acceleration to the ramp. Force is also required to match
friction. For this reason theoretical calculation is not likely to yield
accurate results unless it is very complicated. To be safe the lightest
material possible was eventually used; cardboard.
2. The stroke length of the crank was decided to be 6cm. Any longer than
this and the lowest position of the crank would compromise the desired
decline of the ramp at its lowest position. The designed crank is similar to a
typical slider-crank, with a rectangular bar as the slider going through a
guide jacket. A shaft collar was secured onto the motor shaft with a
setscrew; epoxy was also used due to suspected setscrew loosening. Bar 1
(see Fig. 19) was bolted onto this shaft collar. Bar 1 was affixed to bar 2
using a bolt, a nylock nut, and a washer. The washer was placed between
bars 1 and 2 and was well lubricated. This provided space between bars 1
and 2 to reduce friction. The nut and bolt could not be tightened because
Figure 19: Three
piece crank

24

this would act as a rigid connection instead of a pin. Thus the nut and bolt had to be placed
loosely. A regular nut would come loose in such a situation, therefore a nylock nut was used
which grips very tightly onto the threading of the bolt. Bar 2 was affixed to bar 3 in the same
manner. The bars were constructed of thick gauge steel sheet. Bars 1 and 2 were strategically
bent along their lengths to increase their longitudinal resistance to buckling.
3. Originally the stepper motor shaft had a gear affixed to it. The vial bin had a hole in the shape
of this gear cut into the middle of its base. The gear fit loosely into this hole causing the stepper
motor to skip undesirably. The modified design had a disk glued onto the stepper motor shaft.
The bin can be connected and disconnected from this disk using Velcro. This provided much
greater operating reliability and precision of the stepper motor whilst still satisfying the
requirement of a removable bin.
4. The solenoid used was a pull-type. Thrusting type solenoids
are not readily available. In order to use a pull-type solenoid to
push, the solenoid would have to be on all the time and would
have to be turned off when a push was required. With the use of
a lever a pull motion can be converted to a push motion. The
solenoid can be off all the time until a push is required, then
solenoid can be activated and pull on the lever which pushes the
other end. The latter design utilizes much less power since the
solenoid is on only when a push is required. The solenoid lever
was constructed of steel sheet. The lever was connected to the
solenoid using a pin (bent nail). The pivot of the lever was a
nail hammered into the support structure. The length of the
lever (longer on the pushing side than the pulling side) also
allowed a longer (faster but less powerful) stroke to ensure the vials were launched with
sufficient velocity to reach their target.
8.3 Suggestions for Improvement
The electromechanical subsystem could be improved in the following ways:
Use of more permanent/robust materials. E.g. thin wood board instead of cardboard,
proper L-brackets instead of bent pieces of thick steel sheet.
Increased precision of construction. Imprecise construction meant much empirical
calibration was required. This would not be suitable for mass production, where
everything needs to work the first time.
Increased aesthetic value. The appearance of the machine prevents it from being a
marketable product.
Improved vial feeding design. The current design, though highly reliable, still clogs on
rare occasion.
Figure 20: Pull type solenoid
attached to lever, allows less
power consumption when
used to thrust

25

Figure 21: The red dot symbolizes where
the micro switch would have gone.
9. Microcontroller
This PIC member of the group was responsible for controlling the various mechanisms
and processing information received from electrical components. In the case of the vial sorter,
the member was responsible was creating assembly language code which would run on a
PIC16F877 to control a DC motor, a Solenoid, a Stepper motor, and process information from
the IR LED-Sensor electric circuits used to differentiate the different vials. In addition, the PIC
must also create a LCD-Keypad User interface and as a bonus, read and write to Real Time
Clock provided on the DevBugger Board (on which the PIC was mounted) and the EEPROM
memory on the PIC.
The original pseudo code for the entire program is provided at the end of this section as
summary, most of the changes will be discussed in detail in Section 8.2. While the entire
machine code can be found in Appendix A

9.1 Assessment of the Problem

Controlling the motors and actuators was judged to be an almost trivial task since it
mostly required one line of code for controlling the DC motor and Solenoid and a simple looping
function for controlling the Stepper Motor. In the case of the LCD-Keypad User Interface, a
START button was required to begin operation and a log entailing the statistics of the different
vials after the run. The real tasks in this design project were to:

1. Detecting if a vial had arrived:
The problem was that there needed to be a way to
detect if a vial has entered the sensing station so the
process of differentiating could be done. Earlier in the
project it was to be done using a micro switch but later it
was decided that the force needed to be applied to the
switch in order to send a signal from it was more than the
vials could provide. Especially since the only place for the
micro switch could be on the rightmost side of the sensing
station which did not allow for too much of the surface
of the vial to touch it. See Figure 21.

2. Differentiating between the vials:
After the vials had arrived inside the sensing station, a way of differentiating the vials
was necessary. The circuits member had created a IR LED-Sensor circuit which was able to
give fairly different voltage readings for key components of the vials, namely the cap of a
vial, the threading of an uncapped PET vial, the body of the PET vial, and the body of a
HDPE vial. These voltage differences can be found in Table 4 at the end of the section.

3. Orienting the bins below the sensing station in order to ensure ejection in the correct
vial bin:
After the PIC had determined that the type of vial it was, the vial needed to be dispensed
into the correct storage bin, which was mounted on a Stepper motor. Therefore, an efficient
algorithm was needed which would be able to do this without unnecessary movements which
would lead to longer runtime for the machine.
26

Figure 22: DCLOOP is the primary looping function which determines if a vial has entered the sensing station.

In addition there were also minor problems which were dealt with:

1. Getting the correct logs: In order to display the log for the sorted vials, an algorithm
was required which would convert double digit numbers from binary into ASCII
characters to be displayed on the LCD.
2. Reading and writing to the Real Time Clock on the Devbugger Board and the
EEPROM memory.

While it is stated above that running the DC motor and the Stepper Motor were trivial tasks,
in the case of the drastic changes made due to a problem encountered in the Circuits Subsystem,
the method of control was changed and it will also be examined.

9.2 Solutions to Major Design Problems:

Detecting vials

In order to detect if a vial has entered the sensing station, so the differentiating process
can begin, the Analog to Digital Convertor was utilized. The A/D Convertor was a component
provided in the PIC which was able to take an Analog Voltage signal and convert it into a digital
binary number. The A/D Convertor requires approximately 20 microseconds in order to convert
the signal. The signals which needed to be converted were from sensor voltage readings from the
the IR LED-Sensor circuit in the sensing station of the vial sorter (see Figure 13). The circuits
gave a Voltage of 0 V (See Table 4) when no vial was inside the sensing station. Likewise, the
AD Convertor, the code for which was provided in the Course Notes (7-61), also returned a
value of 0x00.
The reading was utilized to test if a vial had arrived using the code displayed above. The
code is in the form of a loop which tests only the sensor at the rightmost end of the sensing
station (see Figure 33) and compares the value to 0x00. This is done by subtracting from 0x00
the value retrieved from the A/D conversion in every loop. When the value of the subtraction is
negative, a zero is placed in the C bit of the Special Register, STATUS. This change is tested
through the mnemonic btfss, which skips the next line if the bit being tested is one. Therefore, as
27

Figure 23: CHECK2 validates if a vial has actually arrived in the sensing station by checking either ends
station for the top of a vial.
long as no vial had arrived, the program would skip to the goto mnemonic which returned the
program to top of the function, namely DCLOOP, where it would repeat itself.
The rightmost sensor was used since if detection was done here, it meant the vial had fully
arrived inside the sensing station, as opposed to the other two sensors sensing vials. The HDPE
vials would be easily be able to give values higher than 0x00 from the A/D conversion while the
PET vial body would not (see Table 4). In worst case scenario, the PET vial would move into the
sensing station bottom first, in which case the only section of the vial which would give a value
above 0x00 is the enclave at the bottom of the vial (see Figure 33). Therefore, in order to ensure
that this vial is detected, the function loops every 20 microseconds since that is the acquisition
time.

In the case of value higher than 0x00 being retrieved by the A/D conversion, the program
would enter a secondary check, which would then compare the value currently retrieved against
the threshold value of the threading for an uncapped PET (see Figure 23 above). In the code, the
comparison is done to the ADCONV0 register since during every run of the A/D convertor
function; the digital value is stored in the working register, W, and ADCONV0. If the value was
found to be lower than the threshold value then the Analog voltage from the leftmost sensor was
retrieved and it was then compared to the threshold value. The method of comparison was
similar to one done in the primary loop of the program, DCLOOP. If neither value was bigger
than the threshold value, then the program returns to the original loop, DCLOOP, otherwise if
either value was larger than the threshold, than the program goes into the differentiating section
of the code, which will be discussed later in the Microcontroller section. In addition, the
acquirement of the threshold value for the threading for an uncapped PET will also be discussed
later on.
The reason behind having this elaborate secondary check was due to cases wherein the
A/D convertor would return values of 0x01 or 0x02 which would trigger the program to believe a
vial had entered when in fact it did not. Therefore, a secondary check was created to make sure
this does not happen. The logic behind the secondary check was that all vials would contain a top
on which there was either a cap or the threading onto which the cap is screwed on. Table 4 shows
that the threading value was lower than the cap value and for the PET vial threading was lower
28

Figure 24: OneSecondCheck is there to make sure that no PET vial, bottom first has entered the station
undetected, as was the case during some testing.
than the HDPE vial threading due to the difference in material. Therefore the digital value of at
least one end of any vial must be bigger than or equal to the voltage from the threading value of
the PET vial. The threshold value used is lower than the lowest documented value for the
threading on a PET vial.
In the case that the bottom enclave of a PET vial was not sensed since it passed through
the third sensor during the acquisition delay, the program checks every second if the leftmost
sensor has the threading part of the vial using the same threshold value as discussed earlier.

Differentiating between the vials

In order to differentiate between vials, the same threshold value method as discussed
earlier was used. For example, the threshold value between the body of an HDPE vial and a PET
vial is 0x50. This value means that any HDPE vial would always have a value above this
threshold value, while every PET vial is below this value. Similarly, there was also a threshold
value between the threading of a PET vial and a cap of a vial. These threshold values can be
found in Table 4. The method of differentiating according to the threshold value is the same as
the method of differentiating if a vial is there or not. The program subtracts the retrieved value
from the set threshold value, and according to the result (which can be seen on C bit of the
STATUS register) it is determined what type it is.
In order to arrive at these threshold values, rigorous testing was done beforehand. This
testing consisted of using two different programs utilizing A/D conversions. In both programs,
three consecutive A/D conversions were done, each corresponding to a sensor, continuously in a
loop. In one program the highest binary value ever acquired was displayed on the LCD screen
for each sensor. While in the other program, the lowest value ever acquired was displayed on the
LCD screen for each sensor. The maxvalue program, as it was called, was used to arrive at the
highest value possible for the body of a PET vial and the threading of a PET vial. While the
leastvalue program, as it was called, was used to arrive at the lowest value possible for the cap of
a vial and the body of a HDPE vial (see Figure 25). These values were obtained through testing
each characteristic on every vial available to the group. In addition, the vials were also rolled
around in order to account for variability on the vials. The numbers retrieved were then used in
29

Figure 25: the leastvalue function which displays the lowest value ever retrieved for each sensor on the
LCD screen.
the same way as the detection of a vial was done; using subtraction with a threshold value and
comparing the result. The differentiating functions can be found at the end of section.

The maxvalue function is the exact same as the above function, with the btfsc mnemonic
after the subtraction substituted with btfss to ensure that the highest value is retrieved instead of
the lowest value.

Orienting the bins below the sensing station in order to ensure ejection in the correct vial bin

In order to orient the bins below the sensing station to the correct one, so when the
solenoid ejects the vial from the station it falls into the correct bin, a 9 case program was derived.
In this 9-case program, two values were compared, previous vial value and current vial value.
Each vial is designated a value; 1 for uncapped PET, 2 for capped PET, and 4 for HDPE. The
previous vial value was set to 1 as default. In order to get a better understanding of the program,
an example is necessary. If one assumes that the first vial is uncapped PET, then a 1 is stored
initially in the current vial register, CURVIAL. In the previous vial check, the program enters
TURN0, after this, the program checks the value of CURVIAL. In this case it is 4, therefore it
fulfills the last condition of TURN0, REVTURN. The function REVTURN is called, which turns
the stepper motor, on which the vial bins are, 16 steps in the anticlockwise direction. These 16
steps correspond to a 120 degree angle turn. Thus now the bin directly below is the HDPE vial
bin, so the solenoid is activated and the CURVIAL value is inserted into the PERVIAL register.
For the next vial, the program will not enter TURN0 but rather TURN2 since the PERVIAL
value has changed from before. Similarly, if it was an uncapped PET vial earlier, the PERVIAL
value would be 2 and the program would go into TURN1.
30

Figure 26: The 9-case stepper motor function, the red boxes symbolize the previous vial and the green boxes
represent the current vial in the station.



This method employed because it is believed to be the most efficient way of dispensing
the vials since it did not involve any unnecessary movements. The maximum amount of turns
possible for 15 vials is 15 turns which is the minimum for the worst case scenario. The 9-case
program can be found at the end of this section.

Minor Problems:

Generating correct logs

In order to generate correct logs, the vials were counted after differentiation. The method
used was that the 4 least significant bits stored the first digit, while the 4 most significant bits
contained the second digit; for example 19 was stored as 0001 1001. In addition, all the numbers
were then converted into ASCII character by breaking the numbers in two binary registers, and
adding 0x30. The code for these two functions can be found at the end of the section

Reading and Writing to EEPROM and Real Time Clock

Both of these functions were derived using various information in the Course Notes (7-
19, 7-20, 7-70) and the PICMicro Manual. In both cases significant time was required in order to
achieve the required result of storing information or writing time to the Real Time Clock.




31

Drastic changes caused by Circuit changes

Some drastic changes were made to the method of controlling the DC Motor and the
Stepper Motor since the Driver Board was being used instead. In order to accommodate this
change, the method of controlling the mechanism as outlined in the Driver Board Manual was
applied. In these methods, both motors were now pulsed instead of simply sending a constant 5
V On signal. Nevertheless, due to the extensive instructions provided in the Driver Board
Manual, this was not a strenuous effort.

9.3 Improvements to the subsystem

Not many improvements could have been made in terms of running the mechanisms
since the method of operation was fairly standard. In regards to the method of processing the
information being provided from the IR LED-Sensor circuits, not much improvements can be
envisioned due the limited nature of the assembly language being used. For example, for both
HDPE and PET vial bodies, there are certain ranges in which all the values of each kind can be
found. A fool proof method would involve deriving these two ranges after extensive testing of
each type. After this is done, then one can easily check against the two ranges to know where the
value being tested falls. The best method of implementing this strategy in Assembly language is
what was implemented in the differentiating program described above.

Runtime for the Vial Sorter

The only thing which could have been changed was how the runtime for the sorter was
determined. The program used for the vial sorter used internal timer registers in order to do this,
namely, Timer1. This timer would raise interrupts whenever it had overflowed, i.e. it had
reached 0xFF and was reset to 0x00. The problem with the internal timer was the fact that during
AD conversions interrupts could not be made, and since the majority of the program was running
AD conversions, this meant that the counter regularly overloaded without it being accounted for
by program itself. Due to time constraints, this problem was not dealt with properly which
resulted in the wrong time being displayed during runs. This problem could have been dealt with
by utilizing the Real Time Clock wherein the time when START was pressed is recorded and
then when the run is completed, subtracted from this final value.

Nevertheless, little changes can be made to make the code a little more efficient and
decrease runtime, something which was not possible during the project due to the many other
issues at hand.

1. Streamlining the programming code

The current programming code has many redundant lines which reduces the overall
efficiency of the program. The redundant codes can be removed to make the code much
more efficient.




32

Table 4: Contains the voltage given from the sensors for each vial type and the
threshold binary value which is the effective lower bound of each type.
2. Organization of the programming code

The current code is messy in many areas making the debugging of the code extremely tough.
The code should be cleaned up and more comments should be inserted.

3. Calibrating the delays in the code

The delays in the current code are not calibrated perfectly for maximum sorting speed. The
stepper motor can be made to turn much faster, the solenoid can be made to activate for less
time and the delays between A/D conversions could be decreased significantly. This would
reduce the overall time it takes for the machine to finish sorting the vials.

9.4 Tables






Vial Type Voltage (V) Threshold Binary Number
No Vial 0.00 B0000000
PET vial body 0.01 B00000001
HDPE vial body 1.00 B01010000
Threading of PET vial 2.00 B10000000
Cap 3.66 B11100000
33

Figure 27: the original pseudo code
9.5 Code
Pseudo Code
34

Figure 28: Code storing the different logs for each vial type in a hexadecimal fashion but with four-bit
numbers ranging from 0-9, not 0-F (STORE). CHNGS contains code for changing each counter into
two ASCII characters to be displayed. In the case shown above, it is the vial counter.


35

Figure 29: Code for the 9-case orientation function for determining which bin to
place under the sensing station.
36

10. Integration
The process of integration started in the 8
th
week of the design project right after the
second individual evaluation. Individually, the PIC program and the circuits were entirely done
and ready for integration. However, the structural component of our machine was lagging
behind, so it was decided to integrate the PIC program with the circuit first.
Stage 1: Programming and Circuits integration
Firstly the circuits were tested with the DevBugger board. This involved the circuits
sending signals to the PIC and PIC turning on the circuits by sending out signals. Three 2-by-7
sockets were soldered onto a solder board. The ribbon cable was used to connect the DevBugger
board with the solder board. Wires and alligator clips were used to connect the sockets with the
signal pins of the MOSFETs.
1. Experiment: Tested the MOSFET motor circuit through PIC sending 5V and 0V signal
through one of its I/O pins.
Result: The motor turns when the PIC sends a 5V signal to the MOSFET. The motor stops
when the PIC sends a 0V signal to the MOSFET.
Problem: The motor doesnt rotate at the same speed as when powered directly through the
power supply.
2. Experiment: Tested the motor by powering it directly through the power supply.
Result: The motor rotated at its normal speed of 50 RPM. There is a problem with the
MOSFET motor circuit. One possibility is that 5V is not enough to completely turn on the
gate of the MOSFET.
3. Experiment: Tested the MOSFET sensor circuit through PIC sending a 5V signal.
Result: The IR LEDs turned on when PIC sent a 5V signal. The voltage drop across the IR
receiver measured using a multimeter is still the same as from before.
4. Experiment: Tested the MOSFET solenoid circuit through PIC sending a 5V signal through
one of its I/O pins.
Result: The solenoid pulls itself back when the PIC sends a 5V signal.
Problem: The solenoid sometimes does not pull itself back. The solenoid was checked to
see if there was any current going through the solenoid by manually pushing it back a little.
The solenoid pulled itself back the moment one pushed it back a little.
5. Experiment: Tested the solenoid by directly connecting it to the power supply.
Result: The solenoid pulls itself back consistently. This proved that there was something
wrong with the MOSFET solenoid circuit that limited that amount of current going through
the solenoid. One possibly is that 5V is not enough to completely turn on the gate of the
MOSFET.
37

6. Experiment: Tested the stepper motor circuit through the PIC sending 5V signals to each of
the four signal wires of the stepper motor.
Result: The stepper motor turned.
Problem: The stepper motor jerked around in an expected manner. The wiring of the stepper
motor is wrong. The magnetic poles of the stepper motor are not turned on in the right
order.
7. Experiment: Tested the stepper motor circuit through the PIC sending 5V signals to each of
the four signal wires of the stepper motor. This time, the stepper motor signal wires were
made sure to be in the correct order.
Result: The stepper motor did not turn.
Problem: We manually rotated the stepper motor slowly to check the activation of the
magnetic poles. We found out that only 2 out of the 4 magnetic poles turned on. One
reason for this is because the PIC is not sending enough voltage through its I/O port.
8. Experiment: Tested the output voltage of the I/O port from the PIC using a multimeter.
Result: The PIC was not sending 5V from some of its I/O ports.
Problem: The PIC is supposed to send a solid 5V but the multimeter is not reading that
voltage. The output voltage of the PIC read anywhere from 1.0V to 3.0V during the
measurement. Output of the PIC to signal the stepper motor was changed into other pins.
9. Experiment: Testing if the output voltages of those pins are 5V.
Result: The output voltages of those pins were not 5V.
Problem: The PIC is sending a 5V pulse, not a long 5V signal. Therefore the multimeter is
measuring the average voltage instead of the pulse. We then changed the program so that
the PIC would send a longer 5V signal.
10. Experiment: Tested the MOSFET stepper motor circuit with the new algorithm.
Result: The stepper motor was jerking back and forth.
Problem: Only 2 out of the 4 stepper motor magnetic poles were activating. All 4 outputs
from the PIC is sending 5V signal. The problem relies in the MOSFET stepper motor
circuit. Two of the MOSFETs used in the stepper motor circuit might be broken. The two
MOSFETs that corresponded to the stepper motor magnetic poles that didnt activated were
replaced with new ones.
11. Experiment: Tested the new stepper motor circuit through the PIC.
Result: The stepper motor turned normally.
12. Experiment: Tested the 1W indication light circuit through the PIC.
Result: The indication light turned on.
38

13. Experiment: Tested the A/D converter code on the PIC by connecting the A/D converter
input port on the PIC with the IR receiver reading.
Result: The A/D converter read some sort of a voltage reading from the IR receiver.
Problem: The voltage coming from the IR receiver seems to be fluctuating. The problem
may be that the PICs ground is kept floated (not properly grounded). The PIC must have a
common reference ground voltage with the rest of the circuit in order for it to read the
voltage of the IR receivers.
14. Experiment: Tested the A/D converter code on the PIC with the PIC having a common
reference ground voltage with the sensor circuit.
Result: The A/D converter read the correct voltage off the IR receiver consistently. These
values were used to differentiate between the different vials.
15. Experiment: Ran the main PIC program that did a single complete run. This meant that the
PIC program ran the DC motor until the sensors detected the presence of a vial in the
sensing station. Then, the stepper motor would turn accordingly depending on the type of
vial and the solenoid would push the vial out of the sensing station.
Result: Everything worked perfectly except for the turning of the stepper motor.
Problem: The MOSFETs may have broken again. The MOSFETs for the stepper motor
circuit were replaced.
16. Experiment: Ran the same main PIC program again with the fixed stepper motor circuit.
Result: The stepper motor turned this time but the solenoid did not activate.
Problem: The stepper didnt turn in the correct direction. The reason for this is likely to be
an algorithm error in the program. The reason why the solenoid did not activate is most
likely because the gate of the MOSFET of the solenoid circuit is not fully opening. A design
change was made to use the Driver Board Version 2.0 to drive the stepper motor and the DC
motor. Another design change was made to implement the TIP142 instead of a MOSFET in
the solenoid circuit.
17. Experiment: Ran a different PIC program with new sensing algorithms with the Driver
Board Version 2.0 and the new solenoid circuit.
Result: The solenoid activated very consistently. The stepper motor did not turn sometimes.
The reason for this can be a bad connection.
Problem: The sensing algorithm is still incorrect.
18. Experiment: Ran the updated PIC program with all of the circuit wires properly soldered.
Result: The stepper motor still didnt turn on some occasions. A reason can be because the
algorithm of the updated PIC program is still incorrect. Another reason might be because
the Driver Board Version 2.0 is broken.
39

19. Experiment: Ran a simple PIC program whose only function was to continuously turn the
stepper with a 3 different Driver Boards.
Result: The stepper motor still refused to turn on some occasions. The stepper motor would
sometimes stop and then move even though the PIC is continuously pulsing signals into the
Driver Board.
Problem: The Driver Board is very unreliable. There are many internal errors in the Driver
Board, which makes it impossible to use for this project. A new stepper motor circuit was
created using TIP.
20. Experiment: Ran the simple stepper PIC program with the new stepper circuit.
Result: The stepper motor moved properly.

After the last experiment, we concluded that all of the circuit components were integrated
with the PIC program. The only problem was that the stepper motor didnt turn properly.
However, this was an algorithm issue with the PIC program. After we did the PIC and Circuits
integration, the structural component of our machine was ready to be integrated with the rest of
the subsystems.
Stage 2. Circuit and Electromechanical Integration
The first thing we did was to run every single actuator to see if they performed
adequately for the machine.
1. Experiment: Tested the DC motor to turn the metal crank that pushes the rocker funnel up
and down.
Result: The metal crank moved as intended.
Problem: The metal crank sometimes got stuck in the middle of the operation. The joint of
the metal crank was filed and lubricated with grease to reduce the friction.
2. Experiment: Tested the metal crank to push the plastic funnel up and down.
Result: The funnel did not move.
Problem: The acrylic plastic funnel is too heavy. A new funnel was made out of cardboard
box. This new funnel was light enough for the metal crank to push it up and down.
3. Experiment: Tested the stepper motor with the bucket to see if the stepper motor has enough
torque to spin it or not.
Result: The stepper motor didnt turn 360 degrees when it was expected to.
Problem: The stepper motor might be slipping. The bucket might be too heavy for the
stepper motor to spin. The bucket was remade out of lighter materials.
4. Experiment: Tested the stepper motor with the new bucket.
40

Result: The stepper motor was still slipping.
Problem: The wooden gear attached to the shaft of the stepper motor was slipping. The
stepper motor itself was not skipping. A new plastic gear was made and properly glued onto
the stepper motor shaft to prevent it from skipping.
5. Experiment: Tested the stepper motor with the new plastic gear.
Result: The stepper motor did not slip.
6. Experiment: Tested if the vials jam at the opening of the funnel.
Result: The vials jammed at the opening of the funnel.
Problem: There is too much friction between the vials. At the opening of the funnel, the
vials cluster because of the friction amongst themselves. To fix this, a plastic strip was
added in the funnel to prevent the vials from clustering.
7. Experiment: Tested if the vials jam at the opening of the funnel with the plastic strip.
Result: The vials still jammed at the opening of the funnel.
Problem: The vials stand up in the funnel and jams. To fix this, another strip of plastic was
inserted to push down the vials from standing.
8. Experiment: Tested if the vials went into the bucket after solenoid pushed it.
Result: The vials went over the bucket.
Problem: The solenoid was too powerful. Sponges were mounted on the opposing wall of
the bucket so that the vials can deflect off the sponge into the bucket.
9. Experiment: Tested if the vials still jammed at the opening of the funnel.
Result: The vials did not jam anymore.
After all of these experiments with the electromechanical parts, our machine was ready
for the overall integration.
Stage 3: Programming, Circuits and Electromechanical Integration
The first thing we did was to organize the circuits and cleaned up the wires. Wires were
elongated and shortened wherever we felt that it was necessary. After cleaning the circuits, the
power supply was mounted onto the platform of the machine. The circuits were not mounted on
the platform. The circuits were stacked up using metal pegs and put in a safe opening.
A hole on one side of the wall was made for the keyboard of the DevBugger and the
LCD. The DevBugger was mounted on the wall using masking tapes.
1. Experiment: A complete trial run 1
Result: The stepper motor didnt turn correctly.
41

Problem: There is an algorithm error in the PIC programming code.
2. Experiment: A complete trial run 2
Result: The stepper motor didnt turn correctly.
Problem: The voltage of the IR receivers change once in a while when the DevBugger
board is turned on.
3. Experiment: A complete trial run 3 with a different DevBugger board
Result: The sensor voltage changed again.
Problem: The DevBugger might be absorbing too much current from the IR receiver,
which changes the voltage of the IR receiver. To fix this, a buffer was placed in front of
the input pin for the A/D converter.
4. Experiment: Testing the voltage after the buffer circuit
Result: The buffer circuit did not do 1-to-1 voltage amplification. The buffer was
removed because it completely changed the voltage readings of the IR receiver.
5. Experiment: A complete trial run 4 with a different DevBugger and a different PIC.
Result: The A/D converter was reading the correct voltage but the stepper motor was not
turning correctly.
Problem: The programming algorithm is incorrect.
6. Experiment: A complete trial run 5 with an updated algorithm
Result: The stepper motor turned properly and the vials were sorted correctly.
Problem: The log on the LCD display displays the incorrect number of total vials.
42

11. Suggestions for Improvement

Suggestions for improvement are mostly related to the construction of the design itself
and its implementation; they do not deal with the actual design chosen. The reason behind this
disparity was that the group did not feel there were any intrinsic issues with the design chosen,
rather just its implementation. The only design changes offered are to change the feeding
mechanism. Since it required thorough testing and calibration, it was felt that the funnel could
have been designed better. This does not necessarily refer to its shape, but rather its finer details;
such as the material it was constructed from, the angles of the triangles etc. All other
improvements correlate with the subsystems presented in Sections 7-9.

Circuits

The circuit subsystem of the machine can be improved in many different ways.

1. Streamlining the organization of the circuit elements on the solder board

Currently, the machine utilizes 4 solder boards. If the circuit elements are organized
appropriately, the entire circuit for the machine can fit on 3 solder boards. This reduces the
amount of space occupied by the circuit as well as the mess caused by it.

2. Cleaning the wiring of the circuits

The current machine has wires stretching everywhere. The wiring can be organized in a
cleaner fashion. By doing this, the debugging on the machine would be made much easier.

3. Using a Single Pull Double Throw relay for the solenoid circuit

The current solenoid circuit uses Double Pull Double Throw relay.
One of the poles of the relay is unused. This DPDT relay can be replaced with a SPDT
relay, which reduces the overall cost of the machine as well the space that the relay occupies
on the solder board.

4. Use a more energy efficient solenoid

The current solenoid dissipates much of its energy in the form of heat. A more energy
efficient solenoid should be used to lower the overall power consumption of the machine.

PIC microcontroller

The PIC microcontroller subsystem of the machine can be improved in the follow ways.

1. Streamlining the programming code

The current programming code has many redundant lines which reduces the overall
efficiency of the program. The redundant codes can be removed to make the code much
more efficient.
43

2. Organization of the programming code

The current code is messy in many areas making the debugging of the code extremely tough.
The code should be cleaned up and more comments should be inserted.

3. Calibrating the delays in the code

The delays in the current code are not calibrated perfectly for maximum sorting speed. The
stepper motor can be made to turn much faster, the solenoid can be made to activate for less
time and the delays between A/D conversions could be decreased significantly. This would
reduce the overall time it takes for the machine to finish sorting the vials.

Electromechanical

The electromechanical subsystem of the machine can be improved in many ways.

1. Using more robust materials

The current machine utilizes poor materials such as cardboard and masking tape. These
materials should be replaced with better ones for more robustness.

2. More precision in the construction of the machine

The current machine was built with very low precision and much instinctive tweaking. The
machine should be built with more precision and accuracy in order to increase feasibility of
mass production.

3. More professional finish to the machine

The current machine does not look like a professional product. In order for it to be placed
on the market, the aesthetic aspect of the machine must be improved.

4. Use a better vial feeding design

The current funnel in the machine that feeds the vials to the sensing station may jam
occasionally at the opening of the funnel. Although this does not happen frequently, a more
reliable vial feeding design should be implemented for a more reliable vial sorting machine.

44

12. Conclusion

This design project addresses the Request for Proposal which specified a vial sorter that
could separate vials according to if they were PET or HDPE and if they are PET, if they are
capped or not. The solution implemented addressed all of the objectives, requirements and
constraints in Section 4. While it did not meet some of them, in regards to durability, it did meet
the other criteria. It also included a number of extra features to enhance the experience of the
user, e.g. a light which prompted the user when the sorting was complete. Furthermore, the
simplicity of the design allowed the group to keep the cost low and also avoid many potential
problems.
The simple design chosen includes a rocking funnel attached to a ramp which allowed
only one vial through at a time with a vertical orientation (lying down and top or bottom through
first). Then the vials would enter the sensing station where they will be sorted through IR
sensors system. Finally they are dispensed by a solenoid-lever mechanism into the appropriate
bin.
In terms of future extensions; the proposed design was made in an open ended manner.
This means that it has the ability to sort through more than three types of vials in the future as
long as the three types are not too similar. This could require a change in programming language,
however, from Assembly to a higher one. In addition, if the design is to accommodate more than
25 vials, then a larger funnel and bins would be required than used. Nevertheless, in any future
applications, the use of better construction material is crucial.


45


13. Accomplished Schedule

The planned schedule is provided below for each of the members with the Gantt Chart
presented in Appendix C. The Circuits and Microcontroller components were initially thought to
have been completed and mostly integrated. Nevertheless, when complete integration with the
mechanical components was done, it became clear that the Circuits needed to be changed. This
change is described in detail in the Circuits Subsystem in Section 7. This meant that integration
did not start until after these changes, and once again when the circuits were changed again (see
Section 7). In the end the integration was only the last three weeks, with extensive testing
coming in the last week before the Public Demonstration. This deviation had more to do with the
lack of good advice to the group than the work ethic of the group themselves, especially the
Circuits component.

PIC Microcontroller Task Management

Week 4: Able to write on LCD screen and read from the keypad
Week 5: Learn to control the Stepper motor, and create delay subroutines
Week 6: Experiment with Analog to Digital Convertor and find out threshold voltages for each
vial. Finish the Main function and Interrupt Service Routine.
Week 7: Fix any problems with programs.
Week 8: Integrate with Circuits.
Week 9: Integrate Microcontroller into the structure.
Week 10: Overall integration of the entire system.
Week 11: Final brush up of the machine.
Week 12: Debug any problems with the machine.
Week 13: Debug any problems with the machine.
Week 14: Public demonstration + start working on the final report.
Week 15: Work on the final report.

Circuits Task management

Week 4: Proposal due on Monday. Start building the prototypes of all of circuits.
Week 5: Finish the prototyping by Wednesday. Start building the final sensor circuit. Finish the
sensor circuits by Sunday.
Week 6: Start building all the motor circuits. Put the sensor circuit on the machine.
Week 7: Finish building all the motor circuits.
Week 8: Integrate all the circuits with the PIC microcontroller.
Week 9: Integrate the motor circuits with the machine.
Week 10: Overall integration of the entire system.
Week 11: Final brush up of the machine.
Week 12: Debug any problems with the machine.
Week 13: Debug any problems with the machine.
Week 14: Public demonstration + start working on the final report.
Week 15: Work on the final report.


46

\
Electromechanical Task Management

Week 4: Construct the Funnel.
Week 5: Construct the Ramp and the Bin.
Week 6: Construct Solenoid-lever mechanism and the rocking pivot
Week 7: Fix any problem with these components
Week 8: Put together the interior components
Week 9: Integrate the motor circuits with the machine
Week 10: Finish integration with the entire system
Week 11: Create the casing for the system
Week 12: Debug any problems with the machine
Week 13: Debug any problems with the machine and encase the system.
Week 14: Public demonstration + start working on the final report.
Week 15: Work on the final report.
47

14. Description of Overall Machine




The machine consists essentially of 3 parts: the vial loading funnel, the sensing station, and the
bin for sorted vials.

Electromechanical





The vial loading funnel is a triangular prism. One side of this prism has an opening; this
side is pinned at the corner. The funnel is made to rotate about this pin by means of a crank
situated roughly mid-length along the ramp. Vertical struts are on either side of the ramp to
provide stability. The crank is driven by a 12V DC Zheng motor. Vials exit the hole in the funnel
into the sensing station.

Figure 30: The entire design of the vial sorter

Figure 32: Motor and the crank

Figure 31: the pin keeping the funnel
connected to the rest of the body

48




The sensing station is lead into by a short V shaped chute. The sensing station is roughly
a rectangular prism with two sides missing. The top and bottom of this prism have 3 infrared
sensors and 3 infrared LEDs respectively (one sensor for middle, and one for each end of the
vial). The side has a hole where a lever powered by a solenoid pokes through, launching the vial
out of the sensing station.





Vials are launched into the vial bin. The bin is a hexagonal prism with three radial
dividers. Each of the three sections contains an insert. The bin is rotated about the center by a
stepper motor. A disk is permanently attached to the stepper motor shaft. The bin can be
connected and disconnected to this disk by Velcro.



Figure 33: LEDs and Sensors

Figure 34: Solenoid mechanism

Figure 35: Bins below the sensing station

Figure 36: Stepper motor which turns the bins

49

Circuits

The machine was controlled by a PIC16 microcontroller.
The DC motor was controlled by a TIP142 NPN Darlington transistor driven by a PIC16
output signal.
The solenoid was controlled by a relay (JQX-115F-05); the relay was driven by an amplified
(by TIP142) PIC16 output signal.
The infrared LEDs were always on. The infrared sensors send input signals to the PIC16.
The stepper motor was controlled by four Darlington transistors, one for each pole of the
stepper motor. These transistors are arrayed in an IC (ULN2001A). They are driven by four
output signals from the PIC16.

Microcontroller

Vials were loaded into the funnel. The PIC16 commenced machine operation when it
received input from the user via a keypad. The PIC16 sent signal to the DC motor and the funnel
was rocked up and down by the crank. Vials exited the funnel into the sensing station. The
PIC16 determined a vial had entered the station according to the values being input by the IR
sensors and turned off the DC motor. By the IR sensor values the PIC16 determined which type
of vial was being sorted. The stepper motor was turned in the appropriate direction so the
trajectory of the vial when launched by the solenoid will place it into the correct bin. The
solenoid was pulsed. The vial was launched into the correct bin. The DC motor was turned on
again and the program loops until another vial was detected. If another vial was not detected in
an allotted amount of time (10 seconds), the PIC16 determined there was no more vials and
ceased machine operation. The PIC16 now displayed operating statistics on an LCD as requested
by the user via a keypad and LCD.












50



15. Standard Operation Procedure

The standard operation of the vial sorter requires the user to do the following:

1. Insert the vials inside the vial sorter from the top (see Figure 30).


2. Enter the vial storage bins into the machine on the front of the machine (see Figure 37).

3. Press START on the keypad on the front of the keypad on the machine.














4. Wait for the machine to complete processing the vials.
5. Chose the log which the user would like to see about the sorted vials (see Figure 38).
Figure 38: Keypad with five different choices

Figure 36: Sorter with top open

Figure 37: Storage bin being inserted.

51


52

16. Appendix A
Entire Code for the Vial Sorter:

processor p=16f877
#include <p16f877.inc>
#include <rtc_macros.inc>

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_OFF & _HS_OSC &
_WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF

;**************************************

#defineRS PORTD,2
#defineE PORTD,3
#defineSM0 PORTB,2
#defineSM1 PORTB,3
#defineSM2 PORTC,7
#defineSM3 PORTC,2
#defineDC PORTC,0
#defineSOL PORTC,1
#defineBGLD PORTC,6


index EQU 0x21
ADDRh EQU 0x22
ADDRl EQU 0x23
index2 EQU 0x24
temp EQU 0x25
count1 EQU 0x26
count2 EQU 0x27
com EQU 0x28
;hr10 EQU 0x29
;hr1 EQU 0x2A
;mn10 EQU 0x2B
;mn1 EQU 0x2C
check EQU 0x2D
cappedvial EQU 0x40
hdpevial EQU 0x41
novial EQU 0x42
uncappedvial EQU 0x43

timer EQU 0x2E
timersec EQU 0x2F
timersec10 EQU 0x2C
timermin EQU 0x2B

w_temp EQU 0x29
53

status_temp EQU 0x2A

VIALCOUNT EQU 0x70
VIALCOUNT2 EQU 0x71
HDPE EQU 0x72
HDPE2 EQU 0x73
CPET EQU 0x74
CPET2 EQU 0x79
UPET EQU 0x7A
UPET2 EQU 0x7B
ADCONV0 EQU 0x7C
CURVIAL EQU 0x7D
PERVIAL EQU 0x7E
ADDR EQU 0x7F

num EQU 0x75
dig10 EQU 0x77
dig1 EQU 0x78

cblock 0x30
d1
d2
d3
d4
d5
endc

;**************************************
ORG 0x0000
goto main

ORG 0x004 ;INT SERVICE ROUTINE for timer
movwf w_temp
movf STATUS,w
movwf status_temp
call INTroutine
movf status_temp,w
movwf STATUS
swapf w_temp,f
swapf w_temp,w
retfie

ORG 0x010
MSGdone
dt "DONE!",0
MSGprog
dt "PROCESSING...",0
54

MSG0
dt "PUSH START ",0
MSG1
dt "TOTAL VIALS:",0
MSG2
dt "uncappedPETS:",0
MSG3
dt "cappedPETS:",0
MSG4
dt "HDPE:",0
MSGnovial
dt "No Vials.",0
MSGtime
dt "TIME: ",0

main
bsf STATUS, RP0
bcf STATUS, RP1 ;bank1
call i2c_common_setup
movlw B'11110010'
movwf TRISB ;keypad initialization, 7-4 for
keyvalue, 1 for signal, 2-3 for Stepper Motor
movlw B'00011000'
movwf TRISC ;all outputs; sensors, leds, dc
and solenoid
clrf TRISD ;lcd initialization
clrf ADCON1
bcf STATUS, RP0 ;bank0
clrf PORTC
bcf SM1
bsf SM0
movlw D'1'
movwf ADDR
bcf STATUS,RP0
movlw B'11100000'
movwf cappedvial
movlw B'00000000'
movwf novial
movlw B'01010000'
movwf hdpevial
movlw B'10000000'
movwf uncappedvial
call lcdsetup
clrf check
START
bcf STATUS,RP0
clrf timersec
55

clrf timersec10
clrf timermin
clrf T1CON ; Stop Timer1, Internal Clock
Source,
; T1 oscillator disabled,
prescaler = 1:1
clrf TMR1H ; Clear Timer1 High byte register
clrf TMR1L ; Clear Timer1 Low byte register
clrf INTCON ; Disable interrupts
bsf INTCON, GIE
bsf INTCON, PEIE
bsf STATUS,RP0
bsf PIE1, TMR1IE
bcf STATUS, RP0 ; Bank0
clrf PIR1 ; Clear peripheral interrupts Flags
movlw 0x30 ; Internal Clock source with 1:8 prescaler
movwf T1CON ; Timer1 is stopped and T1 osc is
disabled
bsf T1CON, TMR1ON ; Timer1 starts to increment


movlw B'00000001'
movwf count1 ;counter for processing and done msg (not
needed in real code)
call display0

poll ;poll for START push

call delay
btfsc PORTB,1
call getkeypad ;initiall polling
goto poll


;*********************************************
;get 4-bit number from keypad, this only accepts D as input
;*********************************************
getkeypad
btfss PORTB,7
return
btfss PORTB,6
return
btfss PORTB,5
return
btfss PORTB,4
return
decfsz count1,f
56


INITRUN
movlw D'1'
movwf PERVIAL
clrf VIALCOUNT
clrf HDPE
clrf CPET
clrf UPET
call displayprog

PROCESS
movlw 0xC8
movwf d2
movlw 0x0D
movwf d3
movlw 0x02
movwf d4
DCLOOP
bsf DC ;turn on the DC motor
movlw B'10000001' ;check the bottom sensor in the sensing station
call ADCONVERT
subwf novial,W ;subtract from 0x00 the digital number from the bottom
sensor
btfss STATUS,C ;check if the subtraction returned a zero or negative
number, 0 means negative, 1 means zero.
goto CHECK2 ;program enters CHECK2 if subtraction returned 0
decfsz d2, f ; d2 and d3 decremented as part of 10s timer after which
the program shuts down sorting
goto $+2
decfsz d3, f
goto $+2
goto OneSecondCheck ;if nothing detected after d2 and d3 have reached zero,
meaning a second has passed,
;secondary
;check done to make sure no vial has already
settled in
goto DCLOOP ;if no vial detected, progam returns to the top of the code,
DCLOOP
call ESCAPE ;after 10s, the program shuts down sorting and
assumes all vials are processed.

;**************************************************************************
;OneSecondCheck is instigated after the DCLOOP has looped for a second, this checks the
rightmost sensor to see if
;the threading of an uncapped PET vial is there (which is the lowest value possible from the top
of any vial).
;**************************************************************************
57

OneSecondCheck
movlw B'10010001' ;checks the top sensor in the station
call ADCONVERT
subwf uncappedvial,W ;subtracts value against lowest value on the top of a vial;
;threading of a PET vial (labelled here as
uncappedvial)
btfss STATUS,C ; 1 returned if no vial there, 0 if a vial is detected
goto VIALCOUNTER ;program enters differentiation if 0 received line above
decfsz d4,f ;if 1 returned then program decrements another
counter (d4)
goto DCLOOP ; if counter>0 (d4), program returns to top of code,
DCLOOP
call ESCAPE ;if counter=0 (d4), program shuts down sorting,
assumes all vials are processed.
;**************************************************************************
;CHECK2 is instigated after DCLOOP detects a vial, this check validates if in fact a vial has
arrived
;**************************************************************************
CHECK2
movf ADCONV0,W ;ADCONV0 contains saved value of last run of the A/D
conversion, it is inputted into W
subwf uncappedvial,W ;subtracts value against lowest value on the top of a vial;
threading of a PET vial
;(labelled here as uncappedvial)
btfss STATUS,C ;1 returned if no vial there, 0 if top of vial there
goto VIALCOUNTER;enters VIALCOUNTER if 0 detected in last line
movlw B'10010001' ;checks the top sensor in the station
call ADCONVERT
subwf uncappedvial,W ;subtracts value against lowest value on the top of a vial;
threading of a PET vial
;(labelled here as uncappedvial)
btfsc STATUS,C ;1 returned if no vial there, 0 if top of vial there
goto DCLOOP ;enters VIALCOUNTER if 1 detected in last line

VIALCOUNTER
bcf DC
incf VIALCOUNT,f
movf VIALCOUNT,W
call STORE
movwf VIALCOUNT

ADCONVERTER
call longerdelay
movlw B'10001001' ;check an1, middle sensor
call ADCONVERT
subwf hdpevial,W
btfss STATUS,C
58

goto STOREHDPE
;*********************************************
;PETCHECK-if it is capped or uncapped
;*********************************************
PETCHK
movlw B'10000001' ;check an2, botton sensor
call ADCONVERT
subwf cappedvial,W
btfss STATUS,C
goto STORECPET

PETCHK2
movlw B'10010001' ;check an1, top sensor
call ADCONVERT
subwf cappedvial,W
btfss STATUS,C
goto STORECPET

;**********************************************
STOREUPET
incf UPET,f
movf UPET,W
call STORE
movwf UPET
movlw D'1'
movwf CURVIAL
goto TURNCHK0
STORECPET
incf CPET,f
movf CPET,W
call STORE
movwf CPET
movlw D'2'
goto TURNCHK0
STOREHDPE
incf HDPE,f
movf HDPE,W
call STORE
movwf HDPE
movlw D'4'
goto TURNCHK0
;*********************************************
TURNCHK0
btfsc PERVIAL,0
goto TURN0 ;previous vial was upet: PERVIAL=0x01
btfsc PERVIAL,1
goto TURN1 ;previous vial was cpet: PERVIAL=0x02
59

goto TURN2 ;previous vial was hdpe: PERVIAL=0x04
;*********************************************
TURN0
btfsc CURVIAL,0
call OUT ;both curvial and pervial same, so only eject
btfsc CURVIAL,1
call ONETURN ;curvial=cpet, pervial=upet, turn 120 degrees left
then eject
call REVTURN ;curvial=hdpe, pervial=upet, turn 120 degrees right
then eject
;*********************************************
TURN1
btfsc CURVIAL,0
call REVTURN ;curvial=upet, pervial=ucpet, turn 120 degrees right
then eject
btfsc CURVIAL,1
call OUT ;curvial=pervial=cpet, eject only
call ONETURN ;curvial=hdpe, pervial=cpet, turn 120 degrees left
then eject
;*********************************************
TURN2
btfsc CURVIAL,0
call ONETURN ;curvial=hdpe, pervial=upet, turn 120 degrees left
then eject
btfsc CURVIAL,1
call REVTURN ;;curvial=hdpe, pervial=cpet, turn 120 degrees right
then eject
call OUT ;curvial=pervial=hdpe, eject only
;*********************************************
ONETURN
bcf SM0
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM3
call longdelay
bcf SM3
call longdelay
bsf SM0
call longdelay
bcf SM0
60

call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM3
call longdelay
bcf SM3
call longdelay
bsf SM0
call longdelay
bcf SM0
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM3
call longdelay
bcf SM3
call longdelay
bsf SM0
call longdelay
bcf SM0
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM3
call longdelay
return

REVTURN2
bcf SM0
61

call longdelay
bsf SM3
call longdelay
call REVTURN
return

ONETURN2
call ONETURN
bcf SM3
call longdelay
bsf SM0
call longdelay
return

;*********************************************
REVTURN
bcf SM3
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM0
call longdelay
bcf SM0
call longdelay
bsf SM3
call longdelay
bcf SM3
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM0
call longdelay
bcf SM0
call longdelay
bsf SM3
62

call longdelay
bcf SM3
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM0
call longdelay
bcf SM0
call longdelay
bsf SM3
call longdelay
bcf SM3
call longdelay
bsf SM2
call longdelay
bcf SM2
call longdelay
bsf SM1
call longdelay
bcf SM1
call longdelay
bsf SM0
call longdelay
return
;*********************************************
OUT
call longdelay
bsf SOL
call longerdelay
bcf SOL
call longdelay
movf CURVIAL, W
movwf PERVIAL
return
;*********************************************
ESCAPE
bcf DC
call displaydone
bsf BGLD
call longerdelay
bcf BGLD
63

call longerdelay
bsf BGLD
call longerdelay
bcf BGLD
call CHNGS

call displaytime
call longerdelay
call longerdelay
poll0 ;polls for user to chose what they
want displayed
call delay
btfsc PORTB,1
goto info
goto poll0
info1
call EXIT
btfsc PORTB,4
call EEPROMDISP
poll1 ;polls for user to chose what they
want displayed
call delay
btfsc PORTB,1
goto info1
goto poll1
info
btfsc PORTB,7
call PET ;displays which PET it is
btfsc PORTB,6
call display4 ;display HDPE
btfss PORTB, 4
call display1 ;displays TOTAL VIALS
goto poll0
;*********************************************
NOVIAL
call displaynovial
call longerdelay
call longerdelay
call longerdelay
goto START
;**********************************************
EEPROMDISP
btfsc PORTB,6
goto NEXTDISP
PREVDISP
movlw B'11101111'
; andwf ADDR
64

call READ
movf W,VIALCOUNT2
incf ADDR
call READ
movf W,VIALCOUNT
incf ADDR
call READ
movf W,HDPE2
incf ADDR
call READ
movf W,HDPE
incf ADDR
call READ
movf W,CPET2
incf ADDR
call READ
movf W,CPET
incf ADDR
call READ
movf W,UPET2
incf ADDR
call READ
movf W,UPET
incf ADDR
return
NEXTDISP
incf ADDR
call READ
movf W,VIALCOUNT2
incf ADDR
call READ
movf W,VIALCOUNT
incf ADDR
call READ
movf W,HDPE2
incf ADDR
call READ
movf W,HDPE
incf ADDR
call READ
movf W,CPET2
incf ADDR
call READ
movf W,CPET
incf ADDR
call READ
movf W,UPET2
65

incf ADDR
call READ
movf W,UPET
incf ADDR
return
;*******************************************
READ
bsf STATUS,RP1
bcf STATUS,RP0
movf ADDR,W
movwf EEADR
bsf STATUS, RP0
bcf EECON1, EEPGD
bsf EECON1, RD
bcf STATUS, RP0
movf EEDATA, W
return
;***********************************************
STORE
btfss W,3
return
btfss W,1
return
movlw B'11110000'
swapf W,f
addlw 0x01
swapf W,f
return
;*********************************************
CHNGS
swapf VIALCOUNT,w ; W = LLLL HHHH
andlw 0x0f ; Mask upper four bits 0000 HHHH
addlw 0x30 ; convert to ASCII
movwf VIALCOUNT2 ;saves into 10ths digit
movf VIALCOUNT,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf VIALCOUNT ; saves into 1s digit

swapf HDPE,w ; W = LLLL HHHH
andlw 0x0f ; Mask upper four bits 0000 HHHH
addlw 0x30 ; convert to ASCII
movwf HDPE2 ;saves into 10ths digit
movf HDPE,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf HDPE ; saves into 1s digit
66


swapf CPET,w ; W = LLLL HHHH
andlw 0x0f ; Mask upper four bits 0000 HHHH
addlw 0x30 ; convert to ASCII
movwf CPET2 ;saves into 10ths digit
movf CPET,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf CPET ; saves into 1s digit

swapf UPET,w ; W = LLLL HHHH
andlw 0x0f ; Mask upper four bits 0000 HHHH
addlw 0x30 ; convert to ASCII
movwf UPET2 ;saves into 10ths digit
movf UPET,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf UPET ; saves into 1s digit

swapf timersec,w ; W = LLLL HHHH
andlw 0x0f ; Mask upper four bits 0000 HHHH
addlw 0x30 ; convert to ASCII
movwf timersec10 ;saves into 10ths digit
movf timersec,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf timersec ; saves into 1s digit

movf timermin,w
andlw 0x0f ; w = 0000 LLLL
addlw 0x30 ; convert to ASCII
movwf timermin ; saves into 1s digit
return
;*********************************************
EEPROMSTORE
bsf STATUS,RP0
bsf STATUS,RP1 ;bank3\
btfsc EECON1,WR ;wait for write to finish
goto $-1
bcf STATUS,RP0 ;bank2
movf ADDR,w
movwf EEADR ;0x20 in eeprom written in
bcf STATUS, RP1 ;bank0
movf temp,w ;ADCONV0 inputted
bsf STATUS, RP1 ;bank2
movwf EEDATA ;insert data
bcf INTCON, GIE
67

bsf STATUS,RP0
bcf EECON1,EEPGD
bsf EECON1,WREN
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
bcf EECON1,WREN
return
;Checks between uncapped and capped PETS
;*********************************************
PET
btfsc PORTB,6
call display2 ;
call display3
return
;*********************************************
;restarts machine to beginnig, only accepts D (which is start/reset key), goes to start
;*********************************************
EXIT
btfss PORTB,7
return
btfss PORTB,6
return
btfss PORTB,5
return
btfss PORTB,4
return
call longdelay
goto START
;*********************************************
;DISPLAY MSGS, ALL DISPLAYS IN AFTER THIS
;*********************************************
display0
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSG0
movwf ADDRh
movlw LOW MSG0
movwf ADDRl
movlw D'11' ;length of bits in msg
movwf index
call write_LCD
rtc_read 0x02
68

movf dig10,w
call WR_DATA
movf dig1,W
call WR_DATA
movlw ":"
call WR_DATA
rtc_read 0x01
movf dig10,w
call WR_DATA
movf dig1,W
call WR_DATA
return
;*********************************************
displaynovial
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSGnovial
movwf ADDRh
movlw LOW MSGnovial
movwf ADDRl
movlw D'9' ;length of bits in msg
movwf index
call write_LCD
return
;*********************************************
displayprog
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSGprog
movwf ADDRh
movlw LOW MSGprog
movwf ADDRl
movlw D'13' ;length of bits in msg
movwf index
call write_LCD

return
;*********************************************
displaydone
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
69

movlw HIGH MSGdone
movwf ADDRh
movlw LOW MSGdone
movwf ADDRl
movlw D'5' ;length of bits in msg
movwf index
call write_LCD
return
;*********************************************
display1
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSG1
movwf ADDRh
movlw LOW MSG1
movwf ADDRl
movlw D'12' ;ength of bits in msg
movwf index
call write_LCD
movf VIALCOUNT2,w
call WR_DATA
movf VIALCOUNT, w
call WR_DATA
goto poll0
;*********************************************
display2
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSG2
movwf ADDRh
movlw LOW MSG2
movwf ADDRl
movlw D'13' ;length of bits in msg
movwf index
call write_LCD
movf UPET2,w
call WR_DATA
movf UPET, w
call WR_DATA
goto poll0
;*********************************************
display3
call delay
70

movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSG3
movwf ADDRh
movlw LOW MSG3
movwf ADDRl
movlw D'11' ;length of bits in msg
movwf index
call write_LCD
movf CPET2,w
call WR_DATA
movf CPET, w
call WR_DATA
goto poll0
;*********************************************
display4
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSG4
movwf ADDRh
movlw LOW MSG4
movwf ADDRl
movlw D'05' ;length of bits in msg
movwf index
call write_LCD
movf HDPE2,w
call WR_DATA
movf HDPE, w
call WR_DATA
goto poll0
;*********************************************
displaytime
call delay
movlw B'00000001' ;clear ram
call WR_INS
call delay
movlw HIGH MSGtime
movwf ADDRh
movlw LOW MSGtime
movwf ADDRl
movlw D'05' ;length of bits in msg
movwf index
call write_LCD
movf timermin,w
71

call WR_DATA
movlw B'00111010'
call WR_DATA
movf timersec10, w
call WR_DATA
movf timersec, w
call WR_DATA
return
;********************************************
;displays characters one by one onto LCD screen
;********************************************
write_LCD
movlw 0
movwf index2
writeagain
movf index2,w
call get_element
call WR_DATA
incf index2
call delay
decfsz index
goto writeagain
return
;*********************************************
;inserts ADDRess of table into pcounter, steps through it after calling it multiple times
;*********************************************
get_element
movwf temp
movf ADDRh,w
movwf PCLATH
movf temp,w
addwf ADDRl,w
btfsc STATUS,C
incf PCLATH
movwf PCL
return
;******************************************
;Write command to LCD
;*******************************************
WR_INS
bcf RS
movwf com
andlw 0xF0
movwf PORTD
bsf E
call delay
bcf E
72

call delay
swapf com,w
andlw 0xF0
movwf PORTD
bsf E
call delay
bcf E
call delay
return
;*********************************************
;Write data to LCD
;*********************************************
WR_DATA
bsf RS
movwf temp
movf temp,w
andlw 0xF0
addlw 4
movwf PORTD
bsf E
call delay
bcf E
swapf temp,w
andlw 0xF0
addlw 4
movwf PORTD
bsf E
call delay
bcf E
return
;*********************************************
lcdsetup
call delay
call delay

movlw B'00110011'
call WR_INS
movlw B'00110010'
call WR_INS
movlw B'00101000'
call WR_INS
movlw B'00001100'
call WR_INS
movlw B'00000110'
call WR_INS
movlw B'00000001'
call WR_INS
73


call delay
call delay

return
;*********************************************
;Delay routine 10cycles
;*********************************************
delay
movlw 2
movwf count1
del1
clrf count2
del2
decfsz count2
goto del2
decfsz count1
goto del1
return
;*********************************************
;delays for 0.5 seconds-ish 2552 cycles
;*********************************************
longdelay
movlw 0x50
movwf d1
delay0
call delay
decfsz d1,f
goto delay0
return
;********************************************
DCdelay
movlw 0xA0
movwf d1
delay01
call delay
decfsz d1,f
goto delay01
return
;*******************************
;delays for 2 seconds-ish 15(2552)=38280 cycles
;*********************************************
longerdelay
movlw 0x0F
movwf d2
delay1
call longdelay
74

decfsz d2
goto delay1
return
;*******************************
ADCONVERT
bcf INTCON,GIE
call AD_CONV
movwf ADCONV0
bsf INTCON,GIE
return
;*******************************
AD_CONV
movwf ADCON0
call TIM20
bsf ADCON0, GO
WAIT
btfsc ADCON0,GO
goto WAIT
movf ADRESH,W
return
;*******************************
TIM20
movlw 084H
movwf temp

TIMLP
decfsz temp,f
goto TIMLP
nop
return
;**********************************
INTroutine
bcf STATUS,RP0
bcf STATUS,RP1
bcf PIR1, TMR1IF
incf timer,f
btfss timer,1
return
btfss timer,0
return
clrf timer
incf timersec,f
movf timersec,w
call STORE
movwf timersec
btfss timersec,6
return
75

btfss timersec,5
return
clrf timersec
incf timermin
return

END

76

Appendix B
Circuit Figures
Sensors (Figure 13)























Figure 13a)
Figure 13b)
77


Comparator

Figure 2





DC motor

















Figure 14
Figure 15a)
Figure 15b)
78

Solenoid circuit



Figure 4b)

















Figure 16a)
Figure 16b)
79

Indication light









Stepper Circuit




Figure 17
Figure 18a)
80


Figure 18b)
81

Appendix C
Gantt Chart:






























82


































83

Appendix D
Data Sheets

Protection Diode 1N4001


84







85

IR Photodiode, LTR-516AD







86










87










88









89

DPDT 8A Relay



90



91

STP16NF06 Mosfet Power Transistor




92

High Power IR LED


93


TIP142 NPN Darlington Transistor



94

References

[1]Emami, Reza. "Request for Proposal #3: The Vial Sorter Machine." AER201 Engineering
Design (2010). Print.
[2] "Robotic Tube & Vial Handling System." BioMicrolab. Web.
<http://www.labhoo.com/brochures/B9541_XL100_InfoSheet_Aug08.pdf>.
[3] "Automated closed test tube sorter from Warsash Scientific." Ferret. Warsash Scientific.
Web. <http://www.ferret.com.au/c/Warsash-Scientific/Automated-closed-test-tube-
sorter-from-Warsash-Scientific-n777474>.
[4] "Highspeed Closed Tube Sorter." MUT Group. Web. <http://www.mut-
group.com/fileadmin/Downloads/Lab_automation/m-u-t_HCTS2000-MK3-web.pdf>.
[5] Emami, Reza. AER201 Enginnering Design. Toronto: Univerity of Toronto, 2010. Print.

You might also like