Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 15:33 05 May 2024 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 : Pico PIO Development

     Page 3 of 4    
Author Message
utop25
Newbie

Joined: 24/05/2022
Location: Australia
Posts: 5
Posted: 06:00am 26 May 2022
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 3558
Posted: 04:14pm 26 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 1797
Posted: 04:08am 27 May 2022
Copy link to clipboard 
Print this post

"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 Kingdom
Posts: 3663
Posted: 06:54am 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 5740
Posted: 07:00am 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1646
Posted: 07:37am 27 May 2022
Copy link to clipboard 
Print this post

@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: Netherlands
Posts: 3558
Posted: 07:43am 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 5740
Posted: 07:59am 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 5740
Posted: 08:08am 27 May 2022
Copy link to clipboard 
Print this post

@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 Kingdom
Posts: 1646
Posted: 08:12am 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 5740
Posted: 08:13am 27 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 1797
Posted: 08:19am 27 May 2022
Copy link to clipboard 
Print this post

@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 Kingdom
Posts: 1646
Posted: 08:25am 27 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 5
Posted: 09:17am 27 May 2022
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 3558
Posted: 09:35am 27 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 203
Posted: 11:18am 27 May 2022
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 3558
Posted: 11:39am 27 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 203
Posted: 12:04pm 27 May 2022
Copy link to clipboard 
Print this post

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: Australia
Posts: 1797
Posted: 01:13pm 27 May 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8592
Posted: 02:38pm 27 May 2022
Copy link to clipboard 
Print this post

  Quote  The PIO Pincntrl function has a bug which does not allow anymore
than 3 params before declaring a syntax error.


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

  Quote  PIO (PINCTRL
no_side_set_pins
[,no_set_pins] [,no_out_pins]
[,IN base] [,side_set_base]
[,set_base] [, out_base])
helper function to calculate the value of pinctrl for the INIT MACHINE
command. Note: The pin parameters must be formatted as GPn.

Edited 2022-05-28 01:12 by matherp
 
     Page 3 of 4    
Print this page
© JAQ Software 2024