Escolar Documentos
Profissional Documentos
Cultura Documentos
478
! ! ! ! ! ! !
Introduction - Sensing, Interfacing and Programming Photoresistor IR Proximity Sensor Pyroelectric Sensor Ultrasonic Ranging Sensor Shaft Encoders Microswitch
Interface Between Sensors and Micro Sensor-interface electronics Sensor-driver routines Software Drivers Once a set of sensors has been selected and the proper interface circuitry has been designed to connect your sensors to a microprocessor, the microprocessor has to be programmed to read the sensors. These pieces of code are often written in assembly language and are known as software drivers. Software drivers provide a well-defined interface between a hardware device (intelligent machine) and a program that needs to use the device. Software drivers deal with the hardware-software interface
Photoresistors
I. Principle and Interfacing Total resistance: RT=R+RL Current : I=V/RT The voltage on PE1: VPE1=I RL => VRL/(R+RL) MC6811 8-bit A/D converter maps the variable voltage, VPE1, into the range 0 to 255. A good compromise between sensitivity and range will be achieved if the resistance R is set to the same value as the resistance exhibited by the photoresistor when exposed to the light level in the middle of the range of light level in which the machine must operate.
II. Software Driver MC6811 port E - 8-bit input port or 8-channel analog-to-digital converter. - Internally only A/D circuit for entire port, only four registers to store results from the eight channels. - Voltage reference pins VRH, VRL - Two control registers ADCTL, OPTION, are used to configure the mode of conversion.
Conversion sequences can be chosen that repeat on a single channel for four times or on four channels, once each. For later mode, two banks of four PE0-PE3 and PE4-PE7. Conversions are complete 34clock cycles after the ADCTL register is written. After each conversion, results are posted in registers ADR1, ADR2, ADR3, ADR4.
Configuring ADCTL
When SCAN=0, four conversions are performed, once each When SCAN=1, conversions continue in a round-robin fashion. When MULT=0, four conversions are repeated on a single channel. The selected channel is set by the lower four bits of ADCTL. When MULT=1, one bank of four channels is converted.
(if bits 2 and 3 are set 0, channels PE0-PE3 are converted. If bits 2 and 3 are set 1, channels PE4-PE7 are converted.)
Assembly Code
ph-right ph-left option adctl adr1 adr2 equ $10 equ $11 equ $1039 equ $1030 equ $1031 equ $1032
update-photo bset option #%10000000 bset adctl #%00010000 check-result brclr adctl #%10000000 check-result ldaa adr1 staa ph-right ldaa adr2 staa ph-left rts
C Code
int ph_right=0; int ph_left=0; void update_photo() { poke(option, 0b10000000); poke(adctl, 0b00010000); while ( (peek(adctl) & 0b10000000)==0) {} ph_left=peek(adr1); ph_right=peek(adr2);}
- The detector responds to a carrier frequency of 40 kHz. A frequency 40 kHz means the LED is blinked on and off with a period of 25 us. This signal is then modulated at a lower frequency so that the blinking is on for 600us and then off for 600us. - The LEDs blink only when pins PD2 and PD3 of port D are asserted, which can be done by writing a program. - The detector is a digital signal, either 0 or 5V. Pin PE4 of MC6811 can be used in the normal digital input mode. The A/D converter capacity is not necessary here.
Pyroelectric Sensors
I. Principle and Interfacing - Essential component in certain types of motion detecting burglar alarms. A lithium tantalate crystal. - The output changes when small changes in the temperature of the sensor occur over time. - Charge is induced as the crystal is heated. Detect radiation in the 810um range (the range of infrared energy emitted by humans). - The Eltec 442-3 sensor incorporates two lithium tantalate crystals. The amplified difference of the voltage across the crystals is the output of the sensor. In the case that both crystals are at the same temperature, the sensor produces an output signal that remains steady at about 2.5V (assuming a 5 V power supply). If a person walks in front of the sensor moving from left to right, the signal will arise above 2.5V by about one volt and then fall below it, finally returning to the steady-state value. Should a person walk in front of the sensor mvoing from right to left, the reverse will happen.
Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand
Microswitches
- MC6811 Interfacing Two input capture registers to record the time when the sonar ping begins its flight and the time when the echo is detected. The input lines PA1 and PA2 are associated with the timer. PD2 and PD3 used to control its infrared emitters. Using the logical AND (HC08 chip) of signals from PD2 and PD3 to initiate a sonar ping. When PD2 and PD3 are asserted, INIT and PA2 are forced high, the former initiates a sonar ping. Upon detection of a returning echo, the ranging board asserts Echo, driving PA1 high. The gate AND acts as a buffer to drive the LED, when Echo goes high, the LED lights, giving a visual indication that an echo has been detected.
Shaft Encoders
I. Principle & Interfacing The disk attaches to the motor shaft and spins with it. A nearinfrared LED is placed on one side of the disks slots and a phototransistor on the other. As the disk spins, the light passing through the disk is interrupted by the moving slots, and a signal in the form of a pulse train is produced at the output of the phototransistor. By using a microprocessor to count these pulses, the robot can tell how far its wheels have rotated. The interface between shaft encoders and MC6811 port A pins PA7 and PA0. Shaft encoder data from the left wheel are counted by the pulse accumulator hardware associated with PA7. For the right wheel, interrupts are triggered by the input capture hardwarre (IC3) connected to PA0. Shaft-encoder pulses are counted in software in an interrup-handler routine.
Dr. Peter Xu, Copyright, ITE, Massey University, New Zealand
TMSK1 register
TFLG1 register
TCTL2 register
Supervising Program
int TCTL2= 0x1021; int TMSK1=0x1022; int TFLG1=0x1023; int PACTL=0x1026; int PACNT=0x1027; void init_velocity() { poke(PACTL, 0b01010000); poke(PANCT,0); bit_clear(TCTL2, 0b00000010); bit_set(TCTL2, 0b00000001); bit_set(TMSK1, 0b00000001); } float get_left_vel() { float vel; vel = (float) peek(PACNT); poke(PACNT,0); return (vel); } float get_right_vel() { float vel; vel = (float) right_clicks; right_clicks=0; return (vel); }