Skip to content

Commit ccbbf02

Browse files
committed
Merge set(x,0) and mov(x, invert(x)) into a single instruction
Thanks to @lurch for finding this.
1 parent 91da8c9 commit ccbbf02

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

pio/pio_pwmin.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,28 @@
99

1010
@asm_pio()
1111
def pwmin():
12-
pull(block) # wait for activation
13-
14-
set(x, 0) # Set x = 0
15-
mov(x, invert(x)) # invert x = Max-Value for 32 bits
12+
pull(block) # wait for activation by doing a blocking pull on the input
13+
mov(x, invert(null)) # invert(null) = Max. 32 Bit value
1614

1715
wait(1, pin, 0) # wait for a full PWM cycle to start measurement
1816
wait(0, pin, 0) # wait for pin to be low
1917

2018
label("count_low")
21-
jmp(pin, "out_low") # jump to output if pin is high
22-
jmp(x_dec, "count_low") # jump back to count loop, decrement X
19+
jmp(pin, "out_low") # jump to output if pin is high
20+
jmp(x_dec, "count_low") # jump back to count loop, decrement X
2321
label("out_low")
2422

25-
mov(isr, x) # move x into ISR
26-
push(noblock) # push into fifo
23+
mov(isr, x) # move x into ISR for outputting low counter of PWM signal
24+
push(noblock) # push into fifo
2725

2826
label("count_high")
2927
jmp(x_dec, "next") # count down X, jump to next instruction
3028
label("next")
3129
jmp(pin, "count_high") # as long as the pin is high, jump back up to continue countdown
3230

33-
mov(isr, x) # move x into ISR
31+
mov(isr, x) # move x into ISR for outputting the total period of the signal
3432
push(noblock) # push into fifo
35-
irq(0) # Signal IRQ (optional, may be used for 0%/100% detection
33+
irq(0)
3634

3735
base_frq = 100_000_000
3836
sm = rp2.StateMachine(0, pwmin, freq=base_frq, jmp_pin=Pin(16), in_base=Pin(16))

0 commit comments

Comments
 (0)