Saturday, December 15, 2012

Infrared "Sonic Screwdriver"


PIC > AVR
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.

Infrared
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.


Transmitting
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.

Video

Monday, December 3, 2012

Every hard drive is dead!

I have a nearly working version that will be in my next post. Nooooope. My next post will be about another failing hard drive.

In a separate computer, so that rules out power supply or SATA controller problems.

If you ever see me madly making backups to every device I can get my hands on, then you'll know it's because every hard drive within 1km of me is dying. Maybe I'm highly magnetized :(..... doesn't explain the corrupted data on the SSD.

Sonic Screwdriver

Update!
I'm overdue for an update! Around Septemberish I made my furthest progress. It goes something like this: Attach drill to distributor, run drill, distributor signal read by microcontroller. Then, the microntroller will 1. Spark Coil at when the distributor is at TDC and 2. Send timing data over USART. Using a MAX232 chip and serial>USB converter I can read that USART data with a C# program and display the rpm!

It worked fairly well except for each spark semi-regularly resetting the mc! I think that's just a matter of high voltage messing up what would be a clean power supply.

Delays, Distractions and the evil Computer Demon
I haven't been able to work on it since. Uni work has been time consuming and finding a big free block of time has been difficult. As awesome as this stuff is, there's usually something more important or better to do! In addition I killed my dragon programmer, my laptop has been sent for repair twice (still waiting for it) AND 3 hard drives died on my file server in different ways (WTF??!!). I <3 backups="" br="">
The Plan
I think I've gotten as far as I can without a running engine to play with, so starting early next year I will be directly driving the coils and injectors on my car. It means the car will be off the road while I figure all this out, but it should work out well with the engine swap and new clutch to be fitted at the same time.

Sonic Screwdriver
In the meantime I'm working on another project. You know those cool toy sonic screwdrivers that light up and make sound effects?
Wouldn't it be cool if you could use it to control any device with an infrared sensor? A TV or airconditioner or pretty much anything with a remote control. My plan is to replace the innards with electronics that can record and playback an infrared signal. Yes, you can buy something like this already from thinkgeek but holy crap it's expensive and it's way more fun to build it yourself! I have a nearly working version that will be in my next post.