Message from discussion
Fancy RGB LEDs with built in control chip
Received: by 10.180.93.6 with SMTP id cq6mr1660799wib.2.1351472125118;
Sun, 28 Oct 2012 17:55:25 -0700 (PDT)
X-BeenThere: hacman@googlegroups.com
Received: by 10.180.20.136 with SMTP id n8ls3520387wie.3.gmail; Sun, 28 Oct
2012 17:55:20 -0700 (PDT)
Received: by 10.180.97.162 with SMTP id eb2mr1656624wib.0.1351472120727;
Sun, 28 Oct 2012 17:55:20 -0700 (PDT)
Received: by 10.180.97.162 with SMTP id eb2mr1656623wib.0.1351472120718;
Sun, 28 Oct 2012 17:55:20 -0700 (PDT)
Return-Path: <alan.burli...@gmail.com>
Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174])
by gmr-mx.google.com with ESMTPS id bu8si280532wib.2.2012.10.28.17.55.20
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 28 Oct 2012 17:55:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of alan.burli...@gmail.com designates 209.85.212.174 as permitted sender) client-ip=209.85.212.174;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of alan.burli...@gmail.com designates 209.85.212.174 as permitted sender) smtp.mail=alan.burli...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-wi0-f174.google.com with SMTP id hq7so1412073wib.9
for <hacman@googlegroups.com>; Sun, 28 Oct 2012 17:55:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=message-id:date:from:user-agent:mime-version:to:cc:subject
:references:in-reply-to:content-type:content-transfer-encoding;
bh=VrRJIPvSS2FIdO+YaPPsvaAQWjs15PrbIfcOW6yaPSA=;
b=CL/09T7FtbcyURI0Hi9rZj4StLYJ9u5wap2YxEw/mjkw/JJr/ZkMpkkIZFdqTCsJPp
fZiI87DJwnERoKsFRxPV2FSSBnqUWKAxLQiAAdP4lq42F7gwo+CWaW0ZBdBy2sJCP8NX
7fN1p433F6Po4GTRDfh7gpTGdHDi0UsjKKRMYQHNFZc+UILKoWBlq8Me2yjbfky6jDdS
PXcB/w5ybTpvhec0SMwsQzMgJagXvY/XDDjKdJNze4K35+/KdworOohfdGyKDMvgLxiP
4PgdStlHtT6fS+Mg2b/W3gEoCbzxdpzEOu9dwHmzDhETogIbvrAytOg4uZ5nFaTR9ieX
pYxA==
Received: by 10.180.7.197 with SMTP id l5mr12832969wia.13.1351472120577;
Sun, 28 Oct 2012 17:55:20 -0700 (PDT)
Return-Path: <alan.burli...@gmail.com>
Received: from [192.168.2.103] (host81-149-45-14.in-addr.btopenworld.com. [81.149.45.14])
by mx.google.com with ESMTPS id dm3sm9112760wib.3.2012.10.28.17.55.18
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 28 Oct 2012 17:55:19 -0700 (PDT)
Message-ID: <508DD3F5.7040...@gmail.com>
Date: Mon, 29 Oct 2012 00:55:17 +0000
From: Alan Burlison <alan.burli...@gmail.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version: 1.0
To: Bob Clough <para...@ivixor.net>
CC: hacman@googlegroups.com
Subject: Re: [HACMan] Fancy RGB LEDs with built in control chip
References: <CAKErKRCJ9xi=PEOCPqDQ19ewRhsA=8NSNwzpv02qkb3CptX...@mail.gmail.com>
In-Reply-To: <CAKErKRCJ9xi=PEOCPqDQ19ewRhsA=8NSNwzpv02qkb3CptX...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
On 24/10/12 14:21, Bob Clough wrote:
> Some more details, including sample code for talking to them:
> http://www.insomnialighting.com/products/rgbsmdws2811.html
I think this code is working more by luck than by anything else.
Assuming the pixels are set to high speed mode (800Kbps) then each bit
period is 1.25usec long. It appears that the WS2881 reads each incoming
bit by looking for a rising edge at the beginning of each bit cell, and
then sampling 1/2 way through each cell - if it's high a 1 is being
transmitted, if it's low then it's a 0.
The example code is using a 4MHz SPI clock and writing 8 bits for each
bit of the value it is sending, either 0b10000000 for zero or 0b11110000
for a one. 8 bits @ 4MHz = 2usec per bit cell or an effective baud rate
of 500Kbps, whereas the spec says it should be 800Kbps, so it's 37.5%
out - a huge margin. I think the only reason it works is because the
WS2881 must be re-syncing on the rising edge at the start of each bit
cell - if this was a normal async serial connection it just wouldn't
work with that degree of clock skew.
What the code *should* be doing is writing 5 bits for each bit it sends,
say 0b10000 for 0 and 0b11110 for 1. 5 bits @ 4MHz = 1.25usec, which is
the specified bit cell length. Of course, writing 5 bits a time is a
lot more complicated to implement as there's a more bit-fiddling to do
to marshal the 5-bit chunks into the 8-bit SPI output register.
On the AVR it *may* be possible to do this more easily with the USART
than with the SPI hardware. The USART has a synchronous mode where it
doesn't use start/stop bits, using instead a clock signal on one of the
pins. If I've read the docs correctly, it *should* be possible to get
it to run at 4MHz (just!). The advantage of the USART is that it can be
set to transmit 5-bit frames, which will then give exactly the right bit
cell length of 1.25usec. The other advantage that the USART has over
the SPI hardware is that unlike the SPI hardware it is double-buffered,
so you can drive it at full line speed.
There's other not-so-good stuff in the code as well, such as the use of
the modulo operator and multiplication instead of bit masking and
shifting. It might work OK on a 64Mhz PIC but on an AVR the
consequential multiplication and division operations will be problematic.
--
Alan Burlison
--