File tree 1 file changed +12
-9
lines changed
1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change 8
8
import microcontroller
9
9
import adafruit_pioasm
10
10
11
- # NeoPixels are 800khz bit streams. Zeroes are 1/3 duty cycle (~416ns) and ones
12
- # are 2/3 duty cycle (~833ns).
11
+ # NeoPixels are 800khz bit streams. We are choosing zeros as <312ns hi, 936 lo> and ones
12
+ # and ones as <700 ns hi, 556 ns lo>.
13
+ # cycle. The first two instructions always run while only one of the two final
14
+ # instructions run per bit. We start with the low period because it can be
15
+ # longer while waiting for more data.
13
16
program = """
14
17
.program ws2812
15
18
.side_set 1
16
19
.wrap_target
17
20
bitloop:
18
- out x 1 side 0 [1 ]; Side-set still takes place when instruction stalls
19
- jmp !x do_zero side 1 [1 ]; Branch on the bit we shifted out. Positive pulse
20
- do_one:
21
- jmp bitloop side 1 [1 ]; Continue driving high, for a long pulse
22
- do_zero:
23
- nop side 0 [1 ]; Or drive low, for a short pulse
21
+ out x 1 side 0 [6 ]; Drive low. Side-set still takes place before instruction stalls.
22
+ jmp !x do_zero side 1 [3 ]; Branch on the bit we shifted out previous delay. Drive high.
23
+ do_one:
24
+ jmp bitloop side 1 [4 ]; Continue driving high, for a one ( long pulse)
25
+ do_zero:
26
+ nop side 0 [4 ]; Or drive low, for a zero ( short pulse)
24
27
.wrap
25
28
"""
26
29
35
38
36
39
sm = rp2pio .StateMachine (
37
40
assembled ,
38
- frequency = 800000 * 6 , # 800khz * 6 clocks per bit
41
+ frequency = 12_800_000 , # to get appropriate sub-bit times in PIO program
39
42
first_sideset_pin = NEOPIXEL ,
40
43
auto_pull = True ,
41
44
out_shift_right = False ,
You can’t perform that action at this time.
0 commit comments