Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
raspberrypipico:raspberrypipico [2021/03/12 13:10]
admin [Programmable I/O]
raspberrypipico:raspberrypipico [2021/03/12 13:21]
admin [Programmable I/O]
Line 107: Line 107:
 ==== Programmable I/O ==== ==== Programmable I/O ====
 [[raspberrypipico:pico_pio|Programmable I/O]]\\ [[raspberrypipico:pico_pio|Programmable I/O]]\\
- 
----- 
-[[https://www.youtube.com/watch?v=yYnQYF_Xa8g|In-depth: Raspberry Pi Pico's PIO - programmable I/O!]] by stacksmashing\\ 
-The RP Pico has eight state machines (0-7) including these parameters:\\ 
-- state machine number\\ 
-- PIO program\\ 
-- frequency (between 2000 and 125000000)\\ 
-- GPIO pin\\ 
-These mini programs run on the PIO state machines and run continuously.\\ 
- 
-  from rp2 import PIO, StateMachine, asm_pio 
-  from machine import Pin 
-  import utime 
-   
-  led_onboard = machine.Pin(25, machine.Pin.OUT) 
-  led_onboard.value(1) 
-  utime.sleep(2) 
-  led_onboard.value(0) 
-   
-  @asm_pio(set_init=PIO.OUT_LOW) 
-  def faint_led(): 
-    set(pins, 0) [20] 
-    set(pins, 1) 
-   
-  sm1 = StateMachine(1, faint_led, freq=10000, set_base=Pin(25)) 
-   
-  while(True): 
-    sm1.active(1) 
-    utime.sleep(1) 
-    sm1.active(0) 
-    utime.sleep(1) 
- 
-The commands set(pins, 0) and set(pins, 1) turns the GPIO pin on and off.\\ 
-In square brackets are numbers between 1 and 31 to pause this clock cycles\\ 
-The @asm_pio descriptor above the function takes the set_init parameters.\\ 
-To start and stop the state machine use the active method (1 or 0)\\ 
- 
-==The Nine State Machine Instructions== 
-  * in – Shifts 1 word of 32 bits at a time into the ISR 
-  * out – Shifts 1 word of 32 bits from the OSR e.g. out(pins, 4) 
-  * push – Sends data to the RX (input) 
-  * pull() – gets data from the TX (output),e.g. sm1.put(1234) 
-  * mov() – moves data x or y in register, e.g. mov(y, osr) osr=output shift register 
-  * irq – Sets or clears interrupt flag e.g. irq(rel(0)) in python: sm.irq(myFunction) 
-  * set() [] – Writes data to destination, 0=off, 1=on, delays 0 to 31 circles 
-  * wait – Pauses until a defined action happens 
-  * label("mylabel") and jmp (condition,"label") – Jumps to a different point in the code 
-==Some more Instructions== 
-- nop () [] - no operations, delays 0 to 31 circles\\ 
-- wrap_target() and wrap () - resets program counter and starts over again\\ 
-- lable() - sts a lable label("end")\\ 
-- jmp () - jumps conditions:\\ 
- _ jump if zero: jmp(not_x, "end")\\ 
- _ shift the register, jump if not exhausted: jmp(not_osre, "lable1")\\ 
- _ decrements, jump if not zero: jmp(x_dec,"label2")\\ 
- 
-Example by [[https://www.youtube.com/watch?v=UJ4JjeCLuaI| Tinker Tech Trove 
-]] and on [[https://github.com/tinkertechtrove/pico-pi-playing/tree/main/pio-steppers|Github]]\\ 
- 
-[[https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf|RP2040 Datasheet]], Chapter 30, page 330 following\\ 
- 
-[[https://www.seeedstudio.com/blog/2021/01/25/programmable-io-with-raspberry-pi-pico/|Seeedstudio: Programmable I/O with Raspberry Pi Pico by Jonathan Tan]]\\ 
  
 ---- ----