|
Forum Index : Microcontroller and PC projects : pio wait instruction not seeing gpio state on RP2350
| Author | Message | ||||
| crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 157 |
I was going through the handy step-by-step PIO guide by Volhout. The example code below was not behaving as expected. The pulsing on gp0 should stop when gp2 is low, but the pulsing did not start when gp2 was set hi. gp2 was always being read as low. The cure was to move the 'setpin gp2,dout' to the start of the program. The RP2350 has something called 'pad isolation latches', which the RP2040 does not have. The PIO initialization does not work correctly unless the pad isolation is disabled first (accomplished by the setpin dout). I'm no expert with PIO, so my explanation may be a bit off. Using PiPicoBT. 'disconnect ARM from GP0 setpin gp0,pio1 'configure pio1 p=Pio(pinctrl 0,1,,,,gp0,) f=1000 * 6 'Hz 'line code comment ' 0 � � E081 SET GP0 output ' 1 � � 2082 WAIT GP2=1 ' 2 � � E201 � �SET gp0 high, dly=2 ' 3 � � E000 � �SET gp0 low ' 4 � � 0001 � �JMP to 1 'program pio1 pio program line 1,0,&hE081 pio program line 1,1,&h2082 pio program line 1,2,&hE201 pio program line 1,3,&hE000 pio program line 1,4,&h0001 'write the configuration PIO init machine 1,0,f,p,,,0 'start the pio1 code PIO start 1,0 'toggle GP2 in MMBasic Setpin gp2,dout '---------------<<<<<-----move this to program start do �pin(gp2) = 1 - pin(gp2) 'toggle pin GP2 �pause 100 loop |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 2041 |
Two things; gp2 hasn't been configured as an output setpin gp2,dout Is this a workable toggle? pin(gp2) = 1 - pin(gp2) 'toggle pin GP2 Edit: Yes it is I would: pin(gp2)= not pin(gp2) Edited 2026-07-30 22:09 by PhenixRising |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6013 |
Good find crez. The examples where developped on 2040, and I did not envision this, but it makes sense. There are more examples where it could go wrong: the logic analyzer example could also fail. Volhout PicomiteVGA PETSCII ROBOTS |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 2041 |
I'll see myself out |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6013 |
In a week I 'll be home, and look into it. Phenix looked at another pio program (stepper pulse decoder) and also noticed it did not work. This one probably because the setpin was brute force moved up to make it work, and then it escaped the define. So my homework.: make sure all pio programs are to modify to make them work eith 60300 for both 2040 and 3350 Volhout Edited 2026-07-31 02:19 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 2041 |
Of course I understand nothing of PIO programming but the issues I have with both the step/dir and the quad decoder is that, due to the FIFO, the current sample is not really the latest value. Not really an issue with the quad decoder because even at steady state, there is still at least a 1bit oscillation and so it updates but the step/dir never updates the latest actual count value. Gemini showed how to directly read the register (not the FIFO) but the instruction wasn't recognised. I believe I explained this correctly |
||||
| crez Senior Member Joined: 24/10/2012 Location: AustraliaPosts: 157 |
the PIO pulse width measurement example in the same tutorial also was behaving strangely so I tried the same fix for the RP2350 and it looked good after that. |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6013 |
Hi crez, I checked the 5 example programs in the pico user manual for both 2040 and 2350, and the examples all work. If you copy and paste from the manual there are a few "`" characters that need replacing with "'" (comments), but that is all that is needed to be changed. The PIO training course on this forum is written for V5.07.00 (3-4 years ago) when there was no built in assembler, and no support for half of the features of the PIO (i.e. interrupts, 2350, 2350B) so the examples in the training do not work 100% as shown. When there is interest, I should be able to re-write this in a new thread. But please look at the examples in the user manual for the semantics, and the way programs are set up (configured). Please use the training on the forum as a guide how PIO works, but do not blind copy the programs, they are older, and there will be discrepancies (such as SETPIN needs to be made at start of the program, to aviod re-configuring pins after PIO configuration is done). I hope this is a satisfactory answer. Volhout Edited 2026-08-05 05:27 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |