Showing posts with label infra red. Show all posts
Showing posts with label infra red. Show all posts

Tuesday, January 26, 2010

Main(s) is a Pain

NOTE: Windows Live Write S*CKS! WYSINWYG (what you see is NOT what you get). I used to type out something, and land up with some completely vague formatting! It took me a while to fix this.

* * * * * * * * * * * *

Now who would have thought
that the powerline would be fraught
with difficulties such as these –
from an imbalanced phase
to noisy EMI
it all just seems a maze
to me!

I want to send data, I wish to communicate
betwixt and between two PIC micros -
in short, that's the scene.
How shall I do it? Well that's the debate!

The TDA5051’s the answer to my problems,
but that darn piece of silicon’s elusive, I must say!
I’ve searched Lamington Road, I’ve scoured Lajpat Rai;
drat! I can’t source it! The only recourse left is to pray.

With God on my side, and inspiration high
I sat down with paper and pen.
I scribbled here, pondered there, calculated in mid-air.
Schematics in hand, my proof-of-concept is ready,
I’m gonna TX some 1's and 0's now, Amen!

 

* * * * * * * * * * *

 

WHY in the name of the good Lord would I compose such a poem? The current project that I’m working on entails transferring packets of data bi-directionally from my laptop to an appliance using nothing but the power line that both are connected to. Communication through the power lines - Power Line Communication. PLC.

So why compose atrocious ‘electro-poetry’? People do all sorts of things in frustration. And why write such rhymes? A poet-friend of mine would chide me for writing such stuff. In my defence, my poem composing skills are not much better than a kindergartener; to me, lines in a poem must rhyme (heck, that’s how I used to remember them in KG!).

Anyway, let us set aside my inanity for the time being and note that the power line in India carries 230V RMS at 50Hz (it’s 120V RMS at 60Hz in the US). Devices using the X10 scheme wait for zero crossings of the AC signal to send data. The idea is that when the instantaneous voltage is 0V, there is the least amount of spurious ‘external signal’ on the power line. One bit, modulated by a 120kHz carrier, is sent every zero crossing. Only a single bit at a time can be transmitted, because, understandably, the time for which AC is 0V or near-about, is very short.

Now while this method works (its been implemented in several home automation devices), data rates are abysmally slow (50bps for 50Hz systems, and 60bps for 60Hz systems), and the maximum number of controllable devices is low. There does exist an extended X10 protocol which increases the number of devices supported, but the lack of speed still remains an issue.

A workaround (it isn’t really a workaround, per se; more like the obvious solution :-P) is to send data not just at zero crossings, but at all times. By modulating the data at the TX end and then demodulating it at the receiver, and adding some good error checking schemes, higher data rates can be achieved. The TDA5051 works just like this.

The TDA5051 is a 600/1200bps, ASK, half-duplex PLC modem. It is a complete solution, with an integrated analog front-end, a BPF, a decoder, and a communication module for connection with a supervisor (a microcontroller, or a PC for instance). Only a few additional external components are required.

This is all very nice and dandy, but for the misfortune that I just can’t seem to get my hands (well, tweezers actually – it’s a small chip) on a TDA5051.

So how did I get around the problem of the hard-to-find TDA chip? Simple – I rolled my own modem :-D . OK, OK, I’ll come clean. I haven’t yet built it completely, but I’m working on it. The basic testing that I’ve done seems most promising.

 

The steps involved at the TX end are:  

PLC tx TX side block diagram

*        generation of a data carrier (38kHz PWM from a PIC16F628A)..…1 38kHz PWM

38kHz PWM @ 18.5% duty, from the CCP module of a ‘628. In retrospect, I should probably have used a 50% duty cycle.

 

  

*         the data itself (300bps UART data) …..2 UART   

The graph is annotated. UARTs idle high; start-bit is low; data is streamed LSB-first; stop-bit is high, followed by idle-high.

 

 

*       modulating the carrier using the data (gating using NAND logic)…..3 Data

The final Boolean output is

(UART) AND (PWM)

 

 

*       coupling the modulated signal to the power transformer (through a 0.1uf ceramic)…..4 xfrmer

Waveform on the mains side of the transformer; secondary side is loaded with an LM317-based power supply. The waveform is probably not sinusoidal due to the 18.5% PWM duty.  

 

 data comparePWM compare
Left: raw data and its modulated inverse, juxtaposed for comparison
Right:
38kHz PWM and the transformer output viewed with the same timebase - 20us

 HardwareThe test setup

 

 

At the RX side (test data and pics will be up soon):

 plc rx

RX side block diagram

*         a transformer steps down the voltage…..5

*         a high pass filter removes 50Hz mains…..6

*         this is fed to a squaring circuit (made by NAND logic)…..7

*         the squarer drives an IR LED…..8

*         38kHz bursts are beamed at a TSOP1738 which demodulates the carrier…..9

*         the data is then fed to a microcontroller for further processing…..10

 

Using a TSOP1738 IR detector for demodulation – I admit that’s pretty smart even by my standards :-P I bet the chaps at Vishay never intended the TSOP to be used like this :-D

Monday, November 17, 2008

My वायरलेस प्रेसेंटर


Wow! Hindi transliteration on blogspot! That's an interesting feature! :-) Useless, but interesting, nonetheless.

Just a small point to note: I'm typing these first few lines from 15 feet away, using my wireless presenter. (Big smile :-) )

Naturally, you scoff, "How can you do that? Oh! You have a wireless keyboard! Umm, hang on a sec! You said वायरलेस प्रेसेंटर . How are you typing text?" (Bigger, mysterious smile :-) )

Well, I made my own Wireless Presenter-cum-Keyboard-cum-Mouse. (Biggest smile yet :-) And, in Sheldon's words - TBBTS02E07 - Muaa-hah-hah). Here are the details.

This project originally started off beacuse I used to get exceedingly irritated with the abysmal lack of dexterity afforded by standard keyboards. This lack was / is felt, most painfully, when getting fragged in a fast-paced game of CoD. "I need my grenade! Where the hell is the 'G' key. Dratted keyboard." My rifle! My rifle! '1'! '1'! '1'. Shots fired! Duck! 'Q'! 'Q'! 'Qqqqqqq....!'. I'm sure you get the point. I also do a lot of 3D modelling in AutoCAD, and image editing in Photoshop. My mouse, which would ordinarily be considered reasonably good, fares pathetically at this zoom-in-zoom-out-click-to-do-this-tap-to-do-that kind of stuff. Wouldn't just be great to have an additional fully customizeable keyboard? It would have a zoom slider, a wonderfully sexy scroll wheel (much like the iPod's), multiple buttons, and special keys which have several keyboard buttons bound to one (so to press 'Ctrl-Alt-Del', I'd just need to press one key on this keyboard). The mouse would be integrated into this device, and would have similar useful features.

I can, of course, buy such a device, but that would mean shelling out absurd quantities of cash - something that I don't have much of! Making one would mean I'd save potloads of money. I have been reasonably successful; hence this post.

So far, I've only made a Wireless Presenter, but this same device can be adapted to do all the stuff I mentioned above. A little effort, some pain, and a couple of milk-and-cookies-filled all-nighters are all that are necessary.

Without going into the overly-technical details of the device I'll tell you what the system consists of:
- a full speed USB PICmicro (the 18F2550) (free from Microchip);
- a TSOP1738 IR detector (Rs.10);
- a cheap roadside SONY TV remote (Rs. 60);
- a USB cable (free from an old mouse), crystal (Rs. 4), capacitors (Rs. 4).

The SONY remote sends IR data to the TSOP, which is connected to the '2550. The PIC decodes the IR signals (which are in SONY's SIRC format). The '2550 then sends this data through USB to the PC. Now, I've programmed the PIC to enumerate as a USB keyboard-mouse combo device. So my PC, for all practical purposes, thinks that it has a second keyboard and mouse. I have mapped certain keys of my laptop keyboard to keys on the remote. So pressing the 'Program +' key on the remote, is equivalent to pressing the 'Right Arrow' key on my keyboard. Pressing the 'Power' button on the remote is like pressing 'Esc' on the keyboard.

This is the nice thing about putting software (firmware) onto a microcontroller - you can fiddle around, and map virtually any key combination to any remote key!

I use this device to control MS Powerpoint slides from upto 30 feet away. I've mapped most of the Powerpoint keyboard shortcuts to buttons on the remote. The 'Contrast' button is 'F5', the 'Program Jump' button is 'Enter', and so on.

For a full listing of the source code go here .

I've made this using a PIC, but if you get the logic and code right, I'm pretty sure you could use any processor.

Future modifications include adding an accelerometer to provide intuitive mouse support (right now I'm pressing 'Mute' and the 'Volume / Program +/-' buttons for mouse-like action). Maybe I'll even port the whole thing to RF (Zigbee, or MiWi); it's running IR now - the great thing about IR is that its laughably cheap and easy! RF would involve additional cost and effort (protocols, and other crazinesses). For now, this is good. Anyway, in the beginning you had asked (well, alright, I had made you ask) how I was typing out text using my वायरलेस प्रेसेंटर.....I think you have the answer now.

I will be, at some point in time, making the gaming device I talked about earlier, but until then, I'll have to amuse myself with this :-) If anyone is planning on building something similar drop me a mail - I'll be glad to help.

Visitors