<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>(Zephyr / NCS) WS2812 Timing and hardware tuning</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79393/zephyr-ncs-ws2812-timing-and-hardware-tuning</link><description>I&amp;#39;m implementing the WS2812 driver on custom hardware and have some confusion around the hardware tuning parameters for the SPI implementation. The description of the device tree definition for my WS2812 implies that you can adjust the `spi-max-frequency</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Sep 2021 13:50:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79393/zephyr-ncs-ws2812-timing-and-hardware-tuning" /><item><title>RE: (Zephyr / NCS) WS2812 Timing and hardware tuning</title><link>https://devzone.nordicsemi.com/thread/328858?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 13:50:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ec4af28-7c7e-4e38-9853-8043c2e8472a</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;The original `&lt;code class="inline"&gt;ws2812_reset_delay();&lt;/code&gt;&lt;span&gt;&amp;nbsp;` function call in the driver delayed for 8us. Since we&amp;#39;ve validated previous hardware revisions with the stock driver, I tried to recreate its functionality as close as possible. I&amp;#39;ll keep an eye on it and know what to tweak if something doesn&amp;#39;t look right.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: (Zephyr / NCS) WS2812 Timing and hardware tuning</title><link>https://devzone.nordicsemi.com/thread/328856?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 13:42:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1076694-e01f-425b-a8c3-73b6807de291</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you for posting the solution here! It looks like you found a good way to generate the reset signal. But are you sure 10 uS will be sufficient? I noticed it said &amp;gt;50uS in the datasheet I found.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: (Zephyr / NCS) WS2812 Timing and hardware tuning</title><link>https://devzone.nordicsemi.com/thread/328681?ContentTypeID=1</link><pubDate>Wed, 08 Sep 2021 20:50:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8a64c78-70f8-4b73-8843-f8e76640044c</guid><dc:creator>zciwor</dc:creator><description>&lt;p&gt;I was able to identify a solution by slightly modifying the driver code to accommodate my inverting driver. You&amp;#39;ll notice in the .overlay file that comes with the sample code has the ONE_FRAME value defined as 0x70 and the ZERO_FRAME defined as 0x40 and a clock speed of 4MHz (each bit becomes 250ns). So the following is true for the non-inverting, standard driver:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;spi-zero-frame = 
0x40 = 
0100000 =
250ns pulse ON &amp;amp; 1050ns pulse OFF

spi-one-frame = 
0x70 = 
01110000 = 
750ns pulse ON &amp;amp; 900ns pulse OFF

Reset signal (0) of 8us.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Now, to change this code for the inverting&amp;nbsp;logic level shifter we can observe the following changes:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;spi-zero-frame = 
0xBF = 
10111111 =
250ns pulse OFF &amp;amp; 1050ns pulse ON

spi-one-frame = 
0x8F = 
10001111 = 
750ns pulse OFF &amp;amp; 900ns pulse ON

Reset signal (1) of 8us&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The reset signal&amp;nbsp;becomes a little&amp;nbsp;tricky in the inverting world. I was able to achieve this by filling a buffer length of 5 with 0xFF. This is because with our&amp;nbsp; clock frequency of 4MHz, 1 bit = 250us, so 5 * 8 bits * 250ns = 10us. &lt;br /&gt;&lt;br /&gt;By modifying the driver code slightly, we can replace the line:&lt;br /&gt;&lt;/span&gt;&lt;code class="inline"&gt;ws2812_reset_delay();&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;(in zephyr/drivers/led_strip/ws2812_spi.c) &lt;br /&gt;&lt;br /&gt;with:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// This is the reset line
uint8_t res_buf[5];
memset(&amp;amp;res_buf, 0xFF, sizeof(res_buf));
struct spi_buf res_spi_buf = {
	.buf = &amp;amp;res_buf,
	.len = sizeof(res_buf),
};
const struct spi_buf_set res_tx = {
	.buffers = &amp;amp;res_spi_buf,
	.count = 1
};
rc = spi_write(dev_data(dev)-&amp;gt;spi, &amp;amp;cfg-&amp;gt;spi_cfg, &amp;amp;res_tx);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: (Zephyr / NCS) WS2812 Timing and hardware tuning</title><link>https://devzone.nordicsemi.com/thread/328642?ContentTypeID=1</link><pubDate>Wed, 08 Sep 2021 14:08:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b4bd02d-2f06-4a8f-ab9a-6a0d06be8520</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not that familiar with the WS2812 but I found some timing requirements from the document here: &lt;a href="https://cdn-shop.adafruit.com/datasheets/WS2812.pdf"&gt;https://cdn-shop.adafruit.com/datasheets/WS2812.pdf&lt;/a&gt;. Are these correct for your device? If so, are you able to tell from the scope trace how much off you are for &amp;#39;1&amp;#39; and &amp;#39;0&amp;#39; with the default configuration?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1631109944495v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I think it might help to simply turn on the &lt;span&gt;&lt;a title="64 MHz crystal oscillator (HFXO)" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/clock.html?cp=4_2_0_18_0_0#concept_rmw_c5y_2q"&gt;HFXO&lt;/a&gt; as it will improve the accuracy of the SPI clock. &lt;a title="  64 MHz internal oscillator (HFINT)  " href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/clock.html?cp=4_2_0_18_3_0#unique_1861058799"&gt;HFINT&lt;/a&gt; which is enabled by default have can have a drift of up to +- 6%. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>