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
Previous revision
raspberrypipico:pico_pio [2021/03/13 19:29]
admin [in(source, bitcount)]
raspberrypipico:pico_pio [2021/12/04 09:40] (current)
admin [Knowledge]
Line 17: Line 17:
 The RP2040 contains two **programmable IO blocks** with four **state machines** each, to control  GPIOs and to transfer data.\\ The RP2040 contains two **programmable IO blocks** with four **state machines** each, to control  GPIOs and to transfer data.\\
 {{:raspberrypipico:rp2040_diagram_for_a_single_pio_block.jpg?400|}}\\ {{:raspberrypipico:rp2040_diagram_for_a_single_pio_block.jpg?400|}}\\
 +
 +//diagram taken from the [[https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf|RP2040 Datasheet]]//\\
 +
 Each PIO block has one **instruction memory** with 32 instructions. Four read ports allows all state machine simultaneously access.\\ Each PIO block has one **instruction memory** with 32 instructions. Four read ports allows all state machine simultaneously access.\\
 Each state machine has:\\ Each state machine has:\\
Line 30: Line 33:
  
  
-//diagrams taken from the [[https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf|RP2040 Datasheet]]//\\+//diagram taken from the [[https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf|RP2040 Datasheet]]//\\
  
 ---- ----
Line 51: Line 54:
 **frequency** the frequency of the state machine, should be between 1000 and 125000000\\ **frequency** the frequency of the state machine, should be between 1000 and 125000000\\
  
-**GPIO pin** depending on the first on all following pins will be mapped (up to 32)\\+**GPIO pin** depending on the first one, all following pins will be mapped (up to 32)\\
 INPUT: in_base (sets input pins) INPUT: in_base (sets input pins)
    sm = StateMachine(0, do_something, freq=1000, in_base=pin10)    sm = StateMachine(0, do_something, freq=1000, in_base=pin10)
Line 152: Line 155:
    wait(0, pin, 0)    wait(0, pin, 0)
  
-====wait()====+====wait(option)====
 **wait(//polarity//, gpio, //num//)**\\ **wait(//polarity//, gpio, //num//)**\\
 It will waits until the specified GPIO has the specified polarity.\\ It will waits until the specified GPIO has the specified polarity.\\
Line 166: Line 169:
 - num (interrupt number, with rel the relative interrupt numbers could be used)\\   - num (interrupt number, with rel the relative interrupt numbers could be used)\\  
  
 +   wait(1, irq, rel(0))
  
 ====in(source, bits)==== ====in(source, bits)====
Line 178: Line 182:
 - 0-31 bits\\ - 0-31 bits\\
  
-====out(destination, bitcount)====+====out(destination, bits)====
 The OUT instructor shifts data from the output shift register (OSR) to the destination.\\ The OUT instructor shifts data from the output shift register (OSR) to the destination.\\
 **destination:**\\ **destination:**\\
Line 188: Line 192:
 - pc (shifts an instruction into the program counter)\\   - pc (shifts an instruction into the program counter)\\  
 - isr (into the input shift registers)\\ - isr (into the input shift registers)\\
-**bitcount:**\\+**bits:**\\
 - 0-31 bits\\ - 0-31 bits\\
  
Line 234: Line 238:
   mov(osr, x) #copy the x scratch register to the output shift register    mov(osr, x) #copy the x scratch register to the output shift register 
  
-====irq(option, irq_num, rel)====+====irq(option, num(rel))====
 The IRQ instruction sets or clears an interrupt flag.\\ The IRQ instruction sets or clears an interrupt flag.\\
 **option**\\ **option**\\
Line 240: Line 244:
 - wait (wait until the flag is zero before setting it)\\ - wait (wait until the flag is zero before setting it)\\
 - clear (clears the flag)\\ - clear (clears the flag)\\
-**irq_num**number of the interrupt 0-7\\ +**num** number of the interrupt 0-7\\ 
-**rel** relative IRQ number, can set different IRQ per StateMachine, ([1:0]+sm_number)%4 \\+**rel** relative IRQ number\\
 In the StateMachine In the StateMachine
    irq(block, rel(0))    irq(block, rel(0))
Line 278: Line 282:
    set(pins, 1) [31] #drive first mapped pin high and delay 31 cycles    set(pins, 1) [31] #drive first mapped pin high and delay 31 cycles
 ====nop()==== ====nop()====
-The NOP instruction stands for no operations. It can delays to 31 cycles.\\ +The NOP instruction stands for no operations. In combination with the delay function one can create delays between 1 to 31 cycles.\\ 
-   nop (31   #delay 31 cycles+   nop () [31]   #delay 31 cycles
  
 ====wrap()==== ====wrap()====
Line 324: Line 328:
  
 ---- ----
-===== Simple Audio Out===== 
  
-   GPIO03----4k--- 
-                  | 
-   GPIO04----2k---- 
-                  |------ Audio Out 
-   GPIO05----1k---- 
-                  | 
-   GPIO06----500--- 
  
----- 
-==== Resistor DAC ==== 
- 
- 
----- 
 ===== Knowledge ===== ===== Knowledge =====
 [[https://www.youtube.com/watch?v=yYnQYF_Xa8g|In-depth: Raspberry Pi Pico's PIO - programmable I/O!]] by stacksmashing\\ [[https://www.youtube.com/watch?v=yYnQYF_Xa8g|In-depth: Raspberry Pi Pico's PIO - programmable I/O!]] by stacksmashing\\
Line 346: Line 337:
 Stepper motor example on [[https://www.youtube.com/watch?v=UJ4JjeCLuaI| Youtube by Tinker Tech Trove]] and the code on [[https://github.com/tinkertechtrove/pico-pi-playing/tree/main/pio-steppers|Github]]\\ Stepper motor example on [[https://www.youtube.com/watch?v=UJ4JjeCLuaI| Youtube by Tinker Tech Trove]] and the code on [[https://github.com/tinkertechtrove/pico-pi-playing/tree/main/pio-steppers|Github]]\\
  
-[[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]]\\+[[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 _seeedstudio.com]]\\ 
 + 
 +[[https://medium.com/geekculture/serial-connection-between-raspberry-pi-and-raspberry-pico-d6c0ba97c7dc|Serial Connection between Raspberry Pi and Raspberry Pico bySebastian _medium.com]]\\ 
 + 
 +---- 
 +==== License ==== 
 + 
 +This manuals is made by **Wolfgang Spahn** 2021.\\ 
 +Except where otherwise noted, content on this wiki is licensed under the following license: [[http://creativecommons.org/licenses/by-nc-sa/4.0/"|Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License]].\\ 
 + 
 +<html> 
 +<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>  
 +</html>
  
 ---- ----