The IR Widget Using pic12f629
Simple IR capture for multitasking operating systems
The IR Widget captures the infrared signals used by remote controls. It operates in a way that makes it compatible with modern multitasking operating systems. It is able to determine the carrier frequency and demodulate the carrier in the digital or analog domain. The captured information can be used to view, recognize or reproduce the signal. The hardware is designed to be as simple and low cost as possible. A PIC12F629 was used for development, but almost any PIC that uses the 12 or 14 bit instruction set could be used.
Limitations of simple IR capture circuits
The usual approach to low cost IR capture typically consists of an IR detector or demodulator module connected to a serial or parallel port. This can work quite well when the CPU is dedicated to servicing the port. It often performs poorly within a preemptive multitasking operating system. The OS is constantly servicing hardware interrupts even when the system is idle, so the IR capture is constantly interrupted. Disabling hardware interrupt handling is dangerous and may be prohibited by the OS. CPU usage is high when polling is used. Using the hardware interrupt capability of the port can greatly reduce CPU load, but interrupt latency may cause inaccurate results. Boosting thread priority may help, but results vary. Parallel and serial ports are becoming less common, and USB adapters do not work for these simple circuits.
Limitations of microcontroller based circuits
There are many DIY and commercial products that use a microcontroller to process the IR signal. These are typically intended for remote control rather than research. Many of them have only an IR demodulator, so they can not determine the carrier frequency or report precise timing. The data sent to the host computer may be in a format that does not allow reconstruction of the actual literal IR signal. The acquisition duration is often limited to a single key press of the remote, making capture of macros difficult or impossible.
A different approach to simple IR capture
The IR Widget solves these problems by using a microcontroller to process the IR signal without interruption and send the data to the PC using ordinary asynchronous serial transmission. This allows the OS to service the serial port with standard drivers and allows the use of USB to serial converters. Simple circuits built with 74HC series parts can also be used. The data is sent in real time and is in a format that allows reasonably precise reconstruction of the actual IR signal received.
An infrared detector module is used to allow the microcontroller to see every infrared pulse at close range. This allows for greatest detail and accuracy. An optional infrared demodulator module can also be used to allow for long range reception with less detail.
The circuit is powered from the serial port. USB to serial converters work well and their use is recommended.
Carrier frequency measurement
Infrared remotes typically use a carrier frequency of 30 to 60 kHz. The carrier is keyed full on and full off. Carrier on durations typically range from 400 microseconds to several milliseconds. Carrier off durations typically range from 400 microseconds to more than 100 milliseconds. The IR Widget requires minimum on and off durations of 300 microseconds. This ensures that there will be at least 3 consecutive 100 microsecond sample periods during the on and off states.
To measure the frequency of a pulsed carrier, a short gate time is required. An ordinary frequency counter with 1 second gate will not give an accurate reading. The frequency could be determined from the period of one cycle, but this would require a rather high resolution measurement for a precise reading.
The IR Widget counts the number of infrared pulses that occur within a 100 microsecond period. The count is sent to the PC at 115200 bps. This repeats every 100 microseconds. This is effectively a frequency counter with a 100 microsecond gate time.
A single sample period can not provide a precise frequency measurement. To calculate the carrier frequency with greater precision many sample periods are used. All the non-zero counts are summed excluding the first and last in a burst. As long as there are pulses of 300 microseconds or greater duration, there will be samples from periods where the carrier was on for the entire sample period. The frequency is simply the sum of the pulse counts divided by the sum of the period durations. The result is not exact, but is accurate enough to determine which of the common frequencies was used.
Pulse time measurement
Once the carrier frequency is know, the first and last sample periods of each burst can be evaluated to determine the duration of the carrier during those periods. The on duration is the count of pulses within the period multiplied by the duration of each pulse (reciprocal of the carrier frequency). The off duration is simply the period duration minus the on duration.
For more Detail: The IR Widget Using pic12f629
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
Current Project / Post can also be found using:
- ir pic12 code samples