from machine import Pin
import rp2
# Configure the PIO program to create 32 ns timing differences
@rp2.asm_pio(
sideset_init=(rp2.PIO.OUT_LOW, rp2.PIO.OUT_LOW), # Initialize both GPIO pins to low
out_shiftdir=rp2.PIO.SHIFT_LEFT
)
def pwm_32ns_dual():
# Pulse A: Set pin high for 32 ns, then low for the rest of the period
set(pins, 1) [0] .sideset(1) # Pulse A on (32 ns)
set(pins, 0) [399999] # Pulse A off for remainder of 20 ms
# Pulse B: Delay by 32 ns, then set pin high for the rest of the period
nop() [0] .sideset(0) # Pulse B off for 32 ns delay
set(pins, 1) [399999] .sideset(1) # Pulse B on for remainder of 20 ms
# Repeat every 20 ms (50 Hz)
wrap_target()
wrap()
# Set up the state machine at 50 Hz frequency (20 ms period)
sm_freq = 50 # Set frequency to achieve 50 Hz
# Initialize the state machine on GPIO 0 (Pulse A) and GPIO 1 (Pulse B)
sm = rp2.StateMachine(0, pwm_32ns_dual, freq=sm_freq, sideset_base=Pin(0))
# Start the state machine
sm.active(1)
# Run indefinitely
while True:
pass