◗ PARTS LIST
Item Description Part No.
◗ C1, C2 47 μF 647-UVR1V470MDD
◗ C3, C4 0.1 μF 80-C315C104M5U
◗ D1 LED 859-LTL-4222N
◗ J1 2.1 mm barrel 806-KLDX-0202-A
◗ J2-J3 RJ- 45 R/A 571-5202514
◗ J4 Machine pin 506-510-AG91D
◗ JP1-JP4 Pin strip header 517-6111TG
◗ Jumpers 0.1” shunt 538-15-29-1024
◗ PB1 N.O. button 612-TL59F160Q
◗ PCB ExpressPCB.com
◗ R1 1K 299-1K-RC
◗ R2-R4 10K 299-10K-RC
◗ R5 100 1/2W 293-100-RC
◗ R6-R7 120Ω 291-120-RC
◗ RES1 20 MHz Parallax 250-02060
◗ S1 28-pin DIP 571-1-390261-9
◗ S2 14-pin DIP 571-1-390261-3
◗ S W1 Slide switch 506-SSA12
◗ U1 SX28AC/DP Parallax SX28AC/DP
◗ U2 MAX489 837-ISL8489IP
◗ VR1 LF50CP 511-LF50CP
◗ X1 R/A header 517-5111TG
Note: All part numbers are from Mouser unless otherwise
noted.
[green] boxes hold the reconstructed bytes.
THE BIG SQUEEZE
At some point, you will probably want to create a node
that requires more than one eight-bit value for a message and
you don’t want to use two bytes for each. Peter came up with
a neat compression solution for his network and I’ve created
it so I can use it. Have a look at Figure 5 to see how Peter
compresses several eight-bit values into seven-bit containers.
Since we will typically manipulate blocks of values, I
created a subroutine called UNSQUEEZE that will take two
bytes from an input buffer and move them into a single byte
of an output buffer. To use this routine, we will pass a
pointer to the start of the input buffer, an offset for the
desired value, and a pointer to the start of the output buffer.
SUB UNSQUEEZE
src = __PARAM1
offset = __PARAM2
dest = __PARAM3
src = src + offset
dest = dest + offset
dByte = __RAM(src)
dByte = dByte >> offset
INC src
dbMSB = __RAM(src)
offset = 7 - offset
dbMSB = dbMSB << offset
dByte = dByte | dbMSB
__RAM(dest) = dByte
ENDSUB
The actual source and destination addresses are incremented by the offset to get to the LSB of the target byte. By
20 January 2008
■ FIGURE 5. Byte packing.
doing this math in the subroutine, we simplify the interface
to it — we don’t have to remember the @ (address of) operator with the array name; we just use the name on its own.
The low bits of the output byte are retrieved using the
__RAM() array and shifted right by the offset to re-align BIT0.
The source address is then incremented to get to the upper
bits. This value is shifted left to move the bits to the correct
position and then the two bytes are ORed together to reconstruct the eight-bit value. Finally, the __RAM() array is used to
move the reconstituted value to the desired output address.
The compliment of UNSQUEEZE is — no big surprise —
SQUEEZE; we can use this to create a compressed packet
to send to another node.
SUB SQUEEZE
src = __PARAM1
offset = __PARAM2
dest = __PARAM3
src = src + offset
dest = dest + offset
dByte = __RAM(src)
dbCopy = dByte
destVal = __RAM(dest)
dByte = dByte << offset
dByte = dByte & $7F
destVal = destVal | dByte
__RAM(dest) = destVal
INC dest
offset = 7 - offset
destVal = dbCopy >> offset
__RAM(dest) = destVal
ENDSUB
With SQUEEZE, the eight-bit value will be split based on its
position in the output array, with the lower half ORed into the
output array so that any previous values there are not disturbed.
Let me suggest that the FILL subroutine be used to clear the
output array before looping through the input array — in order
— to create the compressed packet. It’s a little bit of code, but
now we can send seven full bytes using eight instead of 14, and
this can be important if we have a lot of network traffic.
Okay, I think we should probably wrap it up right here.
Order your boards, build a simple node, and start
experimenting. I’d love to hear your ideas on home control,
especially those ideas that allow us to conserve energy.
Until next time, Happy Networking with the SX! NV
JON WILLIAMS
RjwEill
PASiam
RAOs@
LLUefx
AXR-te
, Ck.c
INCEom
.S
www.parallax.com