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 : Pico PIO Development
Page 3 of 4 | |||||
Author | Message | ||||
utop25 Newbie Joined: 24/05/2022 Location: AustraliaPosts: 5 |
After my earlier post re a squarewave on GP0, I then tried to output the same squarewave on GP02. So now: SetPin GP02,pio0 Also I assume that I need to change: pio(pinctrl 0,1) (works for GP0) Adding extra arguments results in MMBasic errors. Help! |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3558 |
Yes, you need to change that. The pinctrl register determins what IO pins can be controlled or read by the PIO sequencers. I do not have a rp2040 manual with me, buy my guess is that you should use Pinctrl(2,1) where 2 is the start number of the range, and 1 is the size of the range. So only GP2 can be controlled from the SET command. There are additional fiwlds in the pinctrl for gpio pins to use for IN, for MOV, and for SIDE_SET. It gets confusing easilly.... PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 1797 |
"It gets confusing easily.." Agree. Have been playing with your square wave example, which is excellent but can't figure out how to use any pin other than GP0, or to use PIO0. Experimented with every combination I can think of. @Geoffg An interim suggestion for the manual. From the PicoMite User Manual Page 145 as it is now. Programming example: This generates a square wave on pin-1 at 1/4 of the clock frequency requested. The program itself is stored in a%(). PIO program 1,a%() sets up state machine 0 to run the program. Dim a%(7)=(&H0001E000E101E081,0,0,0,0,0,0,0) 'This is the actual program SetPin 1,pio1 'Pin 1 is allocated to pio1 PIO program 1,a%() 'pio1 will run the program stored in a%() PIO init machine 1,0,100000,Pio(pinctrl 0,1) 'Initialise pio1, state machine 0 to run at 100000Hz 'note that PINCTRL, EXECCTRL & SHIFTCTRL are not 'changed in this example. PIO start 1,0 'Start pio0, state machine 0 Proposed PicoMite Manual Amendment Programming example: 'This generates a square wave on pin-1 at 1/4 of the clock frequency requested. The program itself is 'stored in a%(). PIO program 1,a%() sets up state machine 0 to run the program on PIO1. Dim a%(7)=(&H0001E000E101E081,0,0,0,0,0,0,0) 'This is the actual program SetPin 1,pio1 'Pin 1 is allocated to pio1 PIO program 1,a%() 'pio1 will run the program stored in a%() PIO init machine 1,0,4000,Pio(pinctrl 0,1) 'Initialise pio0, state machine 0 to run at 4000Hz for a 1000Hz output. 'note that EXECCTRL & SHIFTCTRL are not changed in this example. PIO start 1,0 'Start pio1, state machine 0 The frequency and comments need updating. I think the original version was intended to produce 1kHz, which this produces. Comments changed to PIO1 . Edited 2022-05-27 14:24 by phil99 |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3663 |
I think you mean PIO init machine 1,0,4000,Pio(pinctrl 0,1) 'Initialise pio1, state machine 0 to run at 4000Hz for a 1000Hz output. (i.e. pio1 not pio0) John |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5740 |
That flippin' PIO did my head in when I was writing the assembler... It's too weird for mere mortals like myself to understand. Confession time: Due to the passage of time and reduction in brain operating efficiency I now have a vague concept of how the assembler works, but no idea whatsoever how to program a PIO to do anything. lol Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
@Mick And herein lies the false economy of the Pico Grab a Prop-1 with PropBasic or FlexBasic and focus on what to do rather than how to do it Craig |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3558 |
The commands in MMBasic for PIO support do not teach you in any way PIO works, nor do they present a higher level language. To understand how to work with PIO you need to study the datasheet, and benefit if you have previous experience with programming assembly language. Like with Microchip MPASM. I had some problems using the assembler Mick wrote (PASM12) so I hand assembled the code. Which is not overly difficult with the datasheet at hand. And there are only 32 program words to fill... For me the most difficult part was to architecture the PIO program. Do you use delay, or side set pins, configure the IO pins for SET instructions, or for OUT/MOV instructions. Ranges can overlap, but can also be different. In example: if you have a value in X register and want that to be output parallel you need use MOV. But the pins where initialized using SET. So you must initialize both pin groups in the PINCTRL instruction. Otherwise it wont work. PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5740 |
I wouldn't know where to start, Craig. The Prop is a completely foreign thing to me, it would be like learning the PIO stuff but without the head's start that I already have. :) Why can't things be as simple as I once found a Z80 macro assembler to be? lol Nope, I'm not intending to move away from a nice, linear, single processor BASIC now. I don't mind using GCBASIC if I want it compiled, but a PicoMite is fine for me. I'll leave the weird stuff to others now. If I had an application that needed that sort of stuff it may be different, but there's nothing to attract me at the moment. And you *still* don't believe that a group of PicoMites on a SPI bus can't be soddin' fast... :) Think how a conventional PLC works. The program is processed then all outputs are updated then all inputs are updated then the program is processed again. When those updates are at 10MHz they are *very* fast, even if you use CS lines to each slave rather than a serial loop. The slave gets a CS interrupt, handles the SPI then goes back to it's task, updating its SPI tx buffer ready for the next interrupt. It spends virtually no time on comms. The master runs as a normal PLC master does, handling the main program. Slaves can be doing independent complex tasks. I can see that I might have to design a PicoMite PLC to attempt to shake your belief in the Great Prop. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5740 |
@Volhout I had problems with that assembler too. A conventional CPU follows different rules, you have an instruction and data. The PIO compresses such a lot into the bit pattern of a single command and I found it pretty difficult to sort out the bits. It's true that there aren't many commands, but each one has a heck of a lot of variations. I agree with you - the manual is the place to go. I still find it hard to get my head round the shift registers for some reason. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Well Mick, I have a bundle of stuff here to pass on to you....when we finally meet Think I might just sneek a Propeller board in there You will soon be addicted |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5740 |
LOL! I'm sure we will eventually. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 1797 |
@JohnS Yes, I got that one wrong. Was changing 0s to 1s but managed to change a 1 to a 0. Going senile. |
||||
Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
This one. It even has touch pads. There is absolutely no difference when it comes to programming until you decide that something is slowing your main loop. Just launch that particular function in a "Cog" and share variables. Absolute child's play Craig |
||||
utop25 Newbie Joined: 24/05/2022 Location: AustraliaPosts: 5 |
Referring to the RP2040 datasheet there are 7 fields assigned to each state machine pin control register (pinctrl). To allow the SET instruction to control GP02, I expected that this is required: pinctrl 0,1,0,0,0,2,0 ie SET_COUNT = 1 and SET_BASE = 2 PIO init machine 0,0,100000,Pio(pinctrl 0,1,0,0,0,2,0) results in: Error : Syntax |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3558 |
You've done your homework... I do not have a manual, but if in doubt, hand assemble the value, and write it to the register before you start the pio. So: Pio program Pio init (without pinctrl, so pinctrl will be 0) Poke word &h502000xx, value Pio start Look up the register adress for pinctrl from the datasheet. The &h5020xxxx is for pio0 For pio1 that is &h5030xxxx PicomiteVGA PETSCII ROBOTS |
||||
led-bloon Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 203 |
Instead of Pio(pinctrl 0,1,0,0,0,2,0) replace with &H04000040. The PIO Pincntrl function has a bug which does not allow anymore than 3 params before declaring a syntax error. The &H04000040 is bitmap necessary in the pinctrl register for GP2 (physical pin 4). led FYI: Pio(pinctrl 0,1,0,0,0,2,0) is actually correct @Geoff The manual, Appendix E page 145 is incorrect for the pinctrl register. This function has in fact 7 parameters. AFTER [,set_base] there should be another parameter [,out_base] Edited 2022-05-27 21:24 by led-bloon Miss you George |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3558 |
All, Please be aware PIO register have no awareness of pico pin numbers. So pico pin 4 is GP02, so you have to put a 2 in the register (not 4). PicomiteVGA PETSCII ROBOTS |
||||
led-bloon Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 203 |
The &H04000040 is bitmap necessary in the pinctrl register for GP2 (physical pin 4) The pinctrl register is a patchwork of smaller bitmaps, it just so happens that GP2 (pin 4) gives that value. Tested and works led Miss you George |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 1797 |
Yes in it does! > LIST '2kHz square wave on pin4 (GP02) PIO CLEAR 0 : PIO CLEAR 1 Dim a%(7)=(&H0001E000E101E081,0,0,0,0,0,0,0) SetPin gp2,pio1 'SetPin gp1,pio1 PIO program 1,a%() PIO init machine 1,0,8000,&H04000040 PIO start 1,0 > clock = 8000 gives 2000 Hz Edited 2022-05-27 23:17 by phil99 |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Not true. You have to specify GP no's i.e. Pio(pinctrl 0,1,,,,GP2) From the latest version of the manual downloaded just now from Geoff's site Edited 2022-05-28 01:12 by matherp |
||||
Page 3 of 4 |
Print this page |