Skip to content

Commit 3a9a028

Browse files
committed
match the latest core code
1 parent 89e2dfa commit 3a9a028

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

examples/pioasm_neopixel.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@
88
import microcontroller
99
import adafruit_pioasm
1010

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.
1316
program = """
1417
.program ws2812
1518
.side_set 1
1619
.wrap_target
1720
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)
2427
.wrap
2528
"""
2629

@@ -35,7 +38,7 @@
3538

3639
sm = rp2pio.StateMachine(
3740
assembled,
38-
frequency=800000 * 6, # 800khz * 6 clocks per bit
41+
frequency=12_800_000, # to get appropriate sub-bit times in PIO program
3942
first_sideset_pin=NEOPIXEL,
4043
auto_pull=True,
4144
out_shift_right=False,

0 commit comments

Comments
 (0)