The purpose of the device is to input a signal from an infrared remote controller and retransmit it through a wire to another infrared LED to control a remote device. This way the IR receiver and the controlled device can be separated, say, by a wall or other obstacle. Another application of this device includes increasing the range of remote controllers by placing the retransmitter between the user and a controlled device.
All IR remote controllers share one common feature: they generate 0-1 codes (commands) which modulate a carrier frequency. Most of modern controllers use 38 KHz carrier frequency, however it can vary in two ranges: 30-50 KHz and 110-120 KHz. The first range covers most remote controllers/receivers today, whereas the second one is used by some new satellite receivers.
The IR signals from a remote controller are received by a special 3-pin IR receiver chip. Such chips use a sophisticated digital signal processing which is optimized for a single carrier frequency only. When it receives the signal, the carrier frequency is filtered out and the output consists just of the device control codes. In order to retransmit the codes, one needs to restore the carrier frequency.
In order to make the repeater universal, the IR receiver chips for various carrier frequencies must be replaceable. Moreover, in order to restore the carrier, it must be known with a high accuracy. In our device the carrier frequency is measured with a resolution of 125 ns and remembered. The repeater restores the carrier frequency of the primary controller and can be tuned to generate carrier frequencies in the range of 30 - 120 KHz. This makes it compatible with virtually any IR controller on the market. Most similar projects published on the Internet (some of them are referenced below) work only with a fixed carrier frequency of 38 KHz.
The repeater is based on MSP430F2101 microcontroller and operates in two modes. In the default retransmission mode the signal received by the IR receiver IR1 is used to turn on/off the carrier frequency generated by PWM (with duty cycle 50%) at channel 0 of Timer_A. This signal comes to the gate of MOSFET Q4 that, in turn, controls the emitting IR LEDS D2 and D3. Two emitting IR diodes are used to extend the working range, which is about 15' (~5 meters). The retransmission is indicated by a green LED for controlling purposes.
In the setup mode the device measures the carrier frequency of the the primary controller. This mode is selected by pressing the button S1, which leads to ignoring the output signals of IR1. To measure the carrier frequency of the primary remote controller, it should be put close (1-2") to the IR sensing diode D1. This diode works as a receiver of the carrier frequency. Its signals are amplified by the opamp IC1 and arrive to the CCP module based on channel 0 if Timer_A of the microcontroller. The timer captures two timestamps corresponding to the two consecutive rising edges of the carrier frequency. The timer runs from the microcontroller clock frequency of 8 MHz, so the timestamps are accurate up to 125 ns. The measured carrier period is then converted into the frequency, which is displayed in KHz on a 3-digit LED display. The carrier frequency in the range 30-50 KHz is displayed with 1 fractional digit, whereas the frequencies above 100 KHz are displayed as an integer. Upon releasing the button S1 the device remembers the latest measured carrier frequency and returns back to the retransmission mode. The measured frequency will then be reproduced.
Schematic | PCB top | PCB back | ||
The MOSFETs Q1 - Q3 are used for multiplexing the LED display in the setup with the display refreshing frequency of about 100 Hz. The display is turned off in the retransmission mode. The device is powered from 12 VDC and consumes about 50mA in average. The voltage regulator IC2 provides stable 3.6 V voltage for powering the microcontroller and other electronics. By using a different input voltage at the power jack J1 one should adjust R5 for the peak current through D2 and D3 of the order of 100 mA. This current determines the range of the device.
The circuit is assembled on a one-side PCB, which is designed to be embedded into Hammond enclosure, model 1591ATCL. The PCB is designed with a free version of Eagle software and is attached. The button below the 3-digit LED display (see the middle image) is for switching the modes. The 38-KHz IR receiver at the top left corner is mounted in a 3-pin receptacle for an operative replacement if needed (in case the remote controller generates a significantly different carrier frequency). The green LED right below it indicates reception of IR signal from the controller. The LED at the top edge is tuning the device as described above. The power is attached via a connector jack in the top right corner of PCB. The 4-pin connector header right below it is for connecting the emitting LEDs D2 and D3.
The microcontroller program is written in assembly language and is intended for compilation with the IAR IDE. The program begins with initializing the microcontroller I/O ports and timer, assigning pins P2.2 and P2.3 to Timer_A, and enabling falling edge interrupts at pin P2.1.
Initialization of the generated carrier frequency of 38 KHz is provided by setting the Timer_A upper counting bound of 104. This way the timer overflows every 104 / 8 = 13 microseconds, which corresponds to 1/2 of the default carrier period. Channel 1 of timer operates in output mode 4, which causes toggling the output at pin P2.3 every 13 μsec as the timer counter reaches the value 1. This leads to generating carrier frequency with a period of 2·13 = 26 μsec, corresponding to approximately 38 KHz.
The code has two interrupt service routines (ISR): one for processing the signals from the remote controller in the repeater mode and one for processing capture events of timer in the carrier frequency measurement mode. The first ISR is called whenever the button is not pressed and the receiver IR1 gets a signal from the remote controller. In this case the output of IR1 becomes low, so the interrupt is triggered by falling edges at P2.1. The ISR first enables the timer output (so that the carrier frequency appears at pin P2.3 and controls the emitting LEDs D2 and D4 via the MOSFET Q4) and turns on the green LED. After that the P2.1 pin is polished for the value change. As soon as the output signal of IR1 goes up again (which corresponds to the end of pulse from the remote controller), the timer output is disabled and green LED is turned off. This way the control signal from the remote controller modulates the carrier frequency.
The other ISR is called when the button is pressed and the output of the opamp changes from 0 to 1. The timestamp of this event (value of the timer counter) is captured by the CCP module of timer channel 0. After capturing the second timestamp, the difference between them (measured in the number of periods of the CPU clock) is proportional to the carrier period. This difference is further divided by 2, saved in variable period, and is used later to generate the half-periods of the carrier frequency as described above. After every second capture the value of period is converted into the carrier frequency for displaying. The computations are done by computeFreq routine according to the formula
freqKHz = 4000 / period
Since we display the lower carrier frequency with one decimal digit, it is more convenient for us to compute 10·freq, so the RHS of the formula becomes 40000 / period. Three higher-order digits of the obtained quotient are stored in variables digit1, digit2, and digit3 and are used for displaying the frequency, see below.
The main loop of the program basically implements a standard button debouncing algorithm based on a shift register. If the button was not pressed before and its state did not change now (at the time of checking the status), we perform a 64 msec delay before checking the button status again. At this time the device is in the frequency repeating mode and is controlled by pin P2.1 value change ISR.
If the button was not pressed before and its status is changed now, the device is switched to the frequency measurement mode. The interrupts from P2.1 are disabled and CCP module of channel 0 of timer is enabled. The main loop is reduced for some time to a subloop at label dispLp in the code. At each iteration of that subloop we throw one of the digits (digit1, digit2, or digit3) to the display via port P1 and display it for about 3 msec. This way the display refresh frequency is 3·3 = 9 msec, which is more that 100 Hz so no display flickering is noticeable. The value on display is not changed for 7 iteration of the subloop, so every frequency value is displayed for 7·9 = 63 msec. This is done to prevent fast display updates cause by frequent capture events.
If the button was pressed before and there is no button status change at the next checking, we continue to display the last measured carrier frequency. At this point the new captures are handled at the background by interrupts. Finally, if the button status is changed and the button is up now, we return back to the signal repeating mode by disabling the CCP interrupts and enabling the P2.1 interrupts. The display loop is not performed in this state and the display remains off. A flowchart of the entire algorithm is attached.
Last modified:Mon, Jan 23, 2023.