Final Design Report 2017.04.18

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

UNIVERSITY OF VICTORIA

Faculty of Engineering

MECH485
Mechatronics

Final Design Report

David Hamdi V00208144


Kieran Armstrong V00780649

April 18, 2017


Table of Contents

List of Figures ..................................................................................................................... ii


List of Tables ...................................................................................................................... ii
1. Introduction ................................................................................................................. 1
1.1 Project Description ............................................................................................... 1
1.2 Project Objectives ................................................................................................ 1
1.3 Timeline ............................................................................................................... 2
2. Firmware ..................................................................................................................... 2
2.1 Delay Timer.......................................................................................................... 2
2.2 Stepper Motor ....................................................................................................... 3
2.3 DC Motor ............................................................................................................. 4
2.4 Optical Reflective Sensor Interrupt ...................................................................... 4
2.5 Ferromagnetic Sensor ........................................................................................... 6
2.6 Exit Sensor ........................................................................................................... 6
3. Circuit Diagrams ......................................................................................................... 6
4. System Implementation .............................................................................................. 6
4.1 Hardware Setup .................................................................................................... 6
4.1.1 Data Direction Registers ............................................................................... 7
4.1.2 PWM for DC Motor Control......................................................................... 7
4.1.3 ADC Initialization ......................................................................................... 8
4.1.4 Stepper Motor Setup ..................................................................................... 8
4.1.5 Linked List .................................................................................................... 9
4.1.6 Sensor Calibration and Part Bounds ............................................................. 9
4.2 Sorting (Decision Matrix) .................................................................................. 10
4.3 System Pause ...................................................................................................... 11
5. System Performance Specifications .......................................................................... 14
6. Testing and Calibration Procedure............................................................................ 14
7. Limitations and System Tradeoffs ............................................................................ 15
7.1 Stepper Motor Tray Weight ............................................................................... 15
7.2 Belt Speed and ADC .......................................................................................... 15
8. Novel System Additions ........................................................................................... 15
8.1 Timer Interrupt Driven Stepper Motor ............................................................... 16
8.2 Stepper Progressive Adjustment ........................................................................ 17

i|Page
9. Experience and Recommendations ........................................................................... 18
10. References .............................................................................................................. 19
Appendix A – List of Global Variables ......................................................................... i
Appendix B – System Level Diagram ........................................................................... i
Appendix C – Circuit Diagrams .................................................................................... i

List of Figures
Figure 1: Transportation Mechanism .................................................................................. 1
Figure 2: Gantt Chart .......................................................................................................... 2
Figure 3: Forward and Backward Step Functions............................................................... 4
Figure 4: Optical Reflective Control Flow ......................................................................... 5
Figure 5: ADC Interrupt Algorithm .................................................................................... 5
Figure 6: Part Classification................................................................................................ 6
Figure 7: Exit Sensor Interrupt ........................................................................................... 6
Figure 8: Setup Hardware Function .................................................................................... 7
Figure 9: PWM Setup Function .......................................................................................... 8
Figure 10: ADC Setup Function External Interrupts .......................................................... 8
Figure 11: Home Stepper Motor Function .......................................................................... 9
Figure 12: Linked List Data Structure ................................................................................ 9
Figure 13: Part Classification Algorithm .......................................................................... 10
Figure 14: Example From the DecisionMatrix() Function ............................................... 11
Figure 15: Pause Button Display While Loop .................................................................. 12
Figure 16: First if Statement in the Pause Button ISR ...................................................... 13
Figure 17: Second if Statement in the Pause Button ISR ................................................. 13
Figure 18: Calibration Spreadsheet Example ................................................................... 15
Figure 19. Angular Acceleration, Speed, and Position [1] ............................................... 16
Figure 20. Speed Profile vs. Stepper Motor Pulses/Speed................................................ 16
Figure 21. State Machine for Timer Interrupt ................................................................... 17

List of Tables
Table 1: Two-phase Full Step Commands .......................................................................... 3
Table 2: Data Direction Register Initialization ................................................................... 7
Table 3. Scaling of Standard SI Values ............................................................................ 17
Table 4: Progressive Stepper Adjustment ......................................................................... 18
Table 5: List of Global Variables......................................................................................... i

ii | P a g e
1. Introduction

1.1 Project Description


The control of mechanical systems is continuing to grow which means the proper
integration of electrical, software, and mechanical principles is becoming more and more
important. To gain experience with industry level implementation the use of an 8-bit
Atmel AT90USB1289 microcontroller was used to implement a sorting machine.

The sorting machine inspects 4 different materials and places them into their
characteristic container. The parts are inspected with an array of sensors which are
positioned on a conveyer belt driven by a DC motor. Once a part is identified a stepper
motor turns a container to the respective position to catch and sort the part. The system is
shown below in Figure 1.

Figure 1: Transportation Mechanism

To classify each piece, the inspection system uses three optical beam sensors, one
inductive sensor, one reflective sensor, and a ferromagnetic sensor. The three optical
beam sensors are used to notify of a parts location which triggers a specific sorting event.
The inductive sensor can be used to differentiate a part between metal or plastic, the
reflective sensors reads an analog value which can be converted to a digital value to
classify all part materials (black, white, steel, or aluminum).

1.2 Project Objectives


The primary objective of this project was to learn how to program a microcontroller that
is based off embedded C architecture. The task presented was to sort a total of 48 parts
which consisted of 12 white, black, steel, and aluminum into their corresponding
containers.

1|Page
Based on past group performances from sessions of this course the project team felt that
based on previous experience and existing course load the following objectives could be
achieved:

1. Zero Sorting Errors: We are aiming to complete the sorting task with no errors.
As a group, we are aiming for a quick sorting time however accuracy is of high
importance.
2. Sub 40 second sorting time: We were aiming to complete the sorting task in
under 40 seconds as a top score was potentially unattainable with our course load
and timeline. However, we are still going to strive for the fastest time that we can
attain.

1.3 Timeline
Creating a project timeline with a Gantt chart is essential to the completion of any
project. The Gantt chart below in Figure 2 was used to keep the team on task and meet
the final system implementation in preparation for a demonstration on April 10, 2017.

Figure 2: Gantt Chart

2. Firmware

2.1 Delay Timer


A delay timer is essential to implement a robust system. The microcontroller runs at a
default frequency of 1 MHz which is at a much higher processing speed than can be
physically attained by the sorting mechanism. Therefore, to slow down the computing
speed of the microcontroller millisecond delays were used to allow sequential flow
through the algorithm.

2|Page
Atmel provides a delay timer within their standard library that implements a software
counter. However, in the final implementation of this system a 16-bit hardware timer was
implemented as it is more accurate and easily configured to fit specific needs.

2.2 Stepper Motor


A unipolar stepper motor manufactured by Soyo was used to drive the position of the
sorting container. The stepper operates at 6V at 0.8A and each step is equivalent to 1.8
degrees. The hybrid stepper motor was run in its two-phase full stepping configuration to
deliver its top amount of torque.

To advance the stepper motors rotational position the 4 coils are pulsed individually one
at a time over and over. It is imperative that the stepper motor receive the correct pulses
to each coil to avoid double-stepping or miss-stepping. The stepper motor drive is
displayed below in Figure 3.

Table 1: Two-phase Full Step Commands

Step Coil Pulse Value


1 0x1B
2 0x1D
3 0x2D
4 0x2B

To ensure that no steps would be missed a variable was incremented for the number of
steps desired and the last step is always recorded as a global variable. The drive function
is show below in Figure 3.

3|Page
Figure 3: Forward and Backward Step Functions

The StepForward() and StepBackward() algorithms follow these steps:

1. Grab the vale from the global variable “lastStep” and increment or decrement it
by 1.
2. Check if the incremented/decremented step is 4. If it is, set counter variable to 0.
3. Send the respective Two-phase full step command from PORTA to the stepper
motor coils.
4. Assign the “lastStep” to the current step.

It should be noted that StepForward() and StepBackward() are only used to send a pulse
to the stepper coil and keep track of which step the motor is on. The command for the
position, speed, acceleration, and deceleration are controlled by SpeedControlMove()
with a timer interrupt.

2.3 DC Motor
To drive the parts through the sensors for classification to the sorting containers a DC
motor was used. The motor consisted of a rotor and a fixed magnetic field generated by
permanent magnets. To control the angular velocity of the motor PWM was
implemented. With a duty cycle of 50%, a top frequency of 0xFF and a bottom of 0x00,
8-bit speed adjustment was possible. Frequencies within these two bounds were explored
to get the fastest belt speed possible for the system without compromising sensor function
or the proper placement of parts.

2.4 Optical Reflective Sensor Interrupt


The optical reflective sensor is triggered when a part passes through the optical beam
sensor. When a part passes through the sensor the microcontroller detects the signal on a
rising edge, which is caught by external interrupt 1 of the microcontroller. When this

4|Page
event fires it sets a 16-bit integer high to the ADC_result variable and starts an ADC
conversion as shown below in Figure 4.

Figure 4: Optical Reflective Control Flow

Starting the ADC fires a designated interrupt within the microcontroller where the ADC
value can be obtained for part classification. Steel, aluminum, black, and white all return
different values therefore, to differentiate the parts, the ADC interrupt is fired until the
minimum value is identified.

Figure 5: ADC Interrupt Algorithm

In Figure 5 above, a high 16-bit global variable ADC_result is compared to the ADC
registers 10-bit value to find the minimum value. If ADC_result is greater than the value
within the register ADC_result is set to the ADC value. This process continues until the
minimum ADC value is found. It should also be noted that a new conversion is started if
the part triggers the optical beam sensor.

Once the lowest value of the ADC is obtained from the algorithm in Figure 5, it is then
assigned a “classificationValue” and added as a node to the list. The implementation is
shown below in Figure 6.

5|Page
Figure 6: Part Classification

2.5 Ferromagnetic Sensor


The Ferromagnetic sensor is used specifically for system startup. To let the system, know
the step of the stepper motor that corresponds to the black, white, steel, and aluminum
containers a home position needs to be set.

The home position is set by rotating the stepper motor until a rising edge is caught and
the current position of the stepper motor is saved globally.

2.6 Exit Sensor


The exit sensor is a falling edge optical beam sensor that is matched with external
interrupt 0. This interrupt was used as it is the highest priority of the 8 external interrupts
that exist on the microcontroller. This interrupt stops the conveyer belt and executes the
stepper motor movement. The event flow is shown below in Figure 7.

Figure 7: Exit Sensor Interrupt

3. Circuit Diagrams
The circuit diagrams for the entire final design can be seen in Appendix C. The diagrams
were created in AUTODESK Eagle Version 8.0 and were regularly referenced to ensure
proper integration of components.

4. System Implementation
This section outlines the algorithms used in this project to meet the project specifications.
A full system implementation can be found in Appendix B.

4.1 Hardware Setup


The hardware setup function is shown below in Figure 8.

6|Page
Figure 8: Setup Hardware Function

4.1.1 Data Direction Registers


The data direction registers (DDRn) need to be initialized for the microcontroller to know
whether they should receive or send signals to peripherals. Table 2 below shows which
ports are used as inputs or outputs.

Table 2: Data Direction Register Initialization

PORT Description of Use Input/Output DDRn Assignment


A Stepper Motor Control Output DDRA = 0xff
B DC Motor Control Both DDRB = 0xff
C LED Indicator Bank Output DDRC = 0xff
D External Interrupts and Sensors Both DDRD = 0xf0
E Other External Interrupts Input DDRE = 0x00
ADC Read-in Input DDRF = 0x00

4.1.2 PWM for DC Motor Control


Fast PWM and clear timer on compare match mode are used to initialize timer0. The
compare match output value is set along with the clock pre-scaler on the 8-bit timer. By
varying the top value of the output compare register 0A (OCR0A) the frequency of the
PWM can be updated which in turn changes the speed of the conveyer belt. For the final
design the top value was set to 85, which resulted in a frequency of 727 Hz. The PWM
setup implementation is shown below in Figure X.

7|Page
Figure 9: PWM Setup Function

4.1.3 ADC Initialization


To initialize the ADC feature within the microcontroller it needs to first be enabled along
with its system interrupt. For ADC to return the most accurate reading it requires a input
clock frequency between 50kHz and 200 kHz to get maximum resolution. Setting the
input clock frequency close to 200kHz will allow faster sampling but may decrease
accuracy. Therefor a pre-scaler of 16 which results in a input clock frequency of 62.5kHz
with 10-bit resolution for this system. If only 8-bit resolution is required the default input
clock frequency is fine. The ADC setup function is shown below in Figure 10: ADC
Setup Function.

Figure 10: ADC Setup Function External Interrupts

4.1.4 Stepper Motor Setup


The stepper motor needs to be properly oriented at the beginning of sorting and then
home position needs to be recorded. In order to achieve this, the stepper motor is pulsed
at a constant frequency with timer1. The output compare register of the timer was set to a
top value of 175 which resulted in a 44Hz coil pulse frequency. As soon as timer3 is
turned on PORTE pin 0 is polled until the ferromagnetic sensor is tripped and the
“stepperPos” is then set.

During the time that the ferromagnetic sensor input signal is being polled a global
variable is set to 1 to tell timer3’s interrupt to remain in setup mode. This condition calls
stepper forward and pulses the motor to turn clockwise. The implementation is show
below in Figure 11.

8|Page
Figure 11: Home Stepper Motor Function

4.1.5 Linked List


The linked list used to store the part information; needed to be initialized for values
within the nodes as well as the pointers at the beginning and end of the list. Each node of
the list has a newLinkPart and rtnLinkPart which are initialized to NULL. When a node is
dequeued from the list it is removed from the tail and when a node is added to the list it is
added at the head. The dynamic data structure is illustrated below in Figure 12.

Figure 12: Linked List Data Structure

4.1.6 Sensor Calibration and Part Bounds


The optical reflective sensor and part bounds are defined within the exit sensor interrupt
to assign a classification value to it. It should be noted that the bounds of the parts do not
have specific ranges. Instead they expand the entire range of top and bottom values. A
detailed explanation of the sensor calibration is included in Section 6.

9|Page
4.2 Sorting (Decision Matrix)
The chief objective of this project was to sort ingots composed of 4 materials into their
respective categories. To achieve this goal the ingots had to be classified based on the
sensor readings. A simple block of “if” statements classified the pieces based on the
readings of the reflective sensor.

Figure 13: Part Classification Algorithm

The “classificationValue” seen above was a temporary variable used to transfer the piece
to the RelectiveValue variable stored in the linked list element.

Once a piece reached the exit sensor a decision needed to be made about the direction and
duration of movement implemented with the stepper motor. The first step was to dequeue
the list and pass the information to the DecisionMatrix() function. The DecisionMatrix()
function used a series of “if” statements that read which category this next piece belonged
to. Once the appropriate condition was met and the program flow entered an “if”
statement, a “switch” statement was used in conjunction with a global variable that stored
the current position of the stepper motor, to determine the necessary movement for the
stepper. Each case of the “switch” statements contained different instructions for the
stepper. An example of one of these “if” and “switch” statement blocks is shown below.

10 | P a g e
Figure 14: Example From the DecisionMatrix() Function

4.3 System Pause


The system pause shut down all of the components of the system from the belt and
stepper to the sensors on top of the belt; before continually displaying the number of
pieces sorted into each category and how many were left on the belt. The display was
accomplished with a basic while loop that would loop infinitely.

11 | P a g e
Figure 15: Pause Button Display While Loop

Once the button was pressed again the system was supposed to restart from where it had
left off. Looking at previous demos and what other groups were doing most of the
systems would need to complete their display loop before reacting to the second button
push and would thus the system restart would be delayed. It was decided that the system
pause button should take effect immediately to restart the system as soon as the button
was pressed for the second time; however, this posed several challenges. For starters,
how could we break out of an infinite while loop by pressing a button and still turn off
the display upon exiting the loop?
The solution came in the form of the careful manipulation of a flag and three of the
registers involved with running external interrupts. The pause button flag was initialized
as 0 but upon the first button push it would be assigned to 1 after the program flow had
entered an “if” statement checking its value. After the flag’s value was changed it would
enter the infinite while loop. Upon the second button push, when the interrupt service
routine was restarted, the program flow would skip the first “if” statement and enter a
second “if” statement executing the code to leave the interrupt service routine.

In order for an external interrupt to function 4 registers are used. The SREG registers
contain the global interrupt enable bit which must be set. The “External Interrupt Mask
Register” (EIMSK) enables specific interrupts. The “External Interrupt Control Register
A/B” (EICRA/B) sets the mode of the interrupt (falling edge or rising edge). Finally, the
“External Interrupt Flag Register” (EIFR) contains the bits that change in accordance
with the external stimulus and tell the CPU something has happened. Typically when an
external interrupt is fired the global interrupt enable bit is flipped disabling all of the
other external interrupts. Including the “ISR_NOBLOCK” key word in the interrupt

12 | P a g e
service routine resets the global interrupt enable bit as soon as possible in the interrupt
service routine, meaning that other interrupts can now fire. The “ISR_NOBLOCK” is a
dangerous tool to use and only appropriate for specific cases; it was felt that this was one
such situation and that practice with this tool (and its multiple pitfalls) would provide
excellent learning outcomes. Having the other external interrupts enabled during the
system pause interrupt was a double edged sword. Allowing external interrupts to fire
meant that the system pause could interrupt itself but meant that the sensors would still
fire. To prevent the other interrupts from firing but still enabling the pause button
interrupt to execute required manipulation of the EIMSK register as seen in the following
screen grab.

Figure 16: First if Statement in the Pause Button ISR

Upon the pause button being hit for the first time the program flow would enter this “if”
statement and disable the interrupts. Unfortunately, since the global interrupt enable bit
was reset the external interrupt flags would still be triggered. While this may not seem
like an issue at first it meant that as soon as the interrupts were re-enabled, they would
fire. To overcome this, the bits had to be set to 1 before re-enabling the interrupts (The
bits work backwards in the EIFR).

Figure 17: Second if Statement in the Pause Button ISR

After the pause button flag was set and the interrupts re-enabled the StateMachine()
function was called. The StateMachine() function contained the infinite for loop that the
program sat in while waiting for something to happen. This structure was implemented so
that the ISR of the second button push would not return to the first one upon completion.
It’s suspected that this could lead to a memory overflow or other issues with the stack if
the system was left to run for long enough. However, for the purposes of the testing this
would not be an issue and there was insufficient time to consider manually manipulating
the stack with assembly to correct this potential problem.

13 | P a g e
4.4 System ramp down
The system ramp down function was similar to the system pause button. The major
differences between the two were that the system ramp down used a timer interrupt but
did not use the “ISR_NOBLOCK” command. When the system ramp down button was
pressed the timer interrupt would be activated. The timer interrupt was set up such that it
would only shut down the system after 4 seconds. The delay in action was crucial as it
gave the system time to sort two more pieces. Once the allotted time was up the system
shut all of the sensors and motors off; before using the same while loop as the system
pause, to output a display on the LEDs.

5. System Performance Specifications


Testing of the system on the demonstration day resulted in sorting 48 parts in 45 seconds
with 1 error. The system parameters governing the speed of the system were that of the
stepper motor and the DC motor that turns the conveyer belt. Running the stepper motor
at the highest acceleration and speed resulted in the fastest placement of the parts but
would result in the motor seizing as the weight of the parts increased during the test.
Adding more than 8 parts onto the belt at once did result in a faster sorting time of 34
seconds but 7 errors were reported. The reason for the high amount of errors was due to
the timer interrupt on the stepper motor, the exit sensor interrupt, and the ADC interrupt
fighting for processor time. If the ADC value was poor then the part was misclassified
and sorted incorrectly.

To avoid system failure during testing, the stepper motor had to be slowed down
significantly to handle to load on the sorting tray. Additionally, near the testing date it
was identified that the exit sensor was double firing due to hardware bouncing and was
mitigated with a capacitor.

Sorting 48 parts within 45 seconds with one error did fall short of the team’s initial goal.
However, the system has the potential to operate at a much higher speed as each
component of the system was implemented with advanced control techniques. The slower
time can be attributed directly to calibration issues when testing along with last minute
adjustments to the stepper delay that needed to be made in order to complete the demo.

6. Testing and Calibration Procedure


To define the part classification boundaries the minimum ADC values of 10 parts were
collected by passing each through the optical reflective sensor. Once obtained the 10-bit
value was output onto 8 LED’s on a breadboard and the last two onto the
microcontrollers built in LEDs.

This 10-bit number was then converted into a decimal and logged on an excel sheet
where the minimum, maximum, and average are calculated as shown below in Figure 18.

14 | P a g e
Figure 18: Calibration Spreadsheet Example

The calibration procedure was completed multiple times prior to the demo to achieve the
most stable ADC values. One major complication that was identified just prior to testing
is that the values of changed when the mini USB connection was removed from the
controller. According to the lab TA about 50% of the microcontrollers change the base
line values wen the USB cable is plugged in. This was detrimental to the test as parts
were classified incorrectly because the system was calibrated with the USB cable plugged
and then tested with it unplugged.

To resolve the issue the TA allowed the team to have the USB cable plugged in during
the testing so that the reference values matched the firmware flashed onto the controller.

7. Limitations and System Tradeoffs

7.1 Stepper Motor Tray Weight


To move heavy objects the stepper motor needs to output more torque and to do this the
motor must turn at a slow angular velocity. This is a major limitation as the stepper is not
operating at its hardware limitation just to account for the weight of the parts that remain
on the sorting tray. This is explained with more technical deal in Section 8 of this report.

7.2 Belt Speed and ADC


The limitation the exists with the belt speed is that at higher speed the parts get to the end
of the belt faster but the accuracy of classifying the part is not as good. This is because
the part remains within the optical beam sensor for a brief period resulting in fewer
readings. Additionally, if the parts are travelling at a higher velocity than the ADC values
compounded with noise could produce poor sorting results.

8. Novel System Additions


The system displayed a few novelties that separated the team from the others. The first
being continuous adjustment of the step delay and linear ramp control of the stepper
motors angular acceleration. The second novelty added to the system was a progressive
kinematic adjustment of the stepper motor with part loading.

15 | P a g e
8.1 Timer Interrupt Driven Stepper Motor
The stepper motor control is based off of Atmel’s linear speed control of a stepper motor
[1]. The document describes how to implement an exact linear speed controller for
angular acceleration and deceleration. The desired speed profile of the motors is shown
below in Figure 19.

Desired Speed Slope

Figure 19. Angular Acceleration, Speed, and Position [1]

The desired speed sloped is achieved be exponential decreasing or increasing the delay
between pulsing the stepper motor. This is displayed conceptually below in Figure 20.

Figure 20. Speed Profile vs. Stepper Motor Pulses/Speed

The firmware is implemented with a timer that is pre-scaled based on the frequency of
the microcontroller clock speed. In this case, the AT90USB1287 runs at 1 MHz and a
pre-scaler of 64 results in a timer reset of 15625 Hz. The system requires:

16 | P a g e
1. The minimum timer length.
2. Step delay.
3. Maximum number of steps to achieve desired speed.
4. The number of steps before deceleration starts.

If the maximum speed is greater than the acceleration limit of the stepper motor then the
deceleration value is calculated and the stepper will decelerate to keep a smooth speed
profile. The acceleration/deceleration state diagram is shown below in Figure 21.

Figure 21. State Machine for Timer Interrupt

The default state is STOP and sits in this state if the stepper is not moving. As soon as the
step amount, acceleration, deceleration, and speed are given to the stepper control
function a 16 bit timer is turned on, the system constants are calculated, and the largest
value the timer can count to is reset. It should be noted that the acceleration, deceleration,
and speed are all scaled by a factor of 100 to increase the resolution and computing
speed. This relation is tabulated below in Table 3. Scaling of Standard SI Values.

Table 3. Scaling of Standard SI Values

Parameter SI Value Firmware Value


Steps 200 200
Speed 10 rad/s 1000
Acceleration 220 rad/s2 22000
Deceleration 220 rad/s2 22000

8.2 Stepper Progressive Adjustment


As more parts drop onto the sorting tray the weight that the stepper motor has to fight
increases, which means the stepper motor cannot operate at its maximum speed and
acceleration parameters. To adjust to these system conditions the stepper motors velocity
and acceleration are adjusted every 16 parts that are sorted. A global variable is used to

17 | P a g e
count the number of part sorted and then the acceleration, deceleration, and speed are set
accordingly as shown below in Table 1.

Table 4: Progressive Stepper Adjustment

Parts Sorted Acceleration Deceleration Speed


0-16 135 rad/s2 145.8 rad/s2 5.9 rad/s
17-25 115 rad/s2 115 rad/s2 4.7 rad/s
26-48 105 rad/s2 105 rad/s2 4.0 rad/s

With a total of 3 incremented step changes of velocity across the entire sorting the fasted
possible stepper movement can be achieved. However, these values are not the optimal
values for the stepper speed and could be tuned to get the fast stepper speed. The team
ran out of time and had to reduce the stepper motor parameter to ensure the demo could
be completed.

9. Experience and Recommendations


During the development of the conveyer system many rudimental software
implementations were honored to a higher level of respect. The group did contain a fair
bit of software experience but not in the field of embedded C. The major take away was
that embedded C programming requires in depth understanding of the hardware manual
to ensure that the microcontroller is setup in the right mode.

When concerned with future development of this system, it is recommended that more
time be spent optimizing the stepper motor acceleration and speeds for the progressive
stepper adjustment. This is suggested because the implementation for a very fast sorting
machine is there but the time for optimization was overlooked which was detrimental to
the system performance. The second recommendation to improve the sorting speed would
be to move the stepper motor to a parts respective container before it reached the exit
sensor so that no delay would exist when sorting parts.

Overall, the team was thoroughly impressed with the amount of knowledge and
experience that was obtained implementing this system and each members interest within
the field of mechatronics has definitely increased.

18 | P a g e
10. References
[1] Atmel Corporation, "AVR446: Linear speed control of stepper motor," pp. 1-
15, 2006.

19 | P a g e
Appendix A – List of Global Variables
Table 5: List of Global Variables

Variable Type Description Initialization


Value
ADC_result unsigned int The minimum value from ADC 0xffff
classificationValue unsigned int Value corresponding the part 0
cw char DC motor cw direction 0x02
ccw char DC motor ccw direction 0x01
dir int Stepper motor direction 0
stepAmount int Number of steps 0
Classifier unsigned char Next part classification 0
lastStep int Last step the motor is on -1
stepperPos int Part the stepper container is on 0
setupMode int 0 if stepper needs to home 0
black int The amount of back sorted 0
steel int The amount of steel sorted 0
white int The amount of white sorted 0
aluminum int The amount of aluminum sorted 0
partCount int The amount of parts sorted 0
exitSensor_Flag char If exit sensor is active 0
pauseButton_Flag char If pause button is active 0
rampDown_Flag char If ramp down is active 0
acceleration unsigned int Value for SpeedControlMove() 0
deceleration unsigned int Value for SpeedControlMove() 0
speed unsigned int Value for SpeedControlMove() 0

i|Page
Appendix B – System Level Diagram
System pause

Initial setup and initialization


Interrupt 6 fires

Interrupt 7 fires Infinite For loop in Timer interrupt fires


StateMachine()

Ramp down flag set to 1 and


timer interrupt 2 activated
Piece enters the
second light sensor
Object has
been
dequeued from
Piece enters the list
exit sensorx
Interrupt 0 fires

No
Interrupt 2 fires Begins ADC conversion

ADC interrupt fires Return to previous function


Conveyor belt is or interrupt
stopped

Compares the current conversion


with the previously stored value and Yes
xLinked list is saves the larger of the two
dequeued

Move stepper
A value is read from the
object and fed through a Piece leaves the
switch statement to second light sensor
determine piece Return to previous function
or interrupt

Yes
Stepper moves from
current position to List already Enqueue is called, new link
new created? with conversion is created

No
Current position is stored in Return to main
a global variable
A new list is created

Return to main Enqueue is called, new link


with conversion is created

Return to main

i|Page
Appendix C – Circuit Diagrams

Sheet Description
1 Shows the port configuration and pin out
for the AT90USB1287

2 Shows the layout for the stepper motor and


DC motor. Includes all power supplies and
control pins to the AT90USB1287

i|Page
1|Page
2|Page

You might also like