<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: HOWTO: drive WS2812 controller-on-LED strips</title>
		<link>http://forums.leaflabs.com/topic.php?id=74191</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:04:45 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=74191" rel="self" type="application/rss+xml" />

		<item>
			<title>anthrolume on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191&amp;page=2#post-105311</link>
			<pubDate>Thu, 03 Apr 2014 14:23:47 +0000</pubDate>
			<dc:creator>anthrolume</dc:creator>
			<guid isPermaLink="false">105311@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@mh: On and if you post, don't bother posting the big LUT - I can generate that in Excel. Thank a ton!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>anthrolume on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191&amp;page=2#post-105310</link>
			<pubDate>Thu, 03 Apr 2014 14:04:55 +0000</pubDate>
			<dc:creator>anthrolume</dc:creator>
			<guid isPermaLink="false">105310@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@mh: That is excellent. Would you be willing to post (or share) your 3.2Mhz, 3-bits-for-1 code?&#60;/p&#62;
&#60;p&#62;I am driving 343 WS2812s and my original approach (the first post in this thread) turns out to turn off interrupts for too long, which screws up serial communication I'm doing. The best I'd done was 4-bits-for-1, and now I can't even get that to work. And clearly you have a lot more knowledge about how to arbitrarily clock SPI that I have.&#60;/p&#62;
&#60;p&#62;Hope you'll post!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mh on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191&amp;page=2#post-105283</link>
			<pubDate>Fri, 14 Mar 2014 08:36:56 +0000</pubDate>
			<dc:creator>mh</dc:creator>
			<guid isPermaLink="false">105283@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oops, that's a typo. I meant : 0b11100000.&#60;/p&#62;
&#60;p&#62;In any event, I have found a different strategy (with the help of the TI e2e community, I have to say). Using a 14.4MHz DCO, divided by 6 (3.2MHz) for SPI, and a lookup table for intensity values, I can feed 3 SPI bits for 1 ws2812 bit instead of 8. This allows the MCU to easily keep feeding the SPI. So, 0 = 100, 1 = 110.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191&amp;page=2#post-105281</link>
			<pubDate>Thu, 13 Mar 2014 17:33:45 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">105281@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;For sure 0xE0 is not 0b00011111.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mh on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191&amp;page=2#post-105280</link>
			<pubDate>Thu, 13 Mar 2014 11:27:08 +0000</pubDate>
			<dc:creator>mh</dc:creator>
			<guid isPermaLink="false">105280@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@jlawson:&#60;br /&#62;
interesting; I am attempting to do the same with a slightly different approach. I am setting the DCO to about 6.4MHz as a source for SPI SIMO, and use 8 bits for 1 WS2812 bit, as you do, but with 0xf8 for a 1 and oxe0 for a 0, which is 0b11111000 and 0b00011111, respectively. That amounts to 0.15725us per bit, so a 1 is 0.78us high, 0.468us low. Seems to be within the range of the ws2812.&#60;br /&#62;
I'm having some difficulties (really beginning with this stuff) using the following test code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;WDTCTL = WDTPW + WDTHOLD;
    //aiming for 6.4MHz;
    BCSCTL1 = 0xd;
    DCOCTL = 0x05 &#38;lt;&#38;lt; 5;
    //spi master on 1.2
    UCA0CTL1 &#124;= UCSWRST;
    P1SEL = BIT2;
    P1SEL2 = BIT2;
    UCA0CTL0 = UCSYNC + UCMST + UCMSB + UCCKPH;
    UCA0CTL1 = UCSSEL_2;
    UCA0CTL1 &#38;amp;= ~UCSWRST;
    while(1){
        UCA0TXBUF = 0x55; //01010101
        while (!(IFG2 &#38;amp; UCA0TXIFG));
        UCA0TXBUF = 0x0;
        __delay_cycles(4000); //just so the scope can trigger
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I suspect the mcu can't source SPI fast enough. Is that why you chose to run at 16MHz?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>matt79 on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105262</link>
			<pubDate>Mon, 03 Mar 2014 20:32:31 +0000</pubDate>
			<dc:creator>matt79</dc:creator>
			<guid isPermaLink="false">105262@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;WS2812B is the new and improved version of the WS2812 LED (a.k.a. 5050/WS2811.)&#60;br /&#62;
For chip details and differences between WS2812, look this &#60;a href=&#34;http://www.ledlightinghut.com/WS2812B_VS_WS2812.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.ledlightinghut.com/WS2812B_VS_WS2812.pdf&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105228</link>
			<pubDate>Wed, 12 Feb 2014 03:21:53 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105228@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;anthrolume - pin HIGH ... pin LOW is pretty good! (I assume the yuck is because small amounts of jitter might be hard to see)&#60;/p&#62;
&#60;p&#62;As you wrote, the systick hardware is running, but the interrupt routine which updates &#60;code&#62;systick_uptime_millis&#60;/code&#62; is not.&#60;/p&#62;
&#60;p&#62;A straightforward way to get timing information for about 1ms elapsed is read the count in SysTick by calling &#60;code&#62;systick_get_count()&#60;/code&#62;.&#60;br /&#62;
Code needs to deal with the fact that it wraps at 1ms, but otherwise it should be robust.&#60;/p&#62;
&#60;p&#62;Or set up another timer, and read its count. Timers can run at 72MHz, and are 16 bits long, so they are under 1ms at 72MHz, but if their input clock is scaled using &#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwaretimer.html#id2&#34;&#62;&#60;code&#62;setPrescaleFactor()&#60;/code&#62;&#60;/a&#62; you can adjust its duration to suit your use case (at the loss of resolution).  The maximum timer count is set by &#60;code&#62;setOverflow()&#60;/code&#62;, which might be 0xFFFF to maximise the duration. These values aren't used until the timer overflows, or pause, refresh then resume the timer explicitly.&#60;br /&#62;
See &#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwaretimer.html&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/hardwaretimer.html&#60;/a&#62; for more information.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>anthrolume on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105227</link>
			<pubDate>Tue, 11 Feb 2014 20:06:59 +0000</pubDate>
			<dc:creator>anthrolume</dc:creator>
			<guid isPermaLink="false">105227@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@crenn,&#60;/p&#62;
&#60;p&#62;That's really cool. I tried using the hardware timers and got nowhere. I hope you can get that to work - I *really* don't want to turn off interrupts.&#60;/p&#62;
&#60;p&#62;You say that systick is still running, but its interrupt routine (which presumably does something like &#34;gs_millis++;&#34;) isn't called. Is there a way to know how much time was spent with interrupts off? (I thought of raising some pin high at the beginning and pulling it low at the end and measuring it with my scope, but...yuck.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105210</link>
			<pubDate>Sat, 08 Feb 2014 08:05:31 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">105210@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Not a stupid question at all, noInterrupts looks like it disables all interrupts, so the systick interrupt route is not called which updates the millis value. Short answer, millis doesn't get updated, although systick is still running.&#60;/p&#62;
&#60;p&#62;I've been experimenting trying to use a PWM pin to run this, but haven't had much success so far to getting it working correctly. Timing according to my logic analyser looks good, but may have to tweak things a little more. Currently it seems the interrupt triggering is too slow and won't be called until the 2nd update/overflow, but it's hard to tell currently. This results in each bit being sent twice, not good. Need to work out exactly what's happening; my code is as follows:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;quot;timer.h&#38;quot;
#define WS2812B_PIN  6
#define PERIOD       90
#define LOWTIME      18
#define HIGHTIME     58//43
#define RESETLOOPS   40
uint8 resettime = 0;
uint32 leddata = 0x00000000;
HardwareTimer timer(1);
uint8 databit = 0;
uint8 repeat = 0;
typedef enum {
  IDLE,
  RESET,
  REFRESH,
  UPDATE
} WS28xxState;
WS28xxState State = IDLE;
void interruptRoutine(void) {
  switch (State) {
    case IDLE:
      break;
    case RESET:
      if(resettime &#38;gt;= RESETLOOPS) {
        if (repeat == 0) {
          State = REFRESH;
          repeat++;
        } else {
          State = IDLE;
          timer.pause();
          timer.setCount(0);
          repeat = 0;
        }
        resettime = 0;
      } else {
        pwmWrite(WS2812B_PIN, 0);
        resettime++;
      }
      break;
    case UPDATE:
    case REFRESH:
      if (leddata &#38;amp; (1&#38;lt;&#38;lt;databit)) {
        pwmWrite(WS2812B_PIN, HIGHTIME);
      } else {
        pwmWrite(WS2812B_PIN, LOWTIME);
      }
      databit++;
      if (databit&#38;gt;=24) {
        databit = 0;
        State = RESET;
      }
      break;
  }
}
void setup() {
  pinMode(WS2812B_PIN, PWM);
  timer.pause();
//  TIMER1-&#38;gt;regs.gen-&#38;gt;DIER &#124;= 0x00000001;
  timer_attach_interrupt(TIMER1, TIMER_UPDATE_INTERRUPT, interruptRoutine);
  nvic_irq_set_priority(NVIC_TIMER1_UP, 6);
  timer.setPrescaleFactor(1);
  timer.setOverflow(PERIOD);
  timer.setCount(0);
  TIMER1-&#38;gt;regs.gen-&#38;gt;CCMR1 &#38;amp;= ~(0x00000004);
  pwmWrite(WS2812B_PIN, 0);
  //timer.setCompare(TIMER_CH1, 45);
  timer.resume();
}
void loop() {
  leddata = 0x000000FF;
  State = UPDATE;
  timer.resume();
  delay(5000);
  leddata = 0x0000FF00;
  State = UPDATE;
  timer.resume();
  delay(5000);
  leddata = 0x00FF0000;
  State = UPDATE;
  timer.resume();
  delay(5000);
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>anthrolume on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105208</link>
			<pubDate>Tue, 04 Feb 2014 03:46:28 +0000</pubDate>
			<dc:creator>anthrolume</dc:creator>
			<guid isPermaLink="false">105208@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@jlawson,&#60;/p&#62;
&#60;p&#62;For what it's worth, I was able to drive WS2812 LEDs with a Maple Mini using the approximate technique described in the Espruino article. The fastest I was able to get it to go was SPI_2_25MHZ (it won't work at SPI_4_5MHZ or above). For each bit, I emitted four bits of data out SPI. I sent 0b0001 for zero bits and 0b0011 for one bits. You end up sending out 4x as many bits as you have real data. The effective frequency of the mixed-duty-cycle squarewaves you get from this technique is 562 KHz according to my scope, which is on the low side according to the WS2812 datasheet. Nevertheless it was entirely reliable. So if you're squeamish about turning interrupts off, you can certainly use this technique and it'll work ok.&#60;/p&#62;
&#60;p&#62;@everyone&#60;br /&#62;
This is probably a stupid question, but between the time I call noInterrupts() and interrupts(), millis() doesn't get updated, right?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105067</link>
			<pubDate>Tue, 10 Dec 2013 13:39:43 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105067@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;crenn - Thanks for that link; that's exactly what I need.&#60;/p&#62;
&#60;p&#62;The timing is more convenient for the WS2812B than the WS2812.&#60;/p&#62;
&#60;p&#62;anthrolume - Again, thanks for posting.&#60;/p&#62;
&#60;p&#62;jlawson - Thank you for posting. I have a plan to do something in hardware using, IMHO, an even neater techniques on STM32F.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jlawson on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105066</link>
			<pubDate>Tue, 10 Dec 2013 13:14:49 +0000</pubDate>
			<dc:creator>jlawson</dc:creator>
			<guid isPermaLink="false">105066@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I saw a neat idea over at the Espruino site for driving the WS2818B type of addressable LEDs.&#60;br /&#62;
Use the SPI peripheral running at 4 times the clock rate of the LEDs (4*800kHz for WS2818B)&#60;br /&#62;
and send multiple bits to make up the asymmetrical signal.&#60;br /&#62;
high byte low byte order&#60;br /&#62;
1 is 11100000 00001110&#60;br /&#62;
0 is 10000000 00001000&#60;/p&#62;
&#60;p&#62;I have implemented this on a 16MHz MSP430 and it works fine using the SPI system. I haven't tried it on a Maple yet.&#60;/p&#62;
&#60;p&#62;&#60;a&#62;http://www.espruino.com/Individually+Addressable+LEDs&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105062</link>
			<pubDate>Tue, 10 Dec 2013 06:53:59 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">105062@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@gbulmer, This is the link to the datasheet I found online: &#60;a href=&#34;http://www.mikrocontroller.net/attachment/180459/WS2812B_preliminary.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.mikrocontroller.net/attachment/180459/WS2812B_preliminary.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I recently did a little breakout board in KiCAD for the WS2812B, only 9.4mm in diameter (which should be small enough to stuff into the cubes they're planned for. Just need to get at least 10 of them!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>anthrolume on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105055</link>
			<pubDate>Tue, 10 Dec 2013 00:50:02 +0000</pubDate>
			<dc:creator>anthrolume</dc:creator>
			<guid isPermaLink="false">105055@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@crenn - Yeah according to spec, the period for 1 and 0 are different, but if you look at my timing constants, I'm using the same period for both and just modifying the pulse width. There's actually quite a bit of slop allowed in the timing - by my calculations you could run the thing anywhere from 540.5 KHz to 1.54 MHz and still be in spec. The fastest squarewave I could make without hardware timers was 1.3MHz on a Maple Mini. The implementation above clocks in at about 884 KHz.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "HOWTO: drive WS2812 controller-on-LED strips"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74191#post-105048</link>
			<pubDate>Mon, 09 Dec 2013 15:51:20 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105048@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;crenn - It is easy enough to find the pin-out data, e.g.&#60;br /&#62;
&#60;a href=&#34;http://www.rgb-123.com/files/WS2812B_VS_WS2812.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.rgb-123.com/files/WS2812B_VS_WS2812.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;However, where did you get the spec sheet with protocol timing for the WS2812B?&#60;br /&#62;
Would you please post a link? The WS2812B look very easy to route.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
