languer
IR Beam Break Test Bed
by
languer
, 3rd December 2010 at 07:30 AM (2344 Views)
So we presented a simple IR receiver/emitter pair here. What can we do with this? How about an example of a test bed where we can determine whether an IR beam is broken.
To do this two microcontrollers are used to control the IR emitter and IR receiver independently. Operation is obtained by sending a known RS232 communication (single character - "beam" character) through the IR link. The known RS232 character is sent three times within 100msec. If the receiver fails to receive any transmission within 100msec, the IR link (beam) is considered broken and an LED indicator reports this condition. This may be a bit of an overkill for a basic beam break circuitry, but it provides very good results.
The original beam break circuitry was built using a single microcontroller as shown below.
But using separate microcontrollers for the emitter and receiver allows to use any type of separation between the two. The following pictures shows the connections between the microcontrollers and the IR emitter and receiver.
Code Description – Beam Break Test Bed:
The code for this basic beam break test bed was created using Oshonsoft Basic. This language is not as complete or provides as much functionality as others (e.g. CCS C), but it can be readily obtained and used.
The emitter code can be summarized as follows:
The receiver code can be summarized as follows:
- On power-up setup MCU for 40kHz PWM output on RB0,
- setup the SW UART for transmission at 1200bps on RB5,
- send RS232 “beam” character approximately every 33msec.
Code - Emitter:
- On power-up setup TMR1 for 100msec,
- setup the HW UART for reception at 1200bps on RB2,
- monitor HW UART for reception of RS232 character,
- monitor RS232 for “beam” character,
- sample every 100msec for RS232 “beam” character,
- if “beam” character was received within the 100msec, turn off LED (or keep off, if previously off),
- “beam” character was not received within the 100msec, turn on LED (or keep on, if previously on).
Code :'* PIC16F88 * IR Transmitter Test Bed *' 'Title: IR Transmitter 'Description: This program uses MCU to send an IR transmission. '>>>>>>>>>>>>>IR transmission is sent by "ANDing" an RS232 character and a 40kHz PWM. '>>>>>>>>>>>>>Transmission sent three times about every 100msec using the SW UART. 'Author: languer (2010) 'Pin Allocation: 'PIN# Main_Fn 'RA0 -> not used 'RA1 -> not used 'RA2 -> not used 'RA3 -> not used 'RA4 -> not used 'RA5 -> not used 'RA6 -> not used 'RA7 -> not used 'RB0 -> PWM Output 'RB1 -> not used 'RB2 -> not used 'RB3 -> not used 'RB4 -> not used 'RB5 -> RS232 IR output (SW_UART-RX) 'RB6 -> PGC - Programming clock 'RB7 -> PGD - Programming data 'Usage Information: 'Uses internal clock @ 8MHz 'IR Baud rate (SW UART): 600bps - 2400bps 'General Configuration 'for internal 8MHz Define CONF_WORD = 0x3f50 Define CONF_WORD_2 = 0x3ffc Define CLOCK_FREQUENCY = 8 OSCCON = 0x70 'define internal 8MHz clock 'Variable Declarations Const trisa1 = %11111111 Const trisb1 = %01011110 Symbol io_pwm = RB0 'PWM output Symbol io_tx232_ir = RB5 'rs-232 IR output 'wireless interface constants Const beam_char = 0xaa 'RS232 transmission character Dim _true As Bit Dim _false As Bit _true = True _false = False 'Main Program main: WaitMs 3000 Call init() While _true Serout io_tx232_ir, 1200, beam_char WaitMs 25 Wend End Proc init() AllDigital TRISA = trisa1 TRISB = trisb1 'pwm settings '>>>pwm period to 40kHz PR2 = 49 '>>>pwm duty cycle to 50% CCPR1L = 25 'using 8-bit mode (for 10-bit mode, 100 would be written to CCPR1L:CCP1CON<5:4>) '>>>pwm tmr2 prescaler 1:1 (for 40kHz) T2CON.T2CKPS1 = 0 T2CON.T2CKPS0 = 0 '>>>pwm tmr2 enable T2CON.TMR2ON = 1 '>>>pwm enable CCP1CON.CCP1M3 = 1 CCP1CON.CCP1M2 = 1 WaitMs 1000 End Proc
Code - Receiver:
Code :'* PIC16F88 * IR Receiver Test Bed *' 'Title: IR Receiver 'Description: This program uses MCU to detect an IR transmission. IR transmission is received by IR module, inverted, and then received by HW UART. 'Author: languer (2010) 'Pin Allocation: 'PIN# Main_Fn 'RA0 -> not used 'RA1 -> not used 'RA2 -> not used 'RA3 -> not used 'RA4 -> not used 'RA5 -> not used 'RA6 -> not used 'RA7 -> not used 'RB0 -> LED Output 'RB1 -> not used 'RB2 -> RS232 IR input (HW_UART-RX) 'RB3 -> not used 'RB4 -> not used 'RB5 -> not used 'RB6 -> PGC - Programming clock 'RB7 -> PGD - Programming data 'Usage Information: 'Uses internal clock @ 8MHz 'IR Baud rate (HW UART): 1200bps 'IR receiver idles "high", active "low" 'Version Info: 'v1 '->RS-232 IR receive 'General Configuration 'for internal 8MHz Define CONF_WORD = 0x3f50 Define CONF_WORD_2 = 0x3ffc Define CLOCK_FREQUENCY = 8 OSCCON = 0x70 'define internal 8MHz clock 'Variable Declarations Const trisa1 = %11111111 Const trisb1 = %01011110 Symbol io_led = RB0 'LED output Symbol io_rx232_ir = RB2 'rs-232 IR input 'wireless interface constants Const beam_char = 0xaa 'RS232 transmission character Const tmr1h_preload = 0x3c 'Timer1 preload for 100msec tick rate Const tmr1l_preload = 0xb1 'Timer1 preload for 100msec tick rate Dim _sample_received As Bit Dim _true As Bit Dim _false As Bit _true = True _false = False 'Main Program main: WaitMs 1000 _sample_received = 0 Call init() 'hwuart setup Hseropen 1200 'preload tmr1 for 100msec tick rate TMR1H = tmr1h_preload TMR1L = tmr1l_preload 'enable tmr1 T1CON.TMR1ON = 1 'enable interrupts INTCON.GIE = 1 INTCON.PEIE = 1 PIE1.TMR1IE = 1 PIE1.RCIE = 1 Dim _char As Byte While _true Wend End Proc init() AllDigital TRISA = trisa1 TRISB = trisb1 'tmr1 settings T1CON.TMR1CS = 0 'tmr1 from internal source 'tmr1 prescale to div-by-4 T1CON.T1CKPS1 = 1 T1CON.T1CKPS0 = 0 Low io_led WaitMs 100 High io_led WaitMs 100 Low io_led WaitMs 1000 End Proc On Interrupt 'for tmr1 overflow If PIR1.TMR1IF Then 'preload tmr1 for 100msec tick rate TMR1H = tmr1h_preload TMR1L = tmr1l_preload If _sample_received Then Low io_led Else High io_led Endif _sample_received = 0 PIR1.TMR1IF = 0 Endif 'for hwuart character in buffer If PIR1.RCIF Then Dim _char As Byte Hserget _char If _char = beam_char Then _sample_received = 1 Else _sample_received = 0 Endif PIR1.RCIF = 0 Endif Resume



Email Blog Entry