diff --git a/pio/pio_servo/README.adoc b/pio/pio_servo/README.adoc new file mode 100644 index 0000000..640713c --- /dev/null +++ b/pio/pio_servo/README.adoc @@ -0,0 +1,31 @@ += Using PIO to drive a servo motor +:xrefstyle: short + +Drive a servo motor by using two PIO statemachines for pulse output. + +== Wiring information + +See <> for wiring instructions. + +[[servo-wiring-diagram]] +[pdfwidth=75%] +.Wiring the servo to Pico +image::pio_servo.png[] + +== List of Files + +A list of files with descriptions of their function; + +pio_servo.py:: The example code, driving one servo + +== Bill of Materials + +.A list of materials required for the example +[[ring-bom-table]] +[cols=3] +|=== +| *Item* | *Quantity* | Details +| Breadboard | 1 | generic part +| Raspberry Pi Pico | 1 | http://raspberrypi.org/ +| Servo | 1 | generic part +|=== diff --git a/pio/pio_servo/pio_servo.fzz b/pio/pio_servo/pio_servo.fzz new file mode 100644 index 0000000..2ce594d Binary files /dev/null and b/pio/pio_servo/pio_servo.fzz differ diff --git a/pio/pio_servo/pio_servo.png b/pio/pio_servo/pio_servo.png new file mode 100644 index 0000000..d6bc404 Binary files /dev/null and b/pio/pio_servo/pio_servo.png differ diff --git a/pio/pio_servo.py b/pio/pio_servo/pio_servo.py similarity index 87% rename from pio/pio_servo.py rename to pio/pio_servo/pio_servo.py index b69a2a9..452dfe7 100644 --- a/pio/pio_servo.py +++ b/pio/pio_servo/pio_servo.py @@ -6,7 +6,7 @@ from time import sleep @asm_pio() def servo_trigger(): - irq(clear, rel(1)) # Clear next relative ISR, allows servo code to run again + irq(clear, rel(1)) # Clear next relative ISR, allows servo code to run again mov(y, x) # Counter is stored in x, copy to y for use label("base") jmp(y_dec, "base") # wait for programmed time @@ -32,7 +32,7 @@ def servo_prog(): class Servo_Trigger: ''' - Run one statemachine in a loop, that clears IRQ4 every 20ms as the + Run one statemachine in a loop, that clears IRQ every 20ms as the base for the servo statemachine. ''' def __init__(self, sm_idx): @@ -41,7 +41,7 @@ class Servo_Trigger: trig_frq = 10_000 #Hz sm_trig = StateMachine(sm_idx, servo_trigger, freq=trig_frq) - trig_ctr = (trig_frq // 1000 * trig_target) - 3 # 3 instructions to have perfect 20ms on IRQ4 + trig_ctr = (trig_frq // 1000 * trig_target) - 3 # 3 instructions to have perfect 20ms on IRQ sm_trig.put(trig_ctr) sm_trig.exec("pull()") @@ -51,8 +51,8 @@ class Servo_Trigger: class Servo: ''' Accepts the servo setpoint via FIFO input. - It raises and waits for IRQ4 after the positive part of the pulse has been output. - The other statemachine should clear IRQ4 every 20ms so that a new pulse is output cyclically. + It raises and waits for IRQ after the positive part of the pulse has been output. + The other statemachine should clear IRQ every 20ms so that a new pulse is output cyclically. Preload the ISR with the base duration (fixed pulse length for position 0°) Send position data via FIFO into the OSR (variable pulse length for 0°..max)