I'm working on a simple stepper motor driver with a very basic behaviour:
1. Send pulse to A4988
2. Wait for a specified delay
3. Repeat
Here is my code:
Code: Select all
import time
import rp2
from machine import Pin
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def stepper():
pull(noblock) # pull new data or recycle x value
mov(x, osr)
mov(y, x) # copy x into y to be able to reset later
# jmp(not_x, "end") # this always jumps to the end
irq(0)
set(pins, 1)
set(pins, 0)
label("delay")
jmp(x_dec, "delay")
mov(x, y) # x is zero now, so restore its value from y
label("end")
def turn(sm):
print("irq")
sm = rp2.StateMachine(0, stepper, freq=10000, set_base=Pin(25))
sm.irq(turn)
sm.put(10000)
sm.active(1)
print("moving")
time.sleep(5)
print("faster")
sm.put(5000)
time.sleep(5)
print("even faster")
sm.put(1000)
time.sleep(5)
sm.active(0)
Now I want to implement stop functionality - just send 0 with sm.put(0) and jump straight to the end if value is zero, skipping the pin triggering and waiting.
But if I put:
Code: Select all
jmp(not_x, "end")
Why is that? I thought this would only jump if x is set to 0, but it always jumps to the end, even if it's not.
Am I misunderstanding what jmp(not_x, "end") is supposed to do?