📄 introductionhardwaresoftwareresu.htm
字号:
<P class=MsoNormal align=center>Figure 4: Photosensors</P>
<P class=MsoNormal align=justify><FONT face="Palatino Linotype"
size=4> We connected
330Ω resistors to the input of the diodes of the photosensors to limit the
input current to 13mA from the 5V power supply. It prevents too much current
from entering the diode and destroying it. At first we tried using 1kΩ pull-up
resistors between the collector and 5V power source. We then scoped the output
of the photosensor to see its sensitivity and voltage reading when we placed
white or black paper over it. Unfortunately, the phototransistor output
fluctuated from a few hundred mV to about 3V. Under black, the
phototransistors output should consistently be very low. However, it seemed
like the phototransistor was detecting sudden movement more than color. When
we switched from white to black, the voltage reading would suddenly flicker
from high to low for a few seconds and then it would return back to a high
reading even tho</FONT><FONT face="Palatino Linotype" size=4>ugh black was
still placed under the sensors. </FONT></P>
<P class=MsoNormal align=justify><SPAN
style="COLOR: black; FONT-FAMILY: Palatino Linotype"><FONT size=4><IMG
height=244 src="IntroductionHardwareSoftwareResu.files/index3.gif" width=115
align=left border=0><IMG height=243
src="IntroductionHardwareSoftwareResu.files/index2.gif" width=120 align=left
border=0>We believe the mistake can be e</FONT></SPAN><SPAN
style="COLOR: black; FONT-FAMILY: Palatino Linotype"><FONT size=4>xplained as
follows: The figure to the far left shows a BJT connected to a pull-up
resistor. Vout = Vcc – Ic*R. If the sensor is over black paper, Ic
will be small and Vout will be closer to Vcc than we want. This accounts
for the larger than expected reading we observe</FONT></SPAN><SPAN
style="COLOR: black; FONT-FAMILY: Palatino Linotype"><FONT size=4>d.
</FONT></SPAN><FONT face="Palatino Linotype" size=4>Therefore, we
decided to switch to using a pull-down resistor as opposed to a pull-up
resistor. </FONT><SPAN
style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Palatino Linotype"> </SPAN><FONT
size=4><SPAN style="COLOR: black; FONT-FAMILY: Palatino Linotype">The figure
to the near left shows that V</SPAN></FONT><FONT size=4><SPAN
style="COLOR: black; FONT-FAMILY: Palatino Linotype">out = Ie * R. In
this case, the smaller current would correspond to a smaller
voltage.</SPAN></FONT><FONT face="Palatino Linotype" size=4> We
connected a 10kΩ resistor in series to a 10kΩ potentiometer between the
emitter and ground on the output of the phototransistor. We used a
potentiometer instead of a static resistor to adjust the pull-down resistance
accordingly to the ambient light. We tested the circuit and it worked better
than the pull-up configuration. We adjusted the potentiometer until we found
the optimal setting. </FONT></P>
<P class=MsoNormal align=justify><FONT face="Palatino Linotype" size=4>The
pull-down resistance of the 10kΩ resistor and potentiometer was about 15kΩ
total. This time, the sensors provided consistent outputs with little
fluctuations. Under white, there was maximum reflectance so the sensors output
approximately 3.9 - 4.1V. Under black, there was maximum absorbance of light
so the sensors output approximately 200 - 250mV. There was a large voltage
difference between white and black readings to enable easy differentiation
between the two colors. We then connected the senor output to Port A.0 of the
microcontroller and tested the sensor using the analog to digital converter
with the internal 5V reference. The<I> </I>conversions were stored in
Ain<I>;</I> for black, Ain values were around 10 - 15, and they were around
190 - 210 for white. We also determined that the sensors performed better
under brighter lighting conditions. Since the sensors are mounted on the
bottom of our car, we decided to add LEDs near the sensors to illuminate the
ground. We placed an LED next to each sensor. The LEDs were again current
limited by placing a 330Ω resistor in series with the 5V power
supply.</FONT></P>
<P class=MsoNormal style="TEXT-INDENT: 0.5in" align=justify><FONT
face="Palatino Linotype" size=4>We chose to use three phototransistors
configured in the shape of a V with the middle sensor out in front of the left
and right sensors. We decided to use three sensors because the sensors were
voluminous and we simply could not mount more on our small car. We decided to
use a V configuration to help the car detect turns in the course. With the
middle sensor out in front, it will detect white first. Then, the left or
right sensors will detect if the course turns or not.</FONT></P>
<P class=MsoNormal style="TEXT-INDENT: 0.5in" align=justify><FONT
face="Palatino Linotype" size=4>For our final version of the sensors, we
soldered three phototransistors in a V configuration onto a small protoboard.
We also soldered three green LEDs adjacent to the phototransistors. The entire
sensor suite, including the LEDs, was powered off of V<SUB>cc</SUB> from the
mini STK board.</FONT></P>
<P class=MsoNormal style="TEXT-INDENT: 0.5in" align=justify><A
href="http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2007/bl222_wh84/bl222_wh84/index.html#top">Back
to Top</A> </P></BLOCKQUOTE>
<H1><FONT face="Palatino Linotype"><A id=sware></A>Software</FONT></H1>
<BLOCKQUOTE>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><SPAN
style="FONT-FAMILY: Palatino Linotype"><FONT size=4>The program to run the car
consists of a portion to sample data from the photosensors and a portion which
uses that data to send the right logic signals to the circuit controlling the
motor. The program cycles back and forth between reading the sensor’s
output and moving the car. </FONT></SPAN></P>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><B><SPAN
style="FONT-FAMILY: Palatino Linotype; TEXT-DECORATION: underline"><FONT
size=4> Sampling Data from Photosensors:</FONT></SPAN></B></P>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-INDENT: 0.5in; TEXT-ALIGN: justify"><SPAN
style="FONT-FAMILY: Palatino Linotype"><FONT size=4>We use the Mega32 ADC to
read the output of each of the three sensors; the outputs are fed into the
first three pins of Port A. The program sets up the ADC so that it uses
AVCC as the voltage reference source, which is the MCU’s internal 5V
reference. The program also left-adjusts the result in the ADC data
register and reads only the first 8-bits. With the exception of using
AVCC rather than AVEC as the voltage reference, our setup is the same as that
of the simple ADC code provided to us by Professor Land for a number of the
semester’s labs. </FONT></SPAN></P>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><SPAN
style="FONT-FAMILY: Palatino Linotype"><FONT
size=4> A
simple state machine, running continuously in the function <I>main,</I>
collects data from each sensor and stores the values in variables that will be
used to inform the car’s motion. In each state, we read from the ADC
data register once before moving to the next state. We sweep through the
right, left, and middle sensors in that order before cycling back to read the
right one. The first command in each state is to read from ADCH, the ADC
data register which contains the values of the conversion. Then, the
program changes which pin to read from by adjusting the appropriate data bits
in ADMUX. Before transitioning to the next state, the program re-enables
ADSC to begin another conversion. It is important to change the pin
selection first before enabling the conversion; flipping the order of these
commands means the ADC will finish a conversion first before switching
channels. This leads to unintentionally reading from the same channel
twice. </FONT></SPAN></P>
<P class=MsoNormal style="TEXT-ALIGN: center"><FONT size=4><SPAN
style="FONT-FAMILY: Palatino Linotype"> <IMG height=222
src="IntroductionHardwareSoftwareResu.files/index4.gif" width=429
border=0> </SPAN></FONT></P>
<P class=MsoNormal style="TEXT-ALIGN: center"><FONT size=4><SPAN
style="FONT-FAMILY: Palatino Linotype">Figure 5: State Machine for
Sensor</SPAN></FONT></P>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><I><SPAN
style="FONT-FAMILY: Palatino Linotype"><FONT size=4> Issues:
</FONT></SPAN></I><SPAN style="FONT-FAMILY: Palatino Linotype"><FONT
size=4>Timing issues posed some problems when writing this portion of the
code. Each conversion of the ADC consumes 13 ADC clock cycles (25 clock
cycles for the first conversion after enabling the ADC). Reading from
the ADC data register or beginning another conversion before 13 clock cycles
have finished may lead to incorrect readings. Such errors arose when we
tested an earlier version of our program. We placed one sensor over a
dark strip of paper while placing the other sensors over white piper. By
printing the value in ADCH for each sensor to Hyperterm, we would be able to
determine if our ADC setup was correct. We noticed that some of the
values that we would expect from one of the other sensors were showing up
along with values from the sensor being tested. In that program, we set
the MCU clock with a prescaler of 64, while running the ADC at a prescaler of
128, and read ADCH immediately after enabling a new conversion. Thus,
there did not seem to be enough time for the conversion to complete itself
before we read from the register so we were getting data from previous
readings. This explains why we saw high values from the sensors over
white paper interspersed with the low readings from the sensor over dark
paper.</FONT></SPAN></P>
<P class=MsoNormal
style="TEXT-JUSTIFY: inter-ideograph; TEXT-INDENT: 0.5in; TEXT-ALIGN: justify"><SPAN
style="FONT-FAMILY: Palatino Linotype"><FONT size=4> A simple counter
helped clear this problem. We put the counter in a timer2 overflow
ISR. With the MCU clock at a prescaler of 64, the counter would
increment every 64/16MHz x 250 = 1 msec. Within each state, we would
wait until the counter increments before reading from ADCH and starting
another conversion. This millisecond buffer provides enough time (much
more time than is needed actually) for one complete conversion.
</FONT></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-WEIGHT: 700; FONT-FAMILY: Palatino Linotype; TEXT-DECORATION: underline"><FONT
size=4>Moving the car:</FONT></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Palatino Linotype"><FONT
size=4>
After sampling the sensor output, the program enters another state machine
which controls how the car should move. The first state, state
<I>stop</I>, checks the values from the variables that store the readings from
each sensor. Through testing, we observed that when the sensors output
high, as it does when placed over white paper, the ADC reading is never below
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -