Skip to content

Latest commit

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SpiPixelController

Lattice MachXO2 FPGA SPI Slave to NeoPixel/WS2812 Controller. The SpiPixelController accepts SPI commands from a Master which contain RGB or WRGB data and converts that to WS2812 or similar serial output. The FPGA utilizes the MachXO2 EFB FIFO and the EFB User Slave SPI. The FIFO is configured to provide a 1024 by 32bit buffer which is used for RGB or WRGB values and Reset Cycle and Reset Code words. The FPGA provides two modes of operation. Wait for Reset and Continuous Mode. In Wait For Reset mode the serialization of the RGB data will only occur when a Reset Cycle or Reset Code has been placed into the FIFO. This allows for a maximum of 1023 LEDs and 1 Reset Command. In continuous mode, the flow control is pushed to the user but the FPGA does not wait for a Reset allowing longer strips then the buffer. However, in the event that the FIFO becomes empty, a Reset Code will be inserted. The FPGA provides configurable Almost Full and Almost Empty output signals. In addition the SPI command protocol will return the contents of the status register when performing RGB or WRGB Load Commands.

SpiPixelController Target Device

Target Device: LCMXO2-1200HC-4SG32C

Lattice MachXO2

  • XO2-1200HC
  • Package: 32-QFNS (5x5)
  • Speed Rating: -4
  • Commercial Temperatures

IO Voltage: 3.3V

SpiPixelController SPI Slave Performance

The SpiPixelController utilizes the MachXO2's hardened User SPI Slave EFB and can operate with a SPI Clock of 20Mhz or less. However, achieving that speed is highly dependent on the PCB and/or wiring of the system and may not be achievable.

SpiPixelController Device Pinout

FPGA FunctionDual FunctionQFN32 PinDesign Signal
PL9APCLKT3_04LED_OUT
PL9BPCLKC3_05ERROR
VCCIO3-63.3V
VCCIO2-73.3V
PB4CCSSPIN8-
PB6CMCLK/CCLK9SCLK
PB6DSO/SPISO10MISO
PB9APCLKT2_011GPO[1]
PB9BPCLKC2_012GPO[0]
PB11APCLKT2_113RST_N
PB11BPCLKC2_114SCSN
VCCIO2-153.3V
PB20CSN16-
PB20DSI/SISPI17MOSI
VCC-183.3V
VCCIO1-193.3V
PR5DPCLKC1_020FIFO_AEMPTY
PR5CPCLKT1_021FIFO_AFULL
PT17DDONE23-
VCCIO0-243.3V
PT15DPROGRAMN25-
PT15CJTAGENB26-
PT12DSDA/PCLKC0_027-
PT12CSCL/PCLKT0_028-
PT11DTMS29-
PT11CTCK30-
VCCIO0-313.3V
PT10DTDI32-
PT10CTDO1-
VCC-23.3V
GND-3GND
GND-22GND
Notes:
1) Design Signals with "-" indicate Not Connected.
2) It is recommended that signals SN and MISO have external pull up resistors.

SPI Commands

SPI is a serialized byte interface and by itself does not define a communication protocol. The following SPI communication protocol is used to operate the SpiPixelController.

CommandCommand ByteAddress ByteDummy ByteData Byte(s)
Hardware ID0xF0-11
Revision Number0xF1-11
Register Read0x00111+
Register Write0x011-1+
Load RGB0x04--1+
Load WRGB0x05--1+
Load Reset Cycle0x06--1+
Load Reset Code0x07--1+
Notes:
1) Command fields with "-" indicate they are not present.
2) During Load RGB, Load WRGB, Load Reset Cycle and Load Reset Code commands the
Status Register value is returned on the MISO. The Status Register has fields
for the state of the FIFO and can be used for flow control by the Master.
3) During Reset Cycle and Code commands the data byte value is ignored but for
each byte an additional reset (either cycle or code) will be inserted.
4) Dummy Bytes allow for the FPGA to fetch and load TX buffers and are required
where indicated.

Hardware ID Command

Hardware ID Command

Revision Number Command

Revision Number Command

Register Read Command

Register Read Command

Register Write Command

Register Write Command

Load RGB Command

Load RGB Command

Load WRGB Command

Load WRGB Command

Load Reset Cycle Command

Load Reset Cycle Command

Load Reset Code Command

Load Reset Code Command

Device Registers

RegisterOffsetBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
Status0x00-WERROROVERUNDERAFULLAEMPTYFULLEMPTY
Configuration0x01------MODEENABLE
WRGB Format0x0276543210
Full MSB0x03-----1098
Full LSB0x0476547777
Empty MSB0x05-----1098
Empty LSB0x0676543210
Zero High Timing0x0776543210
Zero Low Timing0x0876543210
One High Timing0x0976543210
One Low Timing0x0A76543210
Reset Cycle Timing0x0B76543210
Reset Code Timing0x0C76543210
Run0x0D-------RUN/STOP
GPIO Value0xF0------GPO1GPO0
GPIO Direction0xF1------GPO1_ENGPO0_EN
Scratch Pad 10xF276543210
Scratch Pad 20xF376543210
Scratch Pad 30xF476543210
Scratch Pad 40xF576543210
Notes:
1) Register bit fields with "-" indicate they are reserved and will be 0 when read.
2) Timing Registers are only writable when ENABLE is 0 or when the FIFO is empty. A
Write Error will occur when a write occurs and the device is ENABLED or the FIFO is
not empty.

File Structure

Lattice Diamond Project Files:

./prj/
-> fifo_dc_efb/ : IPexpress files for the FIFO EFB
-> slave_efb/ : IPexpress files for the User SPI Slave
-> /top/ : Lattice Diamond top level project
-> top_4SG32C.ldf : Top level Lattice Diamond project file in the 4SG32C package
-> top_6SG32I.ldf : Top level Lattice Diamond project file in the 6SG32I package
-> top1.sty : Top level Lattice Diamond strategy file
./syn/machxo2_qfn32.lpf : Design IO constraints

RTL Design:

./rtl/
-> ctrl.v : Wishbone and SPI Command controller
-> fifo_dc_efb.v : EBF FIFO instance
-> regs.v : Device Registers
-> ser.v : Device WS2812 serializer
-> slave_efb.v : EBF SPI Slave instance
-> top.v : Top level

Test Bench:

./rpi/
-> rpi_debug_test.py : Raspberry Pi Python FPGA Checkout Test
-> rpi_strand_test.py : Raspberry Pi Python FPGA Strand Test
./sim/
-> macros/
-> test_gpo.do : Active HDL do macro to launch GPO test
-> test_registers.do : Active HDL do macro to launch Registers test
-> test_rgb.do : Active HDL do macro to launch RGB pixel test
-> test_wrgb.do : Active HDL do macro to launch WRGB pixel test
-> tb/
-> tb_common.v : Common testbench tasks and functions, this file is `included
-> tb_gpo.v : GPO test specific operations
-> tb_registers.v : Registers test specific operations
-> tb_rgb.v : RGB test specific operations
-> tb_wrgb.v : WRGB test specific operations
-> waves/
-> aliases.xml : Active HDL signal group aliases
-> wave_ctrl.do : Controller waveform .do file
-> wave_efb.do : User SPI Slave EFB waveform .do file
-> wave_reg.do : Register waveform .do file
-> wave_ser.do : Serializer waveform .do file
-> wave_tb.do : Test Bench waveform .do file
-> wave_top.do : Device top waveform .do file

Launch Simulation Using Active-HDL:

  1. Change the BASE_PATH attribute in the macro .do files to the location of the files
  2. Launch Active HDL
  3. Execute the .do macro assocaited with a give test to compile and run the test
 Tools -> Execute macro...
Navigate to the [BASE_PATH]/sim/tb/test_rgb.do
Select file and Click -> "Open"

TinyFPGA AX2 Implementation Pinout

FPGA FunctionDual FunctionDesign SignalQFN32 PinTinyFPGA AX2 Pin
VCC--Multiple3.3V
GND--MultipleGND
PL9APCLKT3_0LED_OUT416
PL9BPCLKC3_0ERROR517
PB6CMCLK/CCLKSCLK919
PB6DSO/SPISOMISO1020
PB9APCLKT2_0GPO[1]1121
PB9BPCLKC2_0GPO[0]1222
PB11APCLKT2_1RST_N131
PB11BPCLKC2_1SCSN142
PB20DSI/SISPIMOSI174
PR5DPCLKC1_0FIFO_AEMPTY205
PR5CPCLKT1_0FIFO_AFULL216

Notes

1) The SpiPixelController uses the onboard oscillator. The onboard oscillator has an
accuracy of +/- 5%. The default timing values for the LED serializer assumes an ideal
clock speed and the timing values may need to be adjusted for a given device or LED
strip.
2) WS2812 and similiar LEDs require a 5.0V data input signal. The MachXO2 device can only
drive a maximum of 3.3v depending on the IO voltage of the device. A logic converter
from 3.3V to 5.0v is required. The Texas Instruments SN74AHCT125N
(http://www.ti.com/product/SN74AHCT125) can be used for this purpose.
3) The TinyFPGA AX2 (https://store.tinyfpga.com/products/tinyfpga-a2) is compatible with
this design and was used as the development device for this project.
4) The MachXO2 is sensitive to Electrostatic Discharge. Proper handling is required.
5) For more information about the Lattice MachXO2 device visit:
http://www.latticesemi.com/en/Products/FPGAandCPLD/MachXO2
6) To build the SpiPixelController design Lattice's Diamond application is required. Diamond
requires a license but a free license can be obtained by visiting Lattice's website:
http://www.latticesemi.com/en/Products/DesignSoftwareAndIP/FPGAandLDS/LatticeDiamond

About

Lattice MachXO2 SPI Slave to WS2812 Pixel Controller

Topics

Resources

Stars

9 stars

Watchers

2 watching

Forks

Releases

Contributors

Languages