WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20001
Dallas Personal Robotics Group
IR Detector
By: Darren Sawicz
Original Documentation By: Jeff Koenig
his document is an update
reflecting the changes made to
Jeff Koenig's Infrared detector circuit.
The assembly code and circuit are
unchanged but the printed circuit
artwork and documentation have
been upgraded to make assembly
easier.
Theory of Operation
The PIC12C509 generates a 38 kHz
square wave, which delivers current
to the infrared LEDs. The infrared
energy is then reflected off of an
obstacle, if present, and is detected
by the Sharp IR receiver.
The program does the following:
1. Flash the 38 kHz square wave
through the Left infrared LED for
600 microseconds.
2. Check the Sharp detector – if it
detects IR light, go to step 3. If not,
go to step X.
3. Good! A reflection was detected.
But, it might be from another source,
so we will turn off the Left LED and
see if the Sharp detector is sti ll
seeing infrared il lumination (from
another source).
4. Keep the Left infrared LED off for
600 microseconds.
5. Check the Sharp detector – there
shouldn’t be any IR detected, since
we turned off the LED. If there is IR
detected, go to step X,
6. A valid reflection was detected, so
turn on the left LED (red) and bring
header pin 4 high. Skip to step 8.
7. No valid detection was made.
8. Return to step one, but this time
substitute “right” for “left”
The New Board
The new circuit board is smaller than
Jeff Koenig's original board. Each
new board measures 1.5" x 1". This
allows 16 small boards to be cut
from a single 4" x 6" board.
The original ASCII artwork showed
none of the component connections,
only component layout. I created a
schematic drawing of the circuit to
make it easier to see how the circuit
is connected. The schematic is
included on the last page.
T
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20002
12C509
PIC
Detector
Module
IR
IR LED
5 - Pin Header
IR LED
RED LED
1k
Po
ten
tio
me
ter
1k
Po
ten
tio
me
ter
Foil Pattern
R2R1
JP1
D3
RED LED
D2
D4
D1
R3R4
+5V
GND
/INHIBIT
Left Detect
Right Detect
The new board is laid out as follows:
The signals available at the
header pins are:
1. +5VDC - Supply +5 VDC to this
pin.
2. GND - Supply ground to this pin.
3. /INHIBIT - If you want the IRPROX
unit to stop pulsing infrared light,
use your micro to take this pin low
(ground).
4. LEFT DETECT - Output from the
IRPROX module. High (+5V) if
reflection detected.
5. RIGHT DETECT - Output from
the IRPROX module. High (+5V) if
reflection detected.
Parts List
The parts list has been revised to include part numbers from distributors in the
Winnipeg Area.
Part Description Qty. Distributor Part Number
IR Detector Board 1 Winnipeg Area Robotics Society
U1 - PIC 12C508 or 12C509 1 Active # 185-0084Digi-Key # PIC12C508A-04/P-ND
JP1 - 5 x 1 Header 1 Active # 666-2758Digi-Key # S1012-36-ND
R1 & R2 - 330 Ohm Resistor 2 Digi-Key # 330QBK-NDActive – 330 ohm
D1 & D2 - Red LED 2 Digi-Key # 67-1402-NDActive # 303-3033
R3 & R4 - 1k Potentiometer 2 Active # 468-7582
Sharp IR Module 36 kHz 1 Radio-Shack # 276-137
D3 & D4 - IR LED 2 Active # LD271Digi-Key # QED423QT-ND
For M ore Information Please Visit: http://www.winnipegrobotics.com
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20003
Appendix A
Source Code
;
TITLE 'Infra Red Proximity Detector - uses Sharp GP1U581Y'
;
LIST P = 12C509, F = INHX8M
; P12C509.INC Standard Header File, Version 1.02 Microchip Technology, Inc.
NOLIST
;==========================================================================
; Verify Processor
;==========================================================================
IFNDEF __12C509
MESSG "Processor-header file mismatch. Verify selected processor."
ENDIF
;==========================================================================
; Register Definitions
;==========================================================================
W EQU H'0000'
F EQU H'0001'
;----- Register Files -----------------------------------------------------
INDF EQU H'0000' ; Uses FSR to address data mem.
TMR0 EQU H'0001' ; 8 bit real time clock/counter
PCL EQU H'0002' ; Low order 8 bits of PC
STATUS EQU H'0003' ; STATUS
FSR EQU H'0004' ; Indirect data memory addr pointer
OSCCAL EQU H'0005' ; Calibration data for osc.
GPIO EQU H'0006' ; General Purpose I/O
;----- STATUS Bits -----------Page 14--------------------------------------
GPWUF EQU H'0007' ; GPIO reset bit
PA0 EQU H'0005' ; Program Page preselect
NOT_TO EQU H'0004' ; Time Out bit
NOT_PD EQU H'0003' ; Power Down bit
ZERO EQU H'0002' ; Zero bit
DC EQU H'0001' ; Digit carry/*borrow bit
CARRY EQU H'0000' ; carry/*borrow bit
;----- OPTION Bits -----------Page 15--------------------------------------
NOT_GPWU EQU H'0007' ; Enable wake-up on pin change
NOT_GPPU EQU H'0006' ; Enable weak pull-ups
T0CS EQU H'0005' ; Timer0 clock source select
T0SE EQU H'0004' ; Timer0 sources edge select
PSA EQU H'0003' ; Prescalar assignment bit
PS2 EQU H'0002' ;\
PS1 EQU H'0001' ; > Prescalar rate select bits
PS0 EQU H'0000' ;/
;==========================================================================
; RAM Definition
;==========================================================================
__MAXRAM H'3F'
;==========================================================================
; Configuration Bits
;==========================================================================
_MCLRE_ON EQU H'0FFF'
_MCLRE_OFF EQU H'0FEF'
_CP_ON EQU H'0FF7'
_CP_OFF EQU H'0FFF'
_WDT_ON EQU H'0FFF'
_WDT_OFF EQU H'0FFB'
_LP_OSC EQU H'0FFC'
_XT_OSC EQU H'0FFD'
_IntRC_OSC EQU H'0FFE'
_ExtRC_OSC EQU H'0FFF'
__CONFIG ( _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC )
;==========================================================================
; Program Variables
;==========================================================================
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20004
CONSTANT DELAYTIME=D'150' ; Timer value
#define LEFTDETECT GPIO,5 ; Pin 2 = GP5 = Bit 5
#defineRIGHTDETECT GPIO,4 ; Pin 3 = GP4 = Bit 4
#define INHIBIT GPIO,3 ; Pin 4 = GP3 = Bit 3 NOTE: INPUT ONLY!
#define RIGHTLED GPIO,2 ; Pin 5 = GP2 = Bit 2
#define IRDETECT GPIO,1 ; Pin 6 = GP1 = Bit 1
#define LEFTLED GPIO,0 ; Pin 7 = GP0 = Bit 0
LIST
WAIT EQU 9 ; Location for counter for time delay loop
;==========================================================================
; Code Begins
;==========================================================================
start
ORG H'00'
; MOVLW H'7F' ; -- USED FOR OFFSET IN ERASABLE PARTS ---
MOVWF OSCCAL ; Store the factory osc. calibration value
MOVLW B'00001010' ; Set pins 4 as inputs, 2,3,5,6,7 as outputs
TRIS GPIO ; Configure pins as either I or O
MOVLW B'00000000' ; Set OPTION bits
OPTION ; Implement OPTION bits
BCF LEFTLED
BCF LEFTDETECT
BCF RIGHTLED
BCF RIGHTDETECT
main
noflash
BTFSC INHIBIT ; Don't flash the IR Leds if the INHIBIT pin is low
GOTO do_left ;
BTFSC IRDETECT ; Check the IR detector
GOTO NF1
GOTO NF2
NF1 BCF LEFTDETECT ; No 38 KHz IR detected
BCF RIGHTDETECT ; So turn on off right and left LED
NF2 BSF LEFTDETECT ; 38 KHz IR detected
BSF RIGHTDETECT ; So turn on right and left LED
GOTO noflash ;
do_left
CALL pulseleft ; Pulse the left IR LED at 38 KHz for 600 microseconds
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_left ; IR detector didn't sense reflection with Left LED on
CALL delayloop ; Wait 600 microseconds
BTFSS IRDETECT ; Read the Sharp Module. Skip next inst. if no detection
(0=detect)
GOTO no_left ; Now check for an obstacle on the right side
CALL pulseleft ; Pulse the left IR LED at 38 KHz for 600 microseconds
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_left ; IR detector didn't sense reflection with Left LED on
CALL delayloop ; Wait 600 microseconds
BTFSS IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_left ; Now check for an obstacle on the right side
CALL pulseleft ; Pulse the left IR LED at 38 KHz for 600 microseconds
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20005
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_left ; IR detector didn't sense reflection with Left LED on
BSF LEFTDETECT ; Turn on the left Visible LED
GOTO do_right ;
no_left ; No obstacle to the left, so
BCF LEFTDETECT ; Turn off the left visible LED
do_right
CALL pulseright ; Pulse the right IR LED at 38 KHz for 600 microseconds
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_right ; IR detector didn't sense reflection with Right LED on
CALL delayloop ; Wait 600 microseconds
BTFSS IRDETECT ; Read the Sharp Module. Skip next inst. if no detection
(0=detect)
GOTO no_right ; Now check for an obstacle on the left side
CALL pulseright ; Pulse the right IR LED at 38 KHz for 600 microseconds
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_right ; IR detector didn't sense reflection with Right LED on
CALL delayloop ; Wait 600 microseconds
BTFSS IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_right ; Now check for an obstacle on the left side
CALL pulseright ; Pulse the right IR LED at 38 KHz for 600 microseconds
BTFSC IRDETECT ; Read the Sharp Module. Skip next inst. if detection
(0=detect)
GOTO no_right ; IR detector didn't sense reflection with Right LED on
BSF RIGHTDETECT ; Turn on the left Visible LED
GOTO main
no_right ; No obstacle to the right, so
BCF RIGHTDETECT ; Turn off the right visible LED
GOTO main
delayloop ;------------------------
MOVLW D'195' ;
MOVWF WAIT ; This creates a 600 microsecond delay
loop ;
NOP ;
DECFSZ WAIT,F ;
goto loop ;
RETLW 0 ;------------------------
pulseleft ;------------------------
MOVLW D'24' ;
MOVWF WAIT ; Pulses the left IR led at 38 KHz
leloop BSF LEFTLED ; for 600 microseconds
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
BCF LEFTLED ;
NOP ;
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20006
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
DECFSZ WAIT,F ;
GOTO leloop ;
RETLW 0 ;------------------------
pulseright ;------------------------
MOVLW D'24' ;
MOVWF WAIT ; Pulses the right IR led
riloop BSF RIGHTLED ; for 600 microseconds
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
BCF RIGHTLED ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
NOP ;
DECFSZ WAIT,F ;
GOTO riloop ;
RETLW 0 ;------------------------
end
WINNIPEG AREA ROBOTICS SOCIETY MARCH 22, 20007
APPENDIX B
Hex Listing
:1000000025000A0C0600000C02000604A6044604A3
:1000100086046606130A26060E0A100AA60486043B
:10002000A6058605090A3E092606240A3809260778
:10003000240A3E092606240A38092607240A3E090E
:100040002606240AA605250AA6045A092606360A03
:1000500038092607360A5A092606360A38092607B5
:10006000360A5A092606360A8605090A8604090A46
:10007000C30C29000000E9023A0A0008180C290004
:100080000605000000000000000000000000000065
:100090000000000000000000060400000000000056
:1000A0000000000000000000000000000000E90265
:1000B000400A0008180C2900460500000000000056
:1000C0000000000000000000000000000000000030
:1000D00046040000000000000000000000000000D6
:0C00E000000000000000E9025C0A0008BB
:021FFE00EA0FE8
:00000001FF
1 2 3 4
A
B
C
D
4321
D
C
B
A
1
Winnipeg Area Robotics Society
1
WARS002 0
21-Mar-2000 22:22:55
Title
Size: Number:
Date:Drawn By: Darren Sawicz
Revision:
Sheet ofTime:
Letter
DPRG IR Proximity Detector
Meetings at U of M
Saint John's College
Room 118
92 Dysart Road
VDD
1
GP5/OSC1
2
GP4/OSC2
3
GP3//MCLR
4
GP2/T0CKI
5GP1
6GP0
7VSS
8
U1
PIC12C509
V
CC
2
V
ou
t
1
G
N
D
3
Det1
IR DETECTOR MODULE
R1
330
R2
330
D1
Red LED
D2
Red LED
R3
1k
R4
1k
D3
IR LED
D4
IR LED
Left Detect
Right Detect
/INHIBIT
+5V
+5V
1 2 3 4 5
JP1
5 Pin Header
+5V
/INHIBIT
Left Detect
Right Detect
Theory of Operation
The signals available at the header pins are:
Parts List
APPENDIX A - Source Code
APPENDIX B - Hex Listing
SCHEMATIC
本文档为【单片机红外壁障传感器制作】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。