⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 introductionhardwaresoftwareresu.htm

📁 机器人应用的全套实例寻机小车
💻 HTM
📖 第 1 页 / 共 5 页
字号:
  <P class=MsoNormal align=center>Figure 4: Photosensors</P>
  <P class=MsoNormal align=justify><FONT face="Palatino Linotype" 
  size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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.&nbsp; </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:&nbsp; The figure to the far left shows a BJT connected to a pull-up 
  resistor.&nbsp; Vout = Vcc – Ic*R.&nbsp; If the sensor is over black paper, Ic 
  will be small and Vout will be closer to Vcc than we want. &nbsp;This accounts 
  for the larger than expected reading we observe</FONT></SPAN><SPAN 
  style="COLOR: black; FONT-FAMILY: Palatino Linotype"><FONT size=4>d. 
  &nbsp;</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">&nbsp;</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. &nbsp;In 
  this case, the smaller current would correspond to a smaller 
  voltage.</SPAN></FONT><FONT face="Palatino Linotype" size=4>&nbsp; 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.&nbsp; The program cycles back and forth between reading the sensor’s 
  output and moving the car.&nbsp; &nbsp;&nbsp;</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>&nbsp;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.&nbsp; The program sets up the ADC so that it uses 
  AVCC as the voltage reference source, which is the MCU’s internal 5V 
  reference.&nbsp; The program also left-adjusts the result in the ADC data 
  register and reads only the first 8-bits.&nbsp; 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.&nbsp; </FONT></SPAN></P>
  <P class=MsoNormal 
  style="TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify"><SPAN 
  style="FONT-FAMILY: Palatino Linotype"><FONT 
  size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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.&nbsp; In each state, we read from the ADC 
  data register once before moving to the next state.&nbsp; We sweep through the 
  right, left, and middle sensors in that order before cycling back to read the 
  right one.&nbsp; The first command in each state is to read from ADCH, the ADC 
  data register which contains the values of the conversion.&nbsp; Then, the 
  program changes which pin to read from by adjusting the appropriate data bits 
  in ADMUX.&nbsp; Before transitioning to the next state, the program re-enables 
  ADSC to begin another conversion.&nbsp; 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.&nbsp; This leads to unintentionally reading from the same channel 
  twice.&nbsp; &nbsp;</FONT></SPAN></P>
  <P class=MsoNormal style="TEXT-ALIGN: center"><FONT size=4><SPAN 
  style="FONT-FAMILY: Palatino Linotype">&nbsp;&nbsp;&nbsp; <IMG height=222 
  src="IntroductionHardwareSoftwareResu.files/index4.gif" width=429 
  border=0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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>&nbsp;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.&nbsp; Each conversion of the ADC consumes 13 ADC clock cycles (25 clock 
  cycles for the first conversion after enabling the ADC).&nbsp; Reading from 
  the ADC data register or beginning another conversion before 13 clock cycles 
  have finished may lead to incorrect readings.&nbsp; Such errors arose when we 
  tested an earlier version of our program.&nbsp; We placed one sensor over a 
  dark strip of paper while placing the other sensors over white piper.&nbsp; By 
  printing the value in ADCH for each sensor to Hyperterm, we would be able to 
  determine if our ADC setup was correct.&nbsp; 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.&nbsp; 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.&nbsp; 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.&nbsp; 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>&nbsp; A simple counter 
  helped clear this problem.&nbsp; We put the counter in a timer2 overflow 
  ISR.&nbsp; With the MCU clock at a prescaler of 64, the counter would 
  increment every 64/16MHz x 250 = 1 msec.&nbsp; Within each state, we would 
  wait until the counter increments before reading from ADCH and starting 
  another conversion.&nbsp; This millisecond buffer provides enough time (much 
  more time than is needed actually) for one complete conversion.&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  After sampling the sensor output, the program enters another state machine 
  which controls how the car should move.&nbsp; The first state, state 
  <I>stop</I>, checks the values from the variables that store the readings from 
  each sensor.&nbsp; 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 + -