PWM with P1 for WS2811 LEDs
Hello,
P1/P2 Newb here.
I am following JonnyMac's demos and playing with the 50 LED lights that are controlled from the WS2811 chip with P2. Jon wrote the LED color driver in P2 PASM. I do not know PASM yet. I wanted to try and write my own PWM driver on the P1 in SPIN only. Was trying to stick with P1 SPIN for now, is just what I know so far.
I wrote some code and can modulate an output pin, but i'm finding that I can not achieve the speeds in the datasheet using P1 SPIN code. Takes too many counts with my code. The WS2811 speeds from the datasheet are as follows for PWM (one-wire):
0 code, high = 0.5 microseconds
0 code, low = 2.0 microseconds
1 code, high = 1.2 microseconds
1 code, low = 1.3 microseconds
Total is time is 2.5 microseconds for each bit
For 3 bytes (24 bits) it should take 60 microseconds. I have my P1 set at 80MHz clock speed with external oscillator.
My question for you...
1) Am I missing something or is it true that the P1 SPIN may not fast enough for this PWM timing? I'd like to continue pursuing making the driver in P1 SPIN, if possible.
2) Is this why people go to PASM to achieve higher speeds? Can I achieve the speeds above with P1 PASM?
I attached my spin file FYI. It basically runs a test PWM for two bits based on what the MSB is. The PWM is high for 1/2 sec and low for 1/2 sec.
Thanks for your help,
Nick
Comments
"is it true that the P1 SPIN may not fast enough for this PWM timing?"
Yes, it's true.
I think it's safe to say a Spin driver for the WS2811 isn't possible. I don't think it's close to fast enough.
thanks for your response! Yeah I was not very close on the timing. I'll check out P1 PASM.
Spin on the P1 is not fast enough, but PASM is. I've attached the P1 version of the P2 driver that I presented a few weeks ago.
jon, thanks! much appreciated. I'll review both your P1/P2 examples to help me learn PASM.
@Ludis Have you ever used '595 shift registers? They're relatively easy to use and in my opinion a great chip to control from PASM. Of course if the shift register was connected to some LEDs it would be all the more fun.
I think my first couple of PASM programs controlled shift registers. The '595 is a nice learning chip since a driver in Spin will work fine, it will just be slower than the PASM driver.
I once wrote a PASM PWM driver that works through '595 shift registers that was used by Disneyland and by a company that made road signs. The PWM is identical to the P2's sawtooth PWM mode.
I have not heard of or used '595 shift registers. Thank you I will look into it. Although my background is engineering, i'm not electrical or computer. I have a fundamental understanding of circuits and microcontrollers but drinking from the fire hose at the moment with all this cool new information. I'm working on a clock with segmented LEDs display and I'd like to connect the WS2811 LEDs from JonnyMac's demos to use as the "bell" which will do some light show on the hour and otherwise will be background lighting. So maybe this '595 might be applicable!
I purchased some LED drivers that use I2C that JonnyMac recommended from Adafruit. Looking forward to those coming in the mail.
I will look this '595 shift registers up! Much appreciated. Looking forward to those I2C segmented LED drivers coming in from Adafruit. Thanks for the recommendation!
Using those for a clock i'm working on. I wrote a clock algorithm in P1. Maybe I can use the RTC from your demos as well! So many things to learn! lol