Using PIO of Raspberry Pi Pico
by Manodeep in Circuits > Raspberry Pi
3204 Views, 0 Favorites, 0 Comments
Using PIO of Raspberry Pi Pico
PIO is programmable in the same sense as a processor. There are two PIO blocks with four state machines each, that can independently execute sequential programs to manipulate GPIOs and transfer data. Unlike a general-purpose processor, PIO state machines are highly specialized for IO, with a focus on determinism, precise timing, and close integration with fixed-function hardware. Each state machine is equipped with:
• Two 32-bit shift registers – either direction, any shift count
• Two 32-bit scratch registers
• 4×32-bit bus FIFO in each direction (TX/RX), reconfigurable as 8×32 in a single direction
• Fractional clock divider (16 integers, 8 fractional bits)
• Flexible GPIO mapping
• DMA interface, sustained throughput up to 1 word per clock from system DMA
• IRQ flag set/clear/status
Each state machine, along with its supporting hardware, occupies approximately the same silicon area as a standard serial interface block, such as an SPI or I2C controller. However, PIO state machines can be configured and reconfigured dynamically to implement numerous different interfaces.
Supplies
1.Raspberry Pi Pico
2.LED
3.Jumper Wire
Connect LED With Pi Pico According to the Diagram
Connect the Pi Pico With PC and Run the Following Code.
import utime import rp2 from machine import Pin # Define the blink program. It has one GPIO to bind to on the set instruction, which is an output pin. # Use lots of delays to make the blinking visible by eye. @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) def blink(): wrap_target() set(pins, 1) [31] nop() [31] nop() [31] nop() [31] nop() [31] set(pins, 0) [31] nop() [31] nop() [31] nop() [31] nop() [31] wrap() # Instantiate a state machine with the blink program, at 2000Hz, with set bound to Pin(15) (you can change the Pin number according to your needs) sm = rp2.StateMachine(0, blink, freq=2000, set_base=Pin(15)) # Run the state machine for 3 seconds. The LED should blink. while True: print("Starting state machine.....") sm.active(1) utime.sleep(1) print("Stopping state machine.....") sm.active(0) utime.sleep(1)
Downloads
Output
For more information on the PIO of RP2040 go to the following link :
https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf refer to page 330.