Add documentation, clean up comments
rodzic
e649f521f9
commit
b11ff90f0b
|
@ -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 <<servo-wiring-diagram>> 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
|
||||
|===
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 228 KiB |
|
@ -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)
|
Ładowanie…
Reference in New Issue