light sensors ece 4437 dr. j. glover 10-15-2015 team 9: jitin george zachary freeman
TRANSCRIPT
Light SensorsECE 4437
Dr. J. Glover10-15-2015
Team 9:Jitin George
Zachary Freeman
Overview
QTR-1RC Reflectance SensorReflectance timeInitialize Pins for I/OTimerInterfacing outputs to digital I/O Data CheckWorks Cited
QTR-1RC Reflectance Sensor• Carries a single infrared LED and phototransistor pair
• The LED current-limiting resistor delivers approximately 17 mA to the LED when VIN is 5 V
• The phototransistor uses a capacitor discharge circuit and the discharge time is used to take an analog reading of the reflected IR
Shorter capacitor discharge time is an indication of greater reflectance
Reflectance Time
• Strong Reflectance (White) - decay time can be as low as several microseconds
• No Reflectance (Black) – decay time can be as high as a few milliseconds
Initialize Pins for I/O
void PortE_Init(void){ volatile unsigned long delay; SYSCTL_RCGCGPIO |= 0x00000010; // Activate clock for Port E delay = SYSCTL_RCGCGPIO; // Allow time for clock to start GPIO_PORTE_CR_R = 0x10; // Allow changes to PE4 GPIO_PORTE_AMSEL_R = 0x00; // Disable analog on PE GPIO_PORTE_PCTL_R = 0x00000000; // GPIO on PE GPIO_PORTE_AFSEL_R = 0x00; // Disable alt funct on PE7-0 GPIO_PORTE_DEN_R = 0x10; // enable digital I/O on PE4}
Timer
• Initialize Timer
SYSCTL_RCGCTIMER = 0x00000001; // Initializing Timer0
• Clear residual bits TIMER0_TAMR &= ~ 0x00000000;
• Write the GPTM Configuration Register (GPTMCFG) with a value of 0x00000001
TIMER0_CFG = 0x00000001;
Timer• Set the TnEN bit in the GPTMCTL register to enable the timer and
start counting
TIMER0_CTL |= 0x01; // Starts the timer
Interfacing Outputs to Digital I/O
• Set the I/O line to an output and drive it high
Interfacing Outputs to Digital I/O
• Wait 10 microseconds for the 10[nF] capacitor to charge
Interfacing Outputs to Digital I/O
• Make the I/O line an input (high impedance)
volatile unsigned long start, end, meas; start = TIMER0_TAR; • Wait for the I/O line to go low
Interfacing Outputs to Digital I/O • Read end time
end = TIMER0_TAR;
• Calculating discharge time of the capacitor
meas = end – start;
Data Check
Works Cited
[1] J. Valvano and R. Yerraballi. (2014). Chapter 6: Parallel I/O ports [Online]. Available: http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C6_MicrocontrollerPorts.htm
[2] J. Pham and C. Harder. (2014). Light Sensor [PowerPoint].
[3] Polulu Robotics & Electronics. QTR-1RC Reflectance Sensor [Online]. Available: https://www.pololu.com/product/959