Saturday, January 5, 2013

MSP430 IR Remote Control

In my post about giving up on using the FT232R for an IR transmitter, I mentioned using a MSP430 as a possible alternative. With the bug in my head, I needed to get this IR transmitter working and the MSP430 did it for me. Here is a list of the key things that helped me get it working with the MSP430G2553 microcontroller:

  • The MSP430G2553 had pre-calibrated data built in for setting the DCO (digitally controlled oscillator) frequency to an accurate 1, 8, 12, or 16 MHz. Using the 16 MHz settings made it very simple to get a very accurate 38 kHz IR frequency (or 57.6 kHz, or whatever), with moderately adjustable duty cycle. I'm using two compares on a single, up-count timer, each compare with its own ISR, for toggling the IR LED. That probably wasn't the right way to do PWM with the timer but it worked. I used the second timer to have the IR LED toggling at its rate for the right amount of time or to stay off for the right amount of time.
  • I knew what to transmit thanks to a few websites and writings:
    • http://www.hifi-remote.com/forums/dload.php?action=file&file_id=6996
      • This is a pdf describing IRP (infrared protocol) notation and how a IR signal is contructed  to send to a device. Click the download button to get the pdf. Very very helpful.
    • http://www.hifi-remote.com/jp1/lookup/
      • Universal remote controls use codes to program the remote to work with your equipment. This site lets you look up a code for a remote to find out what IRP protocol it's using and what EFC (extended function codes) goes to what function (power, channel+, etc.). You can also look up protocols and EFCs by the brand and type of device you want to control. You may get a big list and have to try more than one (just like when you program a real universal remote control).
    • http://www.hifi-remote.com/johnsfine/DecodeIR.html
      • This site lists the IRP for a ton of protocols you might find using the above lookup site or by examining an IR signal. Critical for getting the signal right. Common protocols you may have heard of include NEC1 and NEC2. My VCR used a JVC protocol.
    • http://www.hifi-remote.com/ofa/xref.shtml
      • This page translates EFCs to OBCs (original button codes). EFCs are for programming universal remotes. OBCs are for sending to the device itself. This was a major hangup for me when trying to figure out why I couldn't turn my VCR on. I was trying to send the EFC value, not the OBC value. Doh! I figured this out when I finally pulled out a TSOP38238 IR receiver, made by Vishay, to sanity check my transmitted signal and compare it to what my remote control was sending.
  • My poor-man's oscilloscope was a great help. I cut an audio cable so it had a 1/8" plug for plugging into my laptop's mic jack and bare wires on the other end. Audacity recorded the signal. I set my mic input to record at 192 kHz, giving a bandwidth of over 90 kHz. Mic inputs are AC coupled and I was measuring DC signals. This isn't a big deal for measuring the 38 kHz signal, that goes through without a problem. But when a DC value is held for a relatively long period of time, you can see the value go back to zero with some time constant (that I should have measured). Knowing what I was looking at and with the fast signals I was measuring, this wasn't a problem at all. I didn't need to measure voltages, just short time intervals. This worked for that. This is what also made me suspicious of my FT232R signal.
After figuring out the IRP for my JVC VCR, the device and function code I needed to send to it, and getting the IR frequency right, it worked like a charm!

Looking back now, when I gave up on using the FT232R, I didn't have the right data sent over IR. Maybe I'll go back and try again but, honestly, I don't think it is worth it. Watching a red LED with the FT232R flicker when it was supposed to stay at a steady, dim intensity doesn't give me a lot of hope that correcting that will solve the problem.

Some things that would make the MSP430 an even better remote control (that I may or may not do):
  • The Launchpad allows your computer interface with the MSP430 device over a serial interface. Over the serial interface, one would give the MSP430 the IRP information and then give it the data to send using that protocol. Or have many common protocols preprogrammed and just tell it which one and the data. Then you could write a program that emulates a universal remote control. Press a button on the program, the launchpad transmits the corresponding signal.
  • Include the IR transmitter and a TSOP38238 (or others for other frequencies) in a launchpad booster pack for a transmitter/receiver/learner device.
  • Maybe turn it into a TV-B-Gone type device.
All of this was inspired by the USB Infrared Toy by Dangerous Prototypes. I didn't really feel like buying one and they ignore IRP for their sampling mode, which I think makes more sense for remote button presses. Using the information linked above, there wouldn't be a need to record a signal before being able to transmit it. And if you know the protocol, just giving the MSP430 the data to send using that protocol should be sufficient.