|
9 | 9 |
|
10 | 10 | @asm_pio()
|
11 | 11 | 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 |
16 | 14 |
|
17 | 15 | wait(1, pin, 0) # wait for a full PWM cycle to start measurement
|
18 | 16 | wait(0, pin, 0) # wait for pin to be low
|
19 | 17 |
|
20 | 18 | 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 |
23 | 21 | label("out_low")
|
24 | 22 |
|
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 |
27 | 25 |
|
28 | 26 | label("count_high")
|
29 | 27 | jmp(x_dec, "next") # count down X, jump to next instruction
|
30 | 28 | label("next")
|
31 | 29 | jmp(pin, "count_high") # as long as the pin is high, jump back up to continue countdown
|
32 | 30 |
|
33 |
| - mov(isr, x) # move x into ISR |
| 31 | + mov(isr, x) # move x into ISR for outputting the total period of the signal |
34 | 32 | push(noblock) # push into fifo
|
35 |
| - irq(0) # Signal IRQ (optional, may be used for 0%/100% detection |
| 33 | + irq(0) |
36 | 34 |
|
37 | 35 | base_frq = 100_000_000
|
38 | 36 | sm = rp2.StateMachine(0, pwmin, freq=base_frq, jmp_pin=Pin(16), in_base=Pin(16))
|
|
0 commit comments