I built this MCU based infrared repeater to allow me to control my A/V equipment that is behind a wall. The system is very simple.
Power is supplied to CON1 from a cheap Alcatel phone charger that outputs stabilized 12V, passes through reverse voltage protection diode to IC1 that outputs 5V VCC. Atmel AVR microcontroller runs from 4MHz ceramic resonator Y1, C3+R1 form a reset circuit. Infrared detector (TSOP1738 in my case) is connected to INT0 input, C1+R2 are for detector power filtering. There is a green indicator LED D2 connected to PB2, and two 940nm infrared leds D1,D3 connected to PB3 via driver transistor Q1. R6 limits current through IR leds, and C2 is good to have if the IR diodes are at the end of long wires. I have separate board with R5,Q1,D1,D3,R6,C2 at the end of cable, but you may choose to build the whole circuit on single board and lengthen the wire that goes to detector.
The code is short and sweet, after initialization the interrupt handler takes care of everything - while the detector output is low, indicator led stays lit and a 39.2kHz burst of infrared is emitted from IR diodes.
; infrared repeater with AVR 90S2313 microcontroller ; Madis Kaal, firstname.lastname@example.org .include "2313def.inc" ; port b pins ; .equ LED = 2 ; indicator led (active low) .equ IR_OUT = 3 ; infrared led driver (active high) ; port d pins ; .equ IR_IN = 2 ; infrared detector (active low) .set GIE = 7 ; interrupt enable bit in sreg .def acc = R16 .def cnt = R17 .CSEG .org 0 rjmp RESET ; Reset Handler rjmp EXT_INT0 ; IRQ0 Handler rjmp EXT_INT1 ; IRQ1 Handler rjmp TIM_CAPT1 ; Timer1 Capture Handler rjmp TIM_COMP1 ; Timer1 Compare Handler rjmp TIM_OVF1 ; Timer1 Overflow Handler rjmp TIM_OVF0 ; Timer0 Overflow Handler rjmp UART_RXC ; UART RX Complete Handler rjmp UART_DRE ; UDR Empty Handler rjmp UART_TXC ; UART TX Complete Handler rjmp ANA_COMP ; Analog Comparator Handler EXT_INT1: TIM_CAPT1: TIM_COMP1: TIM_OVF0: UART_RXC: TIM_OVF1: UART_DRE: UART_TXC: ANA_COMP: reti ; ignore interrupts that we dont need ;------------------------------------------ ; invoked when IR receiver output goes low ; ; activates indicator led, outputs burst of infrared until ; the detector output goes inactive again, then turns off ; the indicator led ; EXT_INT0: push R0 in R0,SREG cbi portb,LED ; output 39.2khz burst of ir while the input stays low ; ; 12.75uS ; ________ ; ___| |_______| ; irloop: sbi portb,IR_OUT ; IR led on rcall wait125 wdr ; kick the watchdog nop nop cbi portb,IR_OUT ; IR led off rcall wait125 sbis pind,IR_IN ; check the detector again rjmp irloop ; and keep flashing the led if still active sbi portb,LED ; indicator off out SREG,R0 ; recover state pop R0 reti wait125: ldi cnt,13 w1: dec cnt brne w1 ret RESET: ldi acc,0xdf ; set stack to end of ram out SPL,acc ; set I/O directions ; d2 input, rest of d is output ; b is output ldi acc,0x04 out portb,acc ldi acc,0xfb out ddrd,acc ldi acc,0xff out ddrb,acc ; enable watchdog ldi acc,0x1b out wdtcr,acc ; enable INT0 interrupts on falling edge ldi acc,0x42 out mcucr,acc ldi acc,0x40 out gimsk,acc bset GIE ; enable interrupts ; loop and kick the watchdog, waiting for interrupts to ; happen mainloop: wdr rjmp mainloop
Copyright © Madis Kaal 2000-