LUT1 Configuration

When the CPU is awakened by LUT0, the LEDs are either going to be turned ON or OFF. By using LUT1 together with the SPI and TCA, it is possible to generate the specific single-wire PWM signal used by the WS2812B LED without writing a specific driver to perform the update.

Using the CCL together with TCA and SPI, it will not be necessary to write a specific software driver to update the LEDs. After initial configuration of the TCA and SPI, the procedure for updating the LEDs is very easy:

  1. Start TCA by writing ̔1ʼ to the enable bit.
  2. Write the data to the SPI data register.
  3. Wait for SPI to be performed.
  4. Stop TCA by writing ̔0ʼ to the enable bit.

Since there is no synchronization between the TCA output and the SPI clock, it is necessary to start and stop the TCA each time data is sent to the LEDs. It is also necessary to clear the TCA CNT register before TCA is started. This is done to make sure that the TCA starts counting from zero each time the LEDs are updated.

The serial protocol used by the WS2812B has three states:

To be able to create State 1, which is equal to B in the timing diagram shown below, the logical expression (SCK, nMOSI, and WO2) needs to be realized.

Creating State 2, the logical expression (SCK and MOSI) is needed. This is not possible directly on LUT1 now since all three inputs are being used, and therefore must continue. This means that a combination of two logical expressions are needed to achieve this. In the timing diagram below, the logical expression C (SCK, MOSI, and WO2) will take care of the first half of State 2 and logical expression A (SCK, MOSI, and nWO2) will handle the remainder.

State 3 is the resetting and latching of the new data. If the data line is held low for 50 μs after the data has been sent, the control circuit inside each LED will reset and latch the new color.

When A, B, and C are combined through an OR gate, the correct signal one-wire protocol is generated.

Figure 1. LUT1 Timing

Connecting the TCA and SPI to LUT1 can be done internally when setting up the CCL.

Figure 2. LUT1 Connections and Truth Table

To get the correct timing it is important to set the correct CPU and peripheral speed by choosing the correct prescalers and clock sources.