Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very buggy for 35762-OP LED - help needed #17

Closed
luccadibe opened this issue Dec 23, 2023 · 2 comments
Closed

Very buggy for 35762-OP LED - help needed #17

luccadibe opened this issue Dec 23, 2023 · 2 comments

Comments

@luccadibe
Copy link

I'm trying to run the examples on a Pi Pico W with an array of 10 LEDs (https://www.mpja.com/download/35762opdata.pdf) .
I thought these are compatible with this library. Maybe they aren't?

When I run the rainbow.py example , it runs OK the first time, then all leds bug out, flicker and for some reason stay red.
The brightness function also seems not to work at all.

Congratulations on the project, really cool idea.

@blaz-r
Copy link
Owner

blaz-r commented Dec 23, 2023

Hello. Looking at the diagrams, I'm not sure this library is really compatible.
These are the timings from your pdf:
image

these are from ws2812b:
image
so you'd need to tune the state automaton program, to suit these timings, which might not be that easy since the one existing is already a bit imprecise on timing:

# PIO state machine for RGB. Pulls 24 bits (rgb -> 3 * 8bit) automatically
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)
def ws2812():
T1 = 2
T2 = 5
T3 = 3
wrap_target()
label("bitloop")
out(x, 1) .side(0) [T3 - 1]
jmp(not_x, "do_zero") .side(1) [T1 - 1]
jmp("bitloop") .side(1) [T2 - 1]
label("do_zero")
nop() .side(0) [T2 - 1]
wrap()

There is some code I have written a while ago that you can probably adjust for your timings. First you'll need to use state machine with following frequency to get 10ns cycles:

rp2.StateMachine(state_machine, ws2812_update, freq=100_000_000, sideset_base=Pin(pin))

instead of these two here:

self.sm = rp2.StateMachine(state_machine, sk6812, freq=8000000, sideset_base=Pin(pin))
# tuple of values required to shift bit into position (check class desc.)
self.shift = ((mode.index('R') ^ 3) * 8, (mode.index('G') ^ 3) * 8,
(mode.index('B') ^ 3) * 8, (mode.index('W') ^ 3) * 8)
else:
self.sm = rp2.StateMachine(state_machine, ws2812, freq=8000000, sideset_base=Pin(pin))

then the timings adjusted for cycles in the following program
#T0H = 35-> 6 * 5
#T0L = 136 -> ~ 27 * 5

#T1H = 136-> 27 * 5
#T1L = 35-> 6 * 5

so I think a final PIO program would look like this:

# PIO state machine for RGB. Pulls 24 bits (rgb -> 3 * 8bit) automatically
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)
def ws2812_update():
    #T0H = 35->  6 * 5
    #T0L = 136 -> ~ 27 * 5

    #T1H = 136-> 27 * 5
    #T1L = 35-> 6 * 5

    # every cycle is 10ns
    # nop() [2] takes 5 cycles
    
    # when using set(y, num), num is 1 less than the actual number of cycles
    # because jmp(y_dec, label) check for 0

    wrap_target()
    label("bitloop")
    out(x, 1)                       .side(1)
    jmp(not_x, "zero")              .side(1)
    
    ## ONE ------------------------------------
    label("one")

    #T1H
    set(y, 26)
    label("one_high_loop")
    nop()                           .side(1)    [2]
    jmp(y_dec, "one_high_loop")     .side(1)    [1]

    #T1L
    set(y, 5)
    label("one_low_loop")
    nop()                           .side(0)    [2]
    jmp(y_dec, "one_low_loop")      .side(0)    [1]

    jmp("bitloop")                  .side(0)

    ## ZERO ------------------------------------

    label("zero")    

    #T0H
    set(y, 5)
    label("zero_high_loop")
    nop()                           .side(1)    [2]
    jmp(y_dec, "zero_high_loop")    .side(1)    [1]

    #T0L
    set(y, 26)
    label("zero_low_loop")
    nop()                           .side(0)    [2]
    jmp(y_dec, "zero_low_loop")     .side(0)    [1]

    wrap()

I can't really verify this, and it's been a while since I've written this 😅 but it could work.

Hope this helped.

@luccadibe
Copy link
Author

Thank you so much for you quick answer! I'll test it and try to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants