Page 4 of 4

Re: SK6812 LED

Posted: Thu Apr 04, 2024 12:15 pm
by mnfisher
Can you try the attached - just outputs a colour (255) to each of RG and B then repeats - note that if you don't have the RGBW variant (I don't) then setting W to 0 is okay... (Note I use D7 as the output pin - you'll need to change this to suit)
test_rgb.fcfx
(12.69 KiB) Downloaded 40 times
Martin

Re: SK6812 LED

Posted: Thu Apr 04, 2024 3:29 pm
by ChrisT66
Yes the processor runs at 8MHz (maximum of the internal oscillator)
Nice of you to help and try this, thanks :)

Re: SK6812 LED

Posted: Thu Apr 04, 2024 3:34 pm
by ChrisT66
Loaded the project test_rgb, unfortunately as always only a white LED :(

Re: SK6812 LED

Posted: Thu Apr 04, 2024 4:01 pm
by kersing
Probably a stupid question but what is the power up state of the LED? Is it not lit if you use a flowchart that doesn’t have any macros related to it? (So an empty flowchart with just a loop doing nothing)

Re: SK6812 LED

Posted: Thu Apr 04, 2024 6:51 pm
by mnfisher
I've tested using an ATMega8 - running at 16MHz (with external crystal) - LED lights all good and at 8MHz (internal)- not good.

Checking on a scope - the timings look 'out' when running at 8MHz - and in fact altering the clock speed - seems to generate the same number of nops (for example setting it to 1MHz and 20Mhz generates the same code)

It should be possible to 'tweak' the ATTiny code I posted above to work - I think 8MHz is fast enough (just!) to give the required timings..

Martin

Re: SK6812 LED

Posted: Thu Apr 04, 2024 10:26 pm
by mnfisher
Okay a bit of a play - and a version running on an 8MHz MCU.

There is an issue - the pin used is hardcoded here as D7. If you want to change it then you'll need to change the output at the start of main (this sets the pin to be an output and should really be done by setting DDRx etc). And the occurrences in Refresh - here I buffer the values of PORTD (as ph (for bit 7 set) and pl for bit 7 cleared.
Then these values are written to PORTD to set the pin high or low. (for example for pin C5 use PORTC and 0b10000. Timing is tight - for TOH (there is more leeway on other values) - here I just set the pin high then low.

The demo just sets the LED to RED, GREEN, BLUE for 5s each. Then repeats.

You can specify the number of pixels (up to 10 if they have 3 bytes each) and number of bytes per pixel (3 or 4). buf could be made larger for more pixels.

SetLED has no facility to set the white component - but it is easy to add if needed (and may be a random value if rgbw specified)

I haven't tested with more than one LED though :-)
test_rgb2.fcfx
(13.95 KiB) Downloaded 12 times

Martin

Re: SK6812 LED

Posted: Fri Apr 05, 2024 11:01 am
by mnfisher
Now tested with 2 LEDs and seems to work AOK (I have a few 'single' LEDs with nice sockets / plugs - so adding extra is easy!) - which bodes well for multiple.
I think I have a 1m of these somewhere (RGBW) - which I will try and find to test further.

Martin

Re: SK6812 LED

Posted: Fri Apr 05, 2024 10:48 pm
by mnfisher
With a little bit of tuning - now working with a 1 metre strip (they turned out to be RGB as well)

I hit a very strange effect.

If if Refresh I do for a 0 bit.

PORTD = ph;
PORTD = pl;

Then if I do the same for a 1 bit with a few nops. Then it is slower (for the 0 bit) than doing PORTD |= 0x80; PORTD &= @0x80; But if I have The code for a 0 using ph and pl then it needs a nop() (a high pulse lasts 120ns) IF the code for 1 uses the | and & to set and clear the pin. An odd quirk of the C code generator?
ie - if I use different methods to set / clear the pin in the code for the 0 and 1 bit the code runs much faster (and allows correct timing for the 0 bit)
test_rgb2.fcfx
(16.31 KiB) Downloaded 13 times
Martin