![]() |
Forum Index : Microcontroller and PC projects : Running PIO flat out?
Author | Message | ||||
Bleep Guru ![]() Joined: 09/01/2022 Location: United KingdomPosts: 534 |
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 KingdomPosts: 7106 |
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: NetherlandsPosts: 4527 |
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 KingdomPosts: 7106 |
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 KingdomPosts: 534 |
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 KingdomPosts: 7106 |
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 KingdomPosts: 1024 |
I wonder if a 74HC14 Schmitt-Trigger would help? |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2281 |
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 KingdomPosts: 1024 |
On the RP2350, GP0 supports the new-ish FFIN What happens if you flip the roles? |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2281 |
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 KingdomPosts: 1024 |
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 KingdomPosts: 534 |
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: ItalyPosts: 11 |
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. |
||||
![]() |