PUTTING THE SPOTLIGHT ON BASIC STAMP PROJECTS, HINTS & TIPS
■ BY JON WILLIAMS
CONTROL FROM THE COUCH —
Some time back, I wrote about being a single guy, drinking milk right out of
the carton, and having a bunch of IR remotes next to my favorite easy chair.
Well … I'm still single, still drinking milk right from the carton and — like
every real man — still loving my remotes! That earlier article had to do with
decoding the Sony IR Control Systems (SIRCS) protocol with a BASIC Stamp.
With the SX and SX/B I think it's time to revisit SIRCS decoding and even
couple it with serial I/O so that we can enable dual-mode control (IR plus
serial) or have the ability to use our project as an IR-to-serial translator.
SIRCS PROTOCOL REVIEW
The SIRCS protocol uses pulse-width encoding transmitted over a modulated IR carrier. To get the signal from
an IR beam into the SX, we can use a standard demodulator
like the Panasonic PNA4602M. The output from the
PNA4602M is a low-going pulse stream as shown in Figure 1.
Many consumer electronics devices use the 12 bit
SIRCS protocol and since this version is so commonplace,
it is what we will work with here. The stream starts with
a 2.4 millisecond start bit which is followed by 12 data
bits — sent LSB first — that contains seven bits for the
command (channel number, volume control, etc.) and five
bits for the device (e.g., TV, VCR, camera). The stream
shown in Figure 1 (%00001_0001001) corresponds to
pressing the zero key on my television remote.
Decoding the SIRCS stream is actually quite easy.
We start by watching for a low-going edge on the detector
input pin and measuring the period that this pulse stays
low. If the pulse is about 2.4 milliseconds, we have a valid
start bit and can drop into a loop to measure and decode
the following 12 data bits. A "1" bit has a width of 1.2
milliseconds and a "0" bit has a width of 0.6 milliseconds.
Each pulse is padded with a 0.6 millisecond dead space
which gives us a lot of time to take care of any inter-bit
■ FIGURE 1. SIRCS Protocol.
SIRCS DECODING: SX/B STYLE
For programs that don't use interrupts and can tolerate
being "blocked" until an SIRCS code is received, the
following function takes care of the grunt work for us
and even splits the device (five bits) and command (seven
bits) codes into separate bytes within the same word:
pWidth VAR tmpB1
tIdx VAR tmpB2
irWork VAR tmpW1
pWidth = GET_IR_PULSE
LOOP UNTIL pWidth > 216
irWork = 0
FOR tIdx = 0 TO 11
irWork = irWork >> 1
pWidth = GET_IR_PULSE
IF pWidth > 108 THEN
irWork.11 = 1
MOVB C, irWork_LSB.7
You'll see that within the function I've aliased my
temporary variables to make the code easier to read. With
SX/B 2.0, we could use locals, but I tend not to do this for
simple programs that have plenty of variable space. The