0

I want to run the same SM (state machine) program on all 8 available SM in the RP2040, but I ran into a small problem trying to get them to run exactly synchronized while using the clock divider.

This is easy when you only use one PIO: pio_enable_sm_mask_in_sync(). The problem is that you can't do this for both PIO:

pio_enable_sm_mask_in_sync(pio0,0xF);
pio_enable_sm_mask_in_sync(pio1,0xF);

Even if there is only one machine cycle between these calls, PIO0 will start ticking before PIO1.

I can have them wait for an event:

wait 1 gpio 21
set pins 1

If this code is loaded on every SM in both PIOs, each SM having a unique pin mapping, I would like to see this:

         GPIO21 _____/‾‾‾‾‾‾‾‾
PIO0 SM0 GPIO01 _________/‾‾‾‾
PIO0 SM1 GPIO02 _________/‾‾‾‾
PIO0 SM2 GPIO03 _________/‾‾‾‾
PIO0 SM3 GPIO04 _________/‾‾‾‾
PIO1 SM0 GPIO05 _________/‾‾‾‾
PIO1 SM1 GPIO06 _________/‾‾‾‾
PIO1 SM2 GPIO07 _________/‾‾‾‾
PIO1 SM3 GPIO08 _________/‾‾‾‾

However, with the clock divider enabled, I think I will see something like this:

         GPIO21 _____/‾‾‾‾‾‾‾‾
PIO0 SM0 GPIO01 _________/‾‾‾‾
PIO0 SM1 GPIO02 _________/‾‾‾‾
PIO0 SM2 GPIO03 _________/‾‾‾‾
PIO0 SM3 GPIO04 _________/‾‾‾‾
PIO1 SM0 GPIO05 __________/‾‾‾
PIO1 SM1 GPIO06 __________/‾‾‾
PIO1 SM2 GPIO07 __________/‾‾‾
PIO1 SM3 GPIO08 __________/‾‾‾

That is, even if they start at the same time, the clock divider's phase will be slightly different between each PIO.

Can someone think of a way to solve this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.