Using a Stamp to decode Sony IR signals
Here's an example of a Sony IR signal after it's been demodulated by the IR
detector module. It consists of a start bit 2200 usec long, followed by 15
data bits. Between each bit is a 550 usec pause. A "1" bit is 1100 usec long,
and a "0" bit is 550usec long. After the last bit is sent, there is a delay
of 23,000 usec (23 msec), and the sequence is repeated as long as the button
is held down.
____ __ _ _ _ __ __ __ _ _ __ _ __ __ _ __
___| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |___
Start 1 0 0 0 1 1 1 0 0 1 0 1 1 0 1
Normally it is not necessary to look at all the bits, because some are used
to denote what kind of device the code is for: TV, VCR, or whatever.
The Stamp (at least the Stamp 1) isn't fast enough to do conditional looping
or compares on the fly, so some software tricks are used to speed things up.
For instance, there is only 550 usec after the start bit before the first
data bit comes through. There isn't enough time for the pulsin command to
measure the pulse and the conditional jump, so we wait 20 msec after a start
pulse is detected, skipping all of the follwing data, until just before the
next start pulse comes around again. The next bit to be read is the start
bit of the second pulse stream, which is discarded.
Now the pulse widths of the next 7 bits are stored in 7 variables (the
remaining 8 bits in the pulse stream are ignored).The Stamp can now build
up a data byte based on the width of the data pulses.
Here's the Sony IR receive code, with a little more explaination:
_____________________________________________________________________
main: pulsin ir,0,w0 'wait for valid start bit
if w0 < 200 then main 'valid start bit is > 200
'Wait until pulse longer than 200x10 usec (2 msec.) is received.
'This indicates start of command word
pause 20 'skip 1st data set
'Stamp is too slow to get data bits immediately after start bit
'so wait until next start bit comes
pulsin ir,0,b0 'wait for 2nd start bit
pulsin ir,0,b1
pulsin ir,0,b2 'read each data bit.
pulsin ir,0,b3 'use in-line code for speed.
pulsin ir,0,b4 'loop is too slow.
pulsin ir,0,b5
pulsin ir,0,b6
pulsin ir,0,b7
'record bit times for seven bits, Stamp is too slow to decode bits
'so we'll do it later
bit0=b1/96 'extract LSB
bit1=b2/96 '(each data bit is the MSB
bit2=b3/96 'of the pulse width)
bit3=b4/96
bit4=b5/96
bit5=b6/96
bit6=b7/96 'extract MSB
bit7=0
'Now build up command from bit times, bit is 1 if time is greater than
'96x10usec (=.96 msec), otherwise it's 0
'Resulting command is in b0; you could put a DEBUG b0 statement here to
'see what codes correspond to the various remote buttons.
______________________________________________________________________
Try http://falcon.arts.cornell.edu/~dnegro/IR/
Theres a lot of IR stuff there including Sony, plus programs to download.
Look under "Remote Cotrol Table" for descriptions of various IR remote
systems.
               (
geocities.com/siliconvalley/park)                   (
geocities.com/siliconvalley)