Saturday, December 15, 2012

Infrared "Sonic Screwdriver"

This is my first project using a PIC microcontroller and programmer. IMO it's not dramatically different than Atmel/AVR, but I did find it easier to use. MPLabX is pretty cool and I found switching between programming and debugging to be much faster and more reliable.

I did some research on infrared signals (heaps of googling) + played around with the remotes I have at home and found that for most consumer electronics most brands follow just a few common signal protocols. Even different protocols have similarities. The most important characteristics I found are that
  • Most signals are modulated at 38KHz with about a 33% duty cycle.
  • The 1's and 0's are represented by 2 different pulse lengths.
  • There can be a 3rd or 4th pulse length that are special bits used for signaling the beginning of data.
  • Some fluorescent lights give off a modulated infrared light that screws up everything!
Signal Data
I decided that trying to interpret each pulse length and then writing the appropriate bit into memory would be too tricky and not very "universal". Is the "1" pulse on my TV remote the same as the "1" pulse on my AC remote? Instead the microcontroller is running a 16bit timer and measuring the time passed before each bit flip. To transmit the signal it just has to flip between 1 and 0 when the timer value matches what was recorded earlier. The only downside is that this method needs more memory.

To actually read the signal I got a IR receiver. It's pretty cool. Just needs power, ground and a pull up on the signal out pin. It is pretty sensitive and doesn't seem to care what frequency the IR signal is modulated at. The signal output looks like this.
Power button on TV remote gives this signal.

The main differences between using an Infrared LED and a regular red LED are that firstly they require much more current and secondly you might not be using a current limiting series resistor! I tried it and it quickly became pretty dim (you can test it by looking through a camera since most will see IR light as blueish-white). Also the remote controls I opened up didn't have a series resistor.

I found the 2nd point pretty surprising, but it sort of makes sense because when the LED is "on" it's actually on just 33% of the time or whatever the PWM duty cycle is. Basically 33% duty cycle is 33% of the current it would normally draw. It's still much more current than usual, so i'm using an NPN transistor instead of connecting it directly to the microcontroller output pin. The output pin will switch on/off at the rate originally recorded from the remote. The last step is to modulate the signal at 38KHz. To do that the microcontroller is running a separate timer to generate a PWM signal at 38KHz with 67% duty cycle. I'm connecting it to the negative side of the LED (directly! which is probably not good!). The end result is the IR signal has a 33% modulation because when the PWM signal is low (33% of the time) the IR LED is on and when the signal is high (67% of the time) the IR LED is off.

What's left
To finish this I need to
  • Switch to a smaller microcontroller that fits inside body of the sonic screwdriver.
  • Have the uC write the signal data to flash memory instead of RAM.


No comments:

Post a Comment