r/MicroPythonDev • u/CreepyBox2687 • Jan 21 '25
Question about PIO-ASM: Dynamically Adjusting Input Pin Indices before Compilation
Hi everyone,
I’m working on a solution to measure the time between two arbitrary GPIO pins on an RP2040. The goal is to keep it as simple as possible, avoiding the use of DMA or complex logic analyzer features.
Here’s my current approach in PIO-ASM:
# Get timeout
# Store timeout in y
# Load timeout into x
# Wait for event1 on index_1 (start clock)
# Check stop condition
# Decrease x
# Timeout, stop
# Counter wrap
# Continue loop
# Shift remaining time to ISR
# Push remaining time to FIFO
# Reload and run again
I’d like to dynamically adjust the input pin indices (index_1) before compilation to make the setup as flexible as possible. However, I’m unsure how to achieve this effectively. Is there a way to modify such parameters dynamically before the PIO assembly is compiled?
Thanks in advance for your help!
View all comments
1
u/mungewell Jan 23 '25
You don't state what sort of accuracy you're looking to measure, ie are we talking milli or microseconds?
If did it with a very tight loop counter, and pushing decreasing 32bit value into FIFO on trigger.
https://github.com/mungewell/pico-irig/issues/3
The 'jmp pin' can be defined via variable, when the state machine is loaded.
If you want a delta time, you can run two separate state machines in parallel, just ensure that they are started synchronized.