Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:51 07 Feb 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Running PIO flat out?

Author Message
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 534
Posted: 03:28pm 30 Jan 2025
Copy link to clipboard 
Print this post

A question for our resident PIO experts, probably Peter or Harm.
I've just splashed out on a second hand 200MHz Oscilloscope and I'm trying to generate a 200MHz signal, or there about to test it with.
I have managed to use the Pico SDK to build an executable, which is overclocked to 428MHz toggling a GPIO pin flat out, I get a nice 107MHz signal, which the scope displays fine. (zip file below)
Is there a way of getting the PIO under MMBasic to do something similar, preferably higher frequency, closer to 200MHz. Even better a variable frequency, up to as high as possible. I realise the step size is likely to be relatively large, but a selection of test frequencies would be nice? maybe a selection of power of 2 frequencies on adjacent pins? Any thoughts?
Thanks in anticipation. :-) Kevin.
FastToggle.zip
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7106
Posted: 03:49pm 30 Jan 2025
Copy link to clipboard 
Print this post

At full speed a PIO state machine can carry out 1 instruction per CPU clock cycle. I suppose that will mean one instruction to set a pin, one to reset it and one to jump back to the first instruction. That would, I think, give a pin that clocked at a maximum of CLK/3 Hz. 142.66MHz.

Now, there are instructions that can actually do two things in one clock cycle (side set etc.). I'm not well up enough on the PIO to be able to help there. It could be that the reset and jump back could be combined.

Note. If a state machine hits the end of it's memory area it automatically jumps back to its start point, so if you put the set instruction at the start point and the end instruction as the last instruction in memory it should toggle at CLK/2, I think.

.
Edited 2025-01-31 01:52 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4527
Posted: 03:59pm 30 Jan 2025
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7106
Posted: 04:19pm 30 Jan 2025
Copy link to clipboard 
Print this post

Ah, that is the question! Can you get 400MHz out of a component specified at a normal speed of 150MHz?  :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 534
Posted: 04:33pm 30 Jan 2025
Copy link to clipboard 
Print this post

Hi Harm,
That was quick, I'll give it a go. Thanks very much. :-)

Hi Mick,
I only need it to do 200Mhz, but even at 107, it's already fairly sinusoidal, so it may/or not cope.
Regards Kevin.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7106
Posted: 05:00pm 30 Jan 2025
Copy link to clipboard 
Print this post

Have you set up your probe using the square wave from the scope? Better check it anyway. Also, with those edge times, you need the short GND wire from the probe tip.
Edited 2025-01-31 03:01 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1024
Posted: 07:44pm 30 Jan 2025
Copy link to clipboard 
Print this post

I wonder if a 74HC14 Schmitt-Trigger would help?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2281
Posted: 08:55pm 30 Jan 2025
Copy link to clipboard 
Print this post

It may help, especially if the 74HC14 is close to the Pico.
The output resistance of the Pico pins is 40 - 50Ω so driving the scope input capacitance may contribute to the rounding.

Edit.
An odd thing.
Tried the program above but using FIN to show the output (Pico2 VGA beta 5) and the Pico freezes when PIO output is connected to FIN. Unplug the link and it resumes running.

Tried various CPU speeds, PIO speeds and FIN sampling times but always same result.
> option list
PicoMiteVGA MMBasic RP2350A Edition V6.00.02b5
OPTION SYSTEM I2C GP14,GP15
OPTION FLASH SIZE 4194304
OPTION COLOURCODE ON
OPTION KEYBOARD US
OPTION DEFAULT MODE 3
OPTION DISPLAY 60, 133
OPTION SDCARD GP13, GP10, GP11, GP12
> RUN
0: E081
1: E000
2: E001
0
0   <---------Heartbeat and program stop when GP0 linked to GP7, resume when removed
0
0
0
>
> LIST
SetPin gp7,FIN,10
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 = 63e6    '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
 Pause 2000
 Print Pin(GP7)
Loop
>

Edit 2
FIN works ok when linked to a PWM pin.
Edited 2025-01-31 08:05 by phil99
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1024
Posted: 10:10pm 30 Jan 2025
Copy link to clipboard 
Print this post

On the RP2350, GP0 supports the new-ish FFIN

What happens if you flip the roles?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2281
Posted: 10:30pm 30 Jan 2025
Copy link to clipboard 
Print this post

Yes, it works with SETPIN GP1,FFIN
With CPU and PIO speed 378MHz FFIN reads 189MHz.

Edit. I should have read the manual!
Edited 2025-01-31 08:37 by phil99
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1024
Posted: 11:00pm 30 Jan 2025
Copy link to clipboard 
Print this post

  phil99 said  Yes, it works with SETPIN GP1,FFIN


Ah, had it in my head that it was GP0 but I looked at my new board layout and sure-enough, I have it routed to GP1  
 
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 534
Posted: 02:27pm 03 Feb 2025
Copy link to clipboard 
Print this post

Hi Harm,
Thanks very much for the PIO Frequency test program, I can confirm the PIO on my 2040  will run at full clock frequency at 420MHz.
so I have 'Option CPUCLOCK 420000' and 'f0 = 420E6' in the code, which give me this. :-)



Which is probably not too bad, all things considered.
Thanks again.
Regards, Kevin.
 
GAVI
Newbie

Joined: 20/11/2024
Location: Italy
Posts: 11
Posted: 03:03pm 03 Feb 2025
Copy link to clipboard 
Print this post

as far as I know the 74HC14 cannot exceed 40 MhZ, but in practice even less.
Used as an output buffer for frequency of 100-200 MhZ it would not work at all.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2025