WS2812 and strobing at 100 Hz

Hi folks,

Using an Arduino UNO and WS2812 LED strip, I basically want to strobe at 100 Hz (10ms period per color update). On top of that, I also wanted to apply a 10/90 duty cycle factor so that comes out to 1ms for ON (color) time and 9ms for OFF (black) time.

Though, based on the 400 Hz (2.5ms period) upper limit of the WS2812, it seems that even if the Atmel+FastLED can send updates of show(color)-delay(1)-show(black)-delay(9), the WS2812 may "miss" some of those show(black) updates because of its 2.5ms period minimum. The previous delay(1) between the show(color) and show(black) is only ~1ms long while the WS2812 update period is 2.5ms so there could be unpredictable behavior (in my case, it seems to "flicker" unevenly). In addition to that, the WS2812 specification requires (X * 2.5us + 50us) worth of setup time where X is the number of LEDs in the strip. I intend to have 20 LEDs which means ~100us of setup overhead for each ON or OFF instance.

I looked around and it seems the APA102 may be able to do this with ease since its PWM is 20 KHz, way more than enough to handle it since its granularity is 50us.

Is my understanding correct here?

Also, I'd like to point out that there is generally a rule when it comes to sampling a signal properly.

The rule is that you apply a 2.5x harmonic factor to whatever frequency you are sampling, the answer you get is the actual MINIMUM frequency you need to reliably sample that data.

In the above case, if I am strobing 1ms ON and 9ms OFF, the WS2812 would actually have to be able to refresh at 400us to reliably sample the 1ms ON time. But because the WS2812 PWM frequency is 400 Hz, it refreshes at only 2.5ms which is way too slow leading to flickering.

I tested this theory on my setup by using the delay() function and sweeping from 1ms to 15ms. You can clearly see UNEVEN flickering from 1-6ms. Once you go above that, the flickering becomes much more evened out.

Hopefully anyone can correct my understanding here.

Nyquist_frequency

Better question (aka, it's a XY problem)

WHY do you want to strobe a strip at 100Hz and 10% duty?

And linked to that, do you really need RGB? Do you really need PWM? Do you really need 20 individual leds?

septillion: Better question (aka, it's a XY problem)

WHY do you want to strobe a strip at 100Hz and 10% duty?

And linked to that, do you really need RGB? Do you really need PWM? Do you really need 20 individual leds?

I'd like to strobe it that way because I'm designing a stroboscopy experiment where I am vibrating an object also at 100Hz +/- 2Hz to see it in slow motion forward/reverse/stop. The 10% duty is to briefly illuminate the vibrating object at its resonant frequency.

I need RGB mainly for aesthetic purposes so I can customize the color that is briefly illuminated on the object.

I need PWM because that's the input required for the RGB LED strip programming. I could easily put together a rig that uses standard LEDs... but then I'd lose out on the RGB programmability (and I'd also need to have 3 seperate LEDs per "bulb" enclosure).

I need 20 individual LEDs because I need as bright of a momentary exposure as I can get. Doing so with 1 LED will not provide sufficient illumination.

100Hz is no problem for WS2812s. You do not need to worry about PWM. The WS2812 generates it own PWM with the 24bit data you give it. If you have 400kHz parts, replace with 800kHz. The "library" may be your limiting factor (or not).

Edit: My head was in SK6812 mode (they are a little faster). 20 WS2812 may work but might leave you with little overhead for switching at 1mS. APA102 should be no problem.

How do you plan to sync the LEDs to the "object" vibration? Are you going to phase shift the object or the LEDs?

boolrules: How do you plan to sync the LEDs to the "object" vibration? Are you going to phase shift the object or the LEDs?

I use a potentiometer control to adjust the delay (phase) of the vibrating object. Because the vibration motor is just a simple DC motor of sorts, I can just PWM it.

The LEDs are not PWM from interface standpoint (as you mentioned, it is internal) so I have no control on its phase. All I can control here is its "duty" cycle (its not a real duty cycle though as you probably already know since it has its own protocol). What I'm really doing is essentially "blinking" the LEDs between WHITE and BLACK color by keeping it on BLACK 90% longer than it is on WHITE.

Though, I'm not sure what you mean about 100 Hz being no problem. If I am allowing only 1ms of WHITE color before switching it to 9ms of BLACK, the internal PWM samples at 2.5ms which means it may "miss" the WHITE cycle occasionally. The WS2812 is 400 Hz (not KHz). Did I understand that part incorrectly?

Nyte: I need 20 individual LEDs because I need as bright of a momentary exposure as I can get. Doing so with 1 LED will not provide sufficient illumination.

Alright, but do you need 20 individual controllable leds or are they all the same color?

If so, I t would say you're better of with a regular led strip.

so I have no control on its phase

The LED phase adjust would be the for the start of the 1ms/9ms period relative to system time -- nothing to do with the LEDs themselves. But since you are adjusting at the object, it's a non issue.

Though, I'm not sure what you mean about 100 Hz being no problem.

That was in reference to your thread title.

...internal PWM samples at 2.5ms which means it may "miss" the WHITE cycle occasionally.

I'm trying to test this now. Have you confirmed this?

"The WS2812 is 400 Hz (not KHz). " The datarate to the WS2812 is 400KHz, up to 800 KHz: "Send data at speeds of 800Kbps." Each display needs 24 bits of data. 20 LEDs need 480 bits of data. 480 bits/800000 bits/second = 600uS to send out. 100 Hz = 10,000uS. You can update the string 10,000/600 = 16+ times in each period of the 100 Hz duty cycle. Seems enough time to do the 10/90 duty cycle you started with.

PWM samples at 2.5ms which means it may “miss” the WHITE cycle occasionally.

Looks like this may be a true statement. I can visually see variations among individual LEDs. Not sure how badly this will affect your strobe spread over 20 LEDs. The effect does not appear to be synchronized LED to LED.

CrossRoads: "The WS2812 is 400 Hz (not KHz). " The datarate to the WS2812 is 400KHz, up to 800 KHz: "Send data at speeds of 800Kbps." Each display needs 24 bits of data. 20 LEDs need 480 bits of data. 480 bits/800000 bits/second = 600uS to send out. 100 Hz = 10,000uS. You can update the string 10,000/600 = 16+ times in each period of the 100 Hz duty cycle. Seems enough time to do the 10/90 duty cycle you started with.

The data rate input is 800 kbps but that is seperate from the PWM rate.

The PWM rate is 400 Hz (from Adafruit Neopixel source, CPLD blog, and FastLED authors). The datasheet is kind of vague on this but it mentions a "scan frequency" of 400Hz which those folks above understood to be its "PWM" rate.

It basically means that the data stream of pixel updates to each LED can be up to 800 kbps. However, the IC will "latch" in the complete 24bit data every 2.5ms (400Hz, it's refresh rate basically).

With 20 LEDs, there are 480 bits as you mentioned. The exact timing for each bit update is 1.25us based on the datasheet. That comes out to 480bits*1.25us/bit = 600us to update 20 LEDs total. There is also an additional 50us reset time after all the updates so it comes out to 650us.

The 650us is the time spent by the microcontroller to send out all 480 bits to the strip.

Regarding the data rate input of 800 kbps. I believe it means how fast the IC can latch in raw bit data.

To "strobe" at 100 Hz (it's not really a true PWM strobe since it's not a typical LED), what it really means is that the LED strip has a color change every 10ms. Applying 10/90 duty cycle means the color changes happen in a 1-9-1-9-1-9-1-9 ms interval. With a 1ms interval between color change, that violates the 2.5ms PWM (or "refresh") rate of the LED. Also, as @boolrules mentioned, it would require a Nyquist rate of at least 5ms (to be on the safe side, I think 8 or 9ms minimum to account for signal parasitics and delays).

boolrules:
Looks like this may be a true statement. I can visually see variations among individual LEDs. Not sure how badly this will affect your strobe spread over 20 LEDs. The effect does not appear to be synchronized LED to LED.

Yes, I don’t have a way to measure the refresh/PWM rate though as I don’t have access to a scope currently.

Also, I’m not sure exactly where the refresh/PWM happens since it’s internal to the IC on the LED.

Here is a reply from the FastLED library architect:

Don’t conflate data rate - which is how quickly you can push data to the leds with the led chipset’s own internal refresh rate and pwm clock which is a different thing. The refresh rate of the 2812s is only 400hz (so a full pwm cycle for a 2812 takes 2.5ms).

Also - ws2812’s get really unhappy if you update them more than 400 times per second - you get all sorts of weird flickering.

septillion:
Alright, but do you need 20 individual controllable leds or are they all the same color?

If so, I t would say you’re better of with a regular led strip.

I guess I don’t really need 20 individual controllable LEDs.

I’m assuming a “regular” LED strip only has power and ground. But I’m not sure where to actually find a regular LED strip these days. Also, using a regular LED strip would require additional electrical components (a resistor and a transistor) to properly PWM the power signal else I risk burning out the power pad.

With the controllable LED strip, the power input doesn’t need to be PWM’d through a microcontroller (though, the internal IC might PWM it on its own).

The chip is basically a WS2811 with internal LEDs vs external LEDs. If one could get their hands on a WS2811, perhaps the 400 Hz multiplexing between channels could be confirmed with a scope. I was thinking it had 3 output drivers, you put in 3 bytes and it updated the output when no data was seen passing thru after a gap; if you didn't update at 400 Hz, (sent 3 bytes too slow) then 3 bytes wouldn't get latched in. Never played with one tho, so the apparent multiplexing is news to me.

www.dipmicro.com has single color LED strips in several different colors.

Or, they used to. I only see green now. Try www.superbrightleds.com also.

Also, I'm not sure exactly where the refresh/PWM happens since it's internal to the IC on the LED.

Right, short of de-liding the part, there is no way to get to that. It is visually obvious, however. I guess you could get a light sensor and probe that output.There may also be an issue with the light rise/fall times that may not make this the best strobe light.

Nyte: I guess I don't really need 20 individual controllable LEDs.

I'm assuming a "regular" LED strip only has power and ground. But I'm not sure where to actually find a regular LED strip these days. Also, using a regular LED strip would require additional electrical components (a resistor and a transistor) to properly PWM the power signal else I risk burning out the power pad.

With the controllable LED strip, the power input doesn't need to be PWM'd through a microcontroller (though, the internal IC might PWM it on its own).

The individual controllable leds you also need a resistor in the signal path. Otherwise you have the risk to blow the first led. But yes, for a regular led strip you would need transistors. But if you grab a suitable mosfet (for 20 you really just need a tiny mosfet) no gate resistor required (as far as I go. Yes, we can have a huge discussion about it...)

And where to buy?! I don't know where you life but around here it's hard to just buy a individual controllable strip in a store but the normal strips are in every Dump/Dollar/Euro store in town. Even Ikea has them. And online both are easy to get and the normal strip is like 1/6 of the price.

And yeah, it makes the code sooooooo much easier. No worries about transfer timings etc. Just 3 PWM outputs... I would say that's more than worth it.

Nyte: Hi folks,

Using an Arduino UNO and WS2812 LED strip, I basically want to strobe at 100 Hz (10ms period per color update). On top of that, I also wanted to apply a 10/90 duty cycle factor so that comes out to 1ms for ON (color) time and 9ms for OFF (black) time.

Though, based on the 400 Hz (2.5ms period) upper limit of the WS2812, it seems that even if the Atmel+FastLED can send updates of show(color)-delay(1)-show(black)-delay(9), the WS2812 may "miss" some of those show(black) updates because of its 2.5ms period minimum. The previous delay(1) between the show(color) and show(black) is only ~1ms long while the WS2812 update period is 2.5ms so there could be unpredictable behavior (in my case, it seems to "flicker" unevenly). In addition to that, the WS2812 specification requires (X * 2.5us + 50us) worth of setup time where X is the number of LEDs in the strip. I intend to have 20 LEDs which means ~100us of setup overhead for each ON or OFF instance.

I looked around and it seems the APA102 may be able to do this with ease since its PWM is 20 KHz, way more than enough to handle it since its granularity is 50us.

Is my understanding correct here?

I am stuck in the similar case but mine is the ws2812 8*8 LED matrix. May I ask how can you know the maximum refreshing frequency is 400 Hz ?