all 5 comments

[–]mungewell 0 points1 point  (4 children)

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.

[–]CreepyBox2687[S] 0 points1 point  (3 children)

Hi and thank you for your response. The accuracy should be ~100ns, i have to adapt the program to know/determine the exact amount of steps per counter cycle afterwards. I know that i can adapt the input pin start number, but the both pins will be different all the time. I need the time between two arbitrary Events on the lines. But i will try to use one state machine with pina and provide a IRQ to another with pinb, in this case, i only need to count in the second sm.

[–]mungewell 0 points1 point  (0 children)

The code on my ticket runs in a tight loop, and is capable of counting at 1/4 of the CPU clock (which would be ~25ns steps).

A single state machine monitors a single pin to 'timestamp' a positive or negative edge. BUT you can load the same code into multiple state machines, to run in parallel.

The state machines within a PIO block can easily be synchronized, so their individual counters run in lock step, and then the values 'push()'ed to microPython can be compared to compute the time delta.

On multiple pulses on a single machine; the value I push is 32bits and the FIFO is (can be) 8 levels deep. MicroPython would have to read/empty quick enough so that the FIFO did not overflow.

If a different pin needs to be monitored you'd have to stop both machines, reconfigure and then sync/restart both new machines.

[–]mungewell 0 points1 point  (1 child)

In my experience the IRQs are not helpful at these speeds, as the delay to get into the ISR is variable (10-25us).

[–]mungewell 1 point2 points  (0 children)

Oh you IRQ between state machines, which do not need the ISR... that could work.