SK6812 LED

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 962
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: SK6812 LED

Post 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 7 times
Martin

ChrisT66
Posts: 37
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: SK6812 LED

Post by ChrisT66 »

Yes the processor runs at 8MHz (maximum of the internal oscillator)
Nice of you to help and try this, thanks :)

ChrisT66
Posts: 37
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: SK6812 LED

Post by ChrisT66 »

Loaded the project test_rgb, unfortunately as always only a white LED :(

kersing
Valued Contributor
Posts: 158
Joined: Wed Dec 02, 2020 7:28 pm
Has thanked: 66 times
Been thanked: 58 times

Re: SK6812 LED

Post 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)

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: SK6812 LED

Post 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

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: SK6812 LED

Post 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 7 times

Martin

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: SK6812 LED

Post 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

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: SK6812 LED

Post 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 5 times
Martin

Post Reply