Home
        AN_371 FT90x WS2812 Example
         Contents
1.       sssssssusu2u222 2        n 7  3 3 Main APDiCAtiON iisiciisssscriertssieieuresietretintiestabiiereieaie erie 8   4 CONCUSSION ei E EE EEA    10   5 Contact Information       pivauowsaaswes oninia Doene anioia 11   Appendix A     References         ssss                    EEE 12  Document RefEreNnCes      cccceeeeeeeeeeeeeeeeeeee eee 12  Acronyms and ADDreviatiONnsS     ccccsssccccccnneescccnneeeseeenneseseennnenesoss 12   Appendix B     List of Tables  amp  Figures        ccsssssceeennnesees 13  LIGCOF TADS isinisisi aA 13  LISE OF FIQGUIES siicicssaricietcntrsdedcereciniestirdrenstitisassrirdercatesdbeetecinbeens 13   Appendix C     Revision HIStOPy       cccssessseeeennnsseseeennneeees 14   1    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    h    Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446               1 Introduction    This Application Note describes and explains the FT90x WS2812 Example  The FT90x WS2812  Example demonstrates how to interface with the World Semi WS2812    Intelligent control LED  integrated light source    with an FT90x microcontroller     1 1 Overview    This document will describe the design and implementation of the FT90x WS2812 Example  The  FT90x WS2812 Example will control two WS2812 LEDs on a MM900 Evaluation Board and fade  them through various hues  WS2812 LEDs use a proprietary 1 Wire like protoco
2.    FTDI  Chip    N    d    Application Note  AN_371    FT9Ox WS2812 Example    Version 1 0    Issue Date  2015 10 06    This note describes how to use GPIO to communicate with the WS2812     Intelligent control LED integrated light source    on the MM900 EV Module     Use of FTDI devices in life support and or safety applications is entirely at the user   s risk  and the  user agrees to defend  indemnify and hold FTDI harmless from any and all damages  claims  suits  or expense resulting from such use     Future Technology Devices International Limited  FTDI   Unit 1  2 Seaward Place  Glasgow G41 1HH  United Kingdom  Tel    44  0  141 429 2777 Fax    44  0  141 429 2758   Web Site  http   ftdichip com  Copyright    2015 Future Technology Devices International Limited        y    E Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446          a     Table of Contents    L TRCPOGUCCION sccscucciccacrnveccsvestusecnrcreecsssasiseaveevecasuestisec   2  LL OV CEVICW oiro acoenreiniaiwenteiaineiereeeeunEn 2  1 2 LICENSE setandvextucwcnsusneuencsesovceav she venceancueuasavasehaudseuckeueneuencesanenc 2   2 e icacdececasadecetenscesnsucsdecriuctcsarvacudvaniusadeareieudusncasvens 3  2l WOZGRZ MEDS iorns rhinn NENEI 3   3 Implementation         ss  2 2525202222222222 25202u2u2 2 2 2 2   n   D  3 1 Bit banging the WS2812 Protocol via GPIO        ssssss2s          5  3 2 HSV to RGB Colour Space Conversion 
3.  by FTDI  Use of FTDI devices in life support and or safety applications is entirely at the user   s risk  and the  user agrees to defend  indemnify and hold harmless FTDI from any and all damages  claims  suits or expense resulting from  such use  This document is subject to change without notice  No freedom to use patents or other intellectual property rights is  implied by the publication of this document  Neither the whole nor any part of the information contained in  or the product  described in this document  may be adapted or reproduced in any material or electronic form without the prior written consent  of the copyright holder  Future Technology Devices International Ltd  Unit 1  2 Seaward Place  Centurion Business Park   Glasgow G41 1HH  United Kingdom  Scotland Registered Company Number  SC136640       13    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited         Application Note  FTDI AN_371 FT90x WS2812 Example      Chie Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446       d       Appendix A   References    Document References    FT900 901 902 903 Datasheet  FT905 906 907 908 Datasheet  FT900 User Manual    World Semi WS2812 Intelligent control LED integrated light source Datasheet    Acronyms and Abbreviations    GPIO General Purpose I O    HSV Hue Saturation Value  LED Light Emitting Diode  RGB Red Green Blue          14  Product Page  Document Feedback Copyright    2015 Future Technol
4.  for the GPIO pin defined in  WS2812_GPIO    e A loop iterates over every bit in parameter b starting at Most Significant Bit and working  down to the Least Significant Bit    e Within the loop  the corresponding symbol mask is chosen and bit banged out on the GPIO  pin  NOOP instructions are used to generate the precise timing     void ws2812_shiftout uints t b       uint8 t i   register uint8_t sym   0  sym    WS2812_GPIO_SYMO  sym1   WS2812_GPIO_SYM1   register uint32_t mask       register volatile uint32_t  gpioval      if  WS2812 GPIO  lt  32           31     gpioval    amp  GPIO  gt GPIO   31 VAL    mask   1  lt  lt  WS2812 GPIO    elif  WS2812 GPIO  lt  64      32   63     gpioval    amp  GPIO  gt GPI032_63_VAL    mask   1  lt  lt   WS2812 GPIO   32     else     64   66     gpioval    amp  GPIO  gt GPI064 66 VAL    mask   1  lt  lt   WS2812 GPIO   64     endif    for i     O  i  lt  8    i     if b  amp  0x80  sym  else sym    sym1    sym      if  sym  amp  0x80   gpioval    mask    else  spioval  amp    mask   asm _noop      asm _noop      asm _noop      asm _noop      if  sym  amp  0x40   gpioval    mask    else  spioval  amp    mask   asm _noop      asm noop      asm _noop      if  sym  amp  0x20   gpioval    mask    else  spioval  amp    mask   asm _noop      asm _noop      asm _noop      asm _noop      if  sym  amp  0x10   gpioval    mask    else  spioval  amp    mask   asm _noop      asm _noop      asm _noop      if  sym  amp  0x08   gpioval    mask    else  spio
5. ce     Shanghai  China  Future Technology Devices International Limited Future Technology Devices International Limited   Taiwan   China   2F  No  516  Sec  1  NeiHu Road Room 1103  No  666 West Huaihai Road   Taipei 114 Shanghai  200052  Taiwan   R O C  China  Tel   886  0  2 8791 3570 Tel   86 21 62351596  Fax   886  0  2 8791 3576 Fax   86 21 62351595  E mail  Sales  tw sales1  ftdichip com E mail  Sales  cn sales ftdichip com  E mail  Support  tw supporti ftdichip com E mail  Support  cn support ftdichip com    E mail  General Enquiries  tw admini ftdichip com E mail  General Enquiries  cn admin ftdichip com    Web Site    http    ftdichip com    Distributor and Sales Representatives    Please visit the Sales Network page of the FTDI Web site for the contact details of our distributor s  and sales  representative s  in your country     System and equipment manufacturers and designers are responsible to ensure that their systems  and any Future Technology  Devices International Ltd  FTDI  devices incorporated in their systems  meet all applicable safety  regulatory and system level  performance requirements  All application related information in this document  including application descriptions  suggested  FTDI devices and other materials  is provided for reference only  While FTDI has taken care to assure it is accurate  this  information is subject to customer confirmation  and FTDI disclaims all liability for system designs and for any applications  assistance provided
6. ent Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example    Chip Version 1 0       Document Reference No   FT_001166 Clearance No   FTDI  446       4 Conclusion    The FT90X devices make for an ideal controller in a home automation or advertising application  where the control of multiple LED lighting is required     The GPIO interface allows for a relatively simple coding exercise to realize full colour  and  brightness control of the LEDs        12    Product Page    Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example      Chie Version 1 0    Document Reference No   FT_001166 Clearance No   FIDI  446    A          5 Contact Information    Head Office   Glasgow  UK Branch Office   Tigard  Oregon  USA  Future Technology Devices International Limited Future Technology Devices International Limited  Unit 1  2 Seaward Place  Centurion Business Park  USA   Glasgow G41 1HH 7130 SW Fir Loop  United Kingdom Tigard  OR 97223 8160  Tel   44  0  141 429 2777 USA  Fax   44  0  141 429 2758 Tel   1  503  547 0988  Fax   1  503  547 0987  E mail  Sales  sales1  ftdichip com  E mail  Support  supporti  ftdichip com E Mail  Sales  us Sales ftdichip com  E mail  General Enquiries  admini ftdichip com E Mail  Support  us Support ftdichip com  E Mail  General Enquiries  us admin ftdichip com  Branch Office   Taipei  Taiwan Branch Offi
7. ices International Limited    Application Note  AN_371 FT90x WS2812 Example    Version 1 0       Document Reference No   FT_001166 Clearance No   FIDI  446       Table 5  Code Listing for Function hsv2rgb    3 3 Main Application  This application  shown in Table 6  Code Listing for the Main Application      will fade the two WS2812 LEDs on the MM900 board through different hues with one LED having  the opposite hue of the other LED     int main void        setup       for     loop       return           void setup    uint8 t i     for  i 0  i lt N_LEDS    i          Every LED has a different Hue Offset     ledhsv i  hue    255 N_LEDS  i   ledhsv i  val   VALUE   ledhsv i  sat   SATURATION          wS2812 init          void loop         uint8 t i        Fade to a new colour     for  i 0  i lt N_LEDS    i     hsv2rgb ledhsv i  hue  ledhsv i  sat  ledhsv i  val    amp  ledrgb i  r    amp  ledrgb i  g    amp  ledrgb i  b     ledhsv i  hue          10    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  AN_371 FT90x WS2812 Example    Version 1 0       Document Reference No   FT_001166 Clearance No   FIDI  446       Write the new values to the LEDs     for  i 0  i lt N_LEDS    i     ws2812 write ledrgb i  r  ledrgb i  g  ledrgb i  b      delayus 5       Have to wait this much for the WS2812 to latch their colour       delayms 25         Table 6  Code Listing for the Main Application       11    Product Page  Docum
8. l to shift in colour  values and allow data to be daisy chained to other WS2812 LEDs     This document is intended to demonstrate the bridging capabilities of the FT90x family of  microcontrollers     1 2 License     Copyright 2015  Future Technology Devices International Ltd     This source code   the Software   is provided by Future Technology Devices International Limited    FTDI   subject to the license terms set out  http   www ftdichip com FTSourceCodeLicenceTerms htm   the License Terms    You must read  the License Terms before downloading or using the Software  By installing or using the Software  you agree to the License Terms  If you do not agree to the License Terms then do not download or  use the Software     Without prejudice to the License Terms  here is a summary of some of the key terms of the  License Terms  and in the event of any conflict between this summary and the License Terms then  the text of the License Terms will prevail      The Software is provided  as is   There are no warranties  or similar  in relation to the quality of  the Software  You use it at your own risk  The Software should not be used in  or for  any medical  device  system or appliance  There are exclusions of FTDI liability for certain types of loss such as   special loss or damage  incidental loss or damage  indirect or consequential loss or damage  loss  of income  loss of business  loss of profits  loss of revenue  loss of contracts  business  interruption  loss of the use of m
9. oL O code  Low Voltage Time 550 700 850    tin 1 code  High Voltage Time 650 800 950  ti 1 code  Low Voltage Time 450 600 750    Table 1  Timing for WS2812 Symbols          4    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example    Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446          Colour is transferred to a WS2812 LED in 24 bit chunks  an 8 bit value of Green  an 8 bit value of  Red  and an 8 bit value of Blue  Most Significant Bit first  Multiple colours can be transferred in  order to update multiple LEDs  At the end of an update a Reset must be sent which will cause the  LEDs to latch in the new colour     LED 1 LED 2    LEDN Reset       Figure 2  Timing Diagram for WS2812 Update       5    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    h    Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446               3 Implementation    3 1 Bit banging the WS2812 Protocol via GPIO    Several methods of communicating with WS2812 are available  UART  SPI  GPIO   however for the  purposes of this demo  GPIO was selected     In order to simplify transferring bits to the WS2812  a common symbol time for    1   s and    O   s is  derived and separated up into 8 sections to allow the use of an 8 bit long pattern  The du
10. ogy Devices International Limited    
11. oney or anticipated savings  loss of information  loss of  opportunity  loss of goodwill or reputation  and or loss of  damage to or corruption of data     There is a monetary cap on FTDI s liability     The Software may have subsequently been amended by another user and then distributed by that  other user   Adapted Software    If so that user may have additional license terms that applies to  those amendments  However  FTDI has no liability in relation to those amendments        2    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example    Chip Version 1 0       Document Reference No   FT_001166 Clearance No   FTDI  446       2 Theory    2 1 WS2812 LEDs    WS2812 Serial LEDs use a One Wire protocol for communication which determines a bit based  upon the pulse width of the symbol  The WS2812 protocol uses three symbols  a O bit  a 1 bit   and a Reset symbol  used to latch in data   These three symbols are described in Figure 1  Timing  Diagram for WS2812 Symbols    and Table 1  Timing for WS2812 Symbols       3    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  AN_371 FT90x WS2812 Example    Chie Version 1 0    Document Reference No   FT_001166 Clearance No   FIDI  446          Figure 1  Timing Diagram for WS2812 Symbols    frame   Bescon   win   rvp   mox   uone  toH O code  High Voltage Time 200 350 500  t
12. ration of  the    1    and    0    symbols lie within 1 25 usec allowing for a 150 nsec bit time for the 8 bit pattern     For a    1    symbol  the signal needs to be high for 650 to 950 nsec which corresponds to either 5 or  6 bit times     For a    0    symbol  the signal needs to be high for 200 to 500 nsec which corresponds to either 2 or  3 bit times     Assuming that a    1    symbol uses 5 bit times and a    0    symbol uses 3 bit times  this means that a    1     symbol will be high for 750 nsec and low for 450 nsec giving a mask of F8   Ob 1111 1000   anda     0    symbol will be high for 450 nsec and low for 750 nsec giving a mask of EO   Ob 1110 0000      The function ws2812_ init in ws2812 gpio c  shown in Table 2  Code Listing for Function  ws2812_init      sets up the GPIO pin as an output     void ws2812_init void          gpio_function WS2812_GPIO  pad_func_     gpio_dir WS2812_GPIO  pad_dir_output         Table 2  Code Listing for Function ws2812_init    The function ws2812_shiftout in ws2812_gpio c  shown in Table 3  Code Listing for Function  ws2812_shiftout       6    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446       A         implements shifting out a byte of data to a GPIO pin using the WS2812 protocol     e The corresponding GPIO register and bitmask is determined
13. val  amp    mask   asm _noop      asm _noop      asm _noop          7    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446       P    asm_noop      if  sym  amp  0x04   gpioval  else  gpioval  amp    asm_noop      asm_noop      asm_noop      if  sym  amp  0x02   gpioval  else  gpioval  amp      asm_noop      asm_noop      asm_noop      asm_noop      if  sym  amp  0x01   gpioval  else  snioval  amp         Table 3  Code Listing for Function ws2812_shiftout       8    Product Page  Document Feedback Copyright    2015 Future Technology Devices International Limited    Application Note  FTDI AN_371 FT90x WS2812 Example      Chip Version 1 0    Document Reference No   FT_001166 Clearance No   FTDI  446    A          Using this function  we can create the function ws2812_write in ws2812_gpio c  shown in Table 4   Code Listing for Function ws2812_ write      which sends out a RGB colour value on the GPIO pin     void ws2812_ write uint8 t r  uint8 t g  uint8 t b       ws2812_shiftout g     ws2812_shiftout r     ws2812_shiftout b         Table 4  Code Listing for Function ws2812_write    3 2 HSV to RGB Colour Space Conversion    Colour can be described in many different ways  Typically  colour is given as a level of Red  Green  and Blue  RGB  which is what the WS2812 LED uses to display a colour  Howe
14. ver  in order to  simplify linearly fading through colour  another colour space can be used  This application uses the  Hue  Saturation and Value  HSV  colour space which allows for a more intuitive approach to colour  manipulation     e Hue defines what base colour to use    e Saturation defines its colorfulness  A high saturation gives a bright colour  a low saturation  gives grey    e Value defines the level of brightness relative to full white     Therefore  by having a fixed saturation and value  and cycling through the Hue  a gradual fade of  colour can be generated     A conversion function is needed to convert from a HSV to a RGB colour space in order for HSV  values to be used with WS2812 LEDs  The function hsv2rgb in rgbhsv c  shown in Table 5  Code  Listing for Function hsv2rgb      converts HSV values to RGB values  This function uses fixed point math since the FT32 core does  not support floating point     void hsv2rgb uint8 t h  uint8 t s  uint8 t v   uint8 t  r  uint8 t  g  uint8 t  b         Based on http   stackoverflow com a 14733008       uint8 t region  remainder  p  q  t     if  s           t  V3   g   V5   b   y      else     region   h   43   remainder    h    region   43     6     p    v    255   s    gt  gt  8   q   v    255     s   remainder   gt  gt  8     gt  gt  8   t    v    255     s    255   remainder    gt  gt  8     gt  gt  8     Switch  region          case 0        9    Product Page  Document Feedback Copyright    2015 Future Technology Dev
    
Download Pdf Manuals
 
 
    
Related Search
    
Related Contents
Monitor 4 - SE International  INSTRUCTION MANUAL NOTICE D'UTILISATION  Oblig 2 -    Samsung WA1088B0 用戶手冊      Carrier TC-NAC01 Owner's Manual  Rollei BullBar 34    Copyright © All rights reserved. 
   Failed to retrieve file