Running PIO flat out?


Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4722
Posted: 03:59pm 30 Jan 2025      

Hi Kevin,

Here you go. This toggles GP0 at half the PIO clock speed.
Change the f0 value according your wishes.

 setpin gp0,PIO1
   
 PIO ASSEMBLE 1,".program toggle"
 pio assemble 1,".line 0"         'start line 0
 PIO ASSEMBLE 1,"set pindirs,1"   'set GPIO to output
 PIO ASSEMBLE 1,".wrap target"
 PIO ASSEMBLE 1,"set pins,0"      'set low
 PIO ASSEMBLE 1,"set pins,1"      'set high
 PIO ASSEMBLE 1,".wrap"           'wrap back to wrap_target
 PIO ASSEMBLE 1,".end program list"
 
 'configure pio1 StateMachine 0
 f0 = 133e6    '1MHz, change this to meet your need
 '              a b c d e f g   'a,e=side set   c,g=OUT  b,f=set
 p0 = Pio(PINCTRL 0,1,,,,GP0,)                  
 e0 = Pio(EXECCTRL GP0,Pio(.wrap target),Pio(.wrap))
 
 'write the configuration
 PIO init machine 1,0,f0,p0,e0,,0        'SM0 start at address 0
 PIO START 1,0
 
 do:loop


Theoretically you can set the PIO clock frequency to the same value as the ARM speed.
But if PIO can really do 400MHz I am not sure. Try it.
Another problem may be the IO pin that cannot toggle fast enough. At 200MHz, you may see a sine wave half the 3.3V amplitude. Becuase that is all the IO pin silicon can do.

Volhout

P.S. if you want to use a different GPIO pin, change the GP0 in PINCTRL. The one in EXECCTRL is a dummy, and can stay the same.
Edited 2025-01-31 02:14 by Volhout