Download presentation
Presentation is loading. Please wait.
Published byHilda Poole Modified over 9 years ago
1
Line Sensing 101 TEAM SpeedRacers _______Team Leader _______ Hardware Specialist _______ Software Specialist _______ Assistant 1
2
Overview Problem statement Hardware – requirements / constraints – interface Software – MCU module(s) needed – code for initialization, operation Q&A 2
3
Problem Statement Line Sensing: to determine relative position of track line beneath car. Line is ¾" wide black on white background – electrical tape – sample 8.5"x11" on website Line Sensor MCU 3
4
Hardware Pololu QTR-8RC Reflectance Sensor Array – module of 8 IR LED/phototransistor element pairs 4
5
QTR-8RC Reflectance Sensor Array Specifications: Dimensions: 2.95" x 0.5" x 0.125" (without header pins installed) Operating voltage: 3.3-5.0 VDC Supply current: 100 mA (all IRLEDs on) Output format: digital I/O compatible Optimal sensing distance: 0.125" (3 mm) Max recommended sensing distance: 0.375" (9.5 mm) Weight without header pins: 0.11 oz (3.09 g) 5
6
QTR-8RC Reflectance Sensor Array Operation: each element has an R-C circuit capacitor discharge rate is a function of reflected IR light – greater reflectance = shorter discharge time algorithm: – C is 1 st charged by driving it with a high output from an MCU I/O pin (~16us, use 20 to be safe) – I/O pin is switched to input and time to H L transition is measured or simply wait for time 'x' and read H or L input 6
7
Scope Shots* Output (yellow) 1/8" above white surface and MCU timing (blue) Output (yellow) 1/8" above black line and MCU timing (blue) * see data sheet for link to hi-res image 7
8
Interface QTR-8RC is interfaced to an 8-bit MCU I/O port via a ribbon cable and breadboard adapter 8
9
Software: Algorithm 1.Turn on IR LEDs (if off) 2.Set 8-bit I/O port to all outputs 3.Set output port to all highs 4.First Delay (20us) 5.Set I/O port to all inputs 6.Second Delay (?) 7.Read 8-bit H/L input value 8.Turn off IR LEDs (opt.) 9
10
Software Implementation to achieve us delays, we will need to employ the MCU's timer peripheral (TPM1) and also speed up the MCU from 4 MHz default to 24 MHz (using the MCG) QTR-8RC is interfaced to I/O portB 10
11
Software: Initialization // initialize MCG module to use external crystal void MCGinit() { MCGC1 = 0x1c; // set RDIV = 12MHz/8 = 1.5MHz MCGC2 = 0x64; // BDIV=2, enable ExtRef and Hi Range MCGC3 = 0x48; // select PLL source and VDIV= x32 // VCO is now going to 48 MHz MCGC1_IREFS = 0; // turn off IREFS while (!MCGSC_LOCK) {} // wait for OSC initialization to complete // MCGOUT=24Mhz, Busclk=12MHz } // MCU-specific initialization void initializeMCU() { SOPT1_COPT = 0; // disable COP SOPT2_CLKOUT_EN = 1; // enable BUSCLK output on PTF4 MCGinit(); // activate MCG for 24 MHz clock // I/O port initialization FB_YLED_ENABLE; // set PTE6 to be output (to yellow LED) // Real-Time Counter initialization RTCSC = 0x08; // enable RTC, select 1ms period from 1kHz internal clock RTCMOD = 9; // RTIF every 10ms // TPM1 initialization TPM1SC = TPM1SC_CLKSA_MASK // select bus clock for timer clock + 2; // divby-4 prescaler (12MHz / 4 = 3MHz Timer clock) EnableInterrupts; } 11
12
Software: Timing Support usDelay() is similar to previous msDelay() except much higher clock source is used – 12 MHz bus clock instead of 1 kHz LPO void usDelay(unsigned short n) { word timerticks = 3*(n-1); // x3 because Timer is clocked at 3MHz word startcnt = TPM1CNT; // wait for time to elapse while ((word)(TPM1CNT-startcnt) < timerticks) {} } 12
13
Software: Line Sensing when line position data is needed, a call to "read_irarray" is made – ex:byte irdata; ∶ irdata = read_irarray(); byte read_irarray() // read & return line sensor data { PTBD = 0xff; // make Port B all highs PTBDD = 0xff; // make Port B all outputs usDelay(20); // allow sensor caps to charge PTBDD = 0; // switch to all inputs usDelay(600); // delay for discharge return PTBD; // read & return sensor array results } 13
14
Performance Issue Considering amount of power required to drive the IRLEDs and the sensor sample rate, a huge power savings would be achieved if IRLEDs are turned off between readings. Ex: if LEDs are on 1ms and sensor is read at 10Hz, the D.C. of the LEDs is 1ms/100ms = 1% – applied to the 100 mA! 14
15
Summary Problem statement Hardware – requirements / constraints – interface Software – MCU module(s) needed – code for initialization, operation 15
16
References Huang, Han-Way. HCS12/9S12: An Introduction to Software and Hardware Interfacing. 2 nd ed. Delmar, Cengage Learning, 2010. MCF51JM128 ColdFire Integrated Microcontroller Reference Manual. 2. Freescale Semiconductor, Inc., 2009. Web. http://www.aet.calu.edu/ftp/cet/360/resources/Coldfire/MCF51JM 128-RefManual-v2.pdf. http://www.aet.calu.edu/ftp/cet/360/resources/Coldfire/MCF51JM 128-RefManual-v2.pdf QTR-8RC Reflectance Sensor Array." Pololu -. N.p., n.d. Web. 18 Feb. 2014. http://www.pololu.com/catalog/product/961http://www.pololu.com/catalog/product/961 Sumey, Jeff. “CET Microprocessor Engineering.” California University of Pennsylvania. Web. 18 Feb 2014. http://aet.calu.edu/~jsumey.http://aet.calu.edu/~jsumey 16
17
QUESTIONS? 17
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.