Translate

2016年12月6日星期二

APA102C compare with SK6812 LED Strips

APA102/APA102C LED strips are controlled through an SPI protocol on the data and clock input lines. The protocol is documented in the APA102C datasheet (1MB pdf), but we describe it below with some modifications that we have found to work better.

The default, idle state of the clock signal line is low, and the data signal is read on each rising edge of the clock. To update the LED colors, you need to toggle the clock line while driving the data line with the value of each bit to send; this can be done through software (bit-banging), or it can be handled by a hardware SPI peripheral in a microcontroller. There is no minimum clock frequency, although using a lower frequency means that it will take longer to update the entire sequence of LEDs (especially when controlling a long strip or many strips are chained together), so you will probably want to use the fastest practical clock speed to get the best update rate.


APA102C control signal timing diagram.
The data for each LED is encoded as a sequence of 32 bits (4 bytes) called an LED frame. The first three bits of the LED frame should be ‘1’. The next 5 bits are a “global”, color-independent brightness value (0–31) that is applied equally to all three color channels. The remaining 24 bits are the color values, in BGR (blue-green-red) order. Each color value uses 8 bits (0–255). The most significant bit of each value is transmitted first. The first LED frame transmitted applies to the LED that is closest to the data input connector, while the second color transmitted applies to the next LED in the strip, and so on.

To update all the LEDs in the strip, you should send a “start frame” of 32 ‘0’ bits, then a 32-bit “LED frame” for each LED, and finally an “end frame”. If you send fewer LED frames than the number of LEDs on the strip, then some LEDs near the end of the strip will not be updated.


The APA102/APA102C datasheet recommends that the end frame be composed of 32 ‘1’ bits, but we have found this does not work reliably in certain situations and can sometimes lead to glitches. This can be avoided by using an end frame that consists of at least (n–1)(n–1) extra clock edges, where nn is the number of LEDs, with ‘0’ on the data line. It is often easiest to round up to a multiple of 16 clock edges so that you are counting bytes instead (there are 2 clock edges in a bit and 8 bits in a byte); you would therefore send ((n–1)/16)((n–1)/16) bytes (rounded up to the next whole number). For a more detailed explanation, see the comments in the source code of our APA102/APA102C Arduino library, discussed below.


APA102C data format.

For example, to update all 30 LEDs on a 1-meter strip, you should send a 32-bit start frame, thirty 32-bit LED frames, and a 16-bit end frame, for a total of 1008 bits (126 bytes). If multiple strips are chained together with their data connectors, they can be treated as one longer strip and updated the same way (two chained 1-meter strips behave the same as one 2-meter strip).

Each RGB LED receives data on its data input line and passes data on to the next LED using its data output line. The update rate is generally limited only by the speed of the controller; our Arduino library below can update 60 LEDs in about 1.43 milliseconds, so it is possible to update nearly 700 LEDs at 60 Hz. However, constant updates are not necessary; the LED strip can hold its state indefinitely as long as power remains connected.

Note: The minimum logic high threshold for the data and clock signals is 3.5 V, so you should use level-shifters if you want to control these strips from 3.3 V systems. It might be possible to control them with 3.3 V signals directly, but using the strip out of spec like this could lead to unexpected problems.

Comparison with SK6812 LED Strips

Like the APA102/APA102C, the SK6812 used in some of our LED strips also combines an RGB LED and driver into a single 5050-size package. However, while the SK6812 uses a one-wire control interface with strict timing requirements, the APA102/APA102C uses a standard SPI interface, with separate data and clock signals that lets it accept a wide range of communication rates; the trade-off is that two I/O lines are required to control it instead of just one.
The APA102/APA102C provides a 5-bit color-independent brightness control that is not available on the SK6812. This feature can be used to vary the intensity of each pixel without changing its color, and it enables much subtler variations at the low end of the LEDs’ brightness range.
In addition, the APA102/APA102C uses a much higher PWM (pulse-width modulation) frequency for controlling each color channel—about 20 kHz, compared to around 1.2 kHz on the SK6812. As a result, APA102/APA102C LEDs can be less prone to flickering when recorded with a camera and are more suited to applications like persistence-of-vision (POV) displays. (The color-independent brightness is modulated separately at about 600 Hz).
The SK6812 has voltage-independent color and brightness over a wide voltage range. This makes it a good choice for installations with power wires longer than a few meters.
Another advantage of the SK6812 is that all the LEDs in a chain are updated at nearly the same time. The LEDs update the color they are displaying when they see a long enough low period on the data line. The transmission delay from one LED to the next is at most 0.5 μs, so if you were controlling a display of 450 LEDs, they would all be updated within a fraction of a millisecond. The APA102/APA102Cs update the displayed color as soon as their next color is received. Using our Arduino library, it would typically take over 10 ms to send colors to a chain of 450 APA102/APA102Cs, which means that some LEDs would get updated 10 ms before other LEDs in the same chain. This makes the SK6812 a good choice for installations with a large number of LEDs where update latency is a concern.
For more information about the ICs, see the SK6812 datasheet and APA102C datasheet 
While our SK6812 strips and APA102/APA102C strips are physically very similar, they are not functionally compatible with each other. The easiest way to tell them apart is to look at the strips’ end connectors and the connections between each LED segment: SK6812 strips have three connections (power, data, and ground), while APA102/APA102C strips have four (power, clock, data, and ground).