Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:30 26 Apr 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 : Converting Pico GP numbers to Pin numbers

Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1781
Posted: 07:55am 24 Sep 2022
Copy link to clipboard 
Print this post

Observations:

Many people prefer:-
a) GP numbers over pin numbers
b) To make everything adjustable with variables at the start of the program.

Problem:
Pin assignments won't use string variables

Solution:

A SUB for converting GP numbers to RPPico module pin numbers.
You supply a string "GPx" and it returns the pin no. in the second variable of your choice.

eg
> GP2Pin "GP7", MyPin% : ? MyPin%
10
>


Dim Integer x, y
For x=0 To 28
 GP2Pin "GP"+Str$(x), y
 If y <> 0 Then : Print "GP";x, "Pin";y : EndIf
Next

Sub GP2Pin GP$, PinN  'GP must be upper case
 If Left$(GP$,2) = "GP" Then
   PinN = Val(Right$(GP$,Len(GP$)-2))
   PinN = PinN + 1 + Int((PinN+2) / 4)
   If PinN > 29 Then : PinN = 0 : EndIf
   If GP$ ="GP26" Then : PinN = 31 : EndIf
   If GP$ ="GP27" Then : PinN = 32 : EndIf
   If GP$ ="GP28" Then : PinN = 34 : EndIf
  Else
   PinN = Val(GP$)
 EndIf
End Sub

A sane person would have used a lookup table, but there is a pattern to most of them.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8578
Posted: 08:03am 24 Sep 2022
Copy link to clipboard 
Print this post

Useful idea thanks . See latest beta.
Edited 2022-09-24 19:55 by matherp
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1781
Posted: 12:35pm 24 Sep 2022
Copy link to clipboard 
Print this post

Peter thanks for building that function in. Much more flexible than the Sub.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1642
Posted: 02:34pm 24 Sep 2022
Copy link to clipboard 
Print this post

Why not?

CONST GP10 = pin14
CONST GP14 = pin19
etc.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5722
Posted: 03:59pm 24 Sep 2022
Copy link to clipboard 
Print this post

In your example pin14 and pin15 have to be numbers or numeric variables. You can use GPI0 and GPI4 as CONST names though (but not GP0 or GP4).

There isn't a way to write a program using PCB pin numbers that will run on variations of RP2040 boards. The RP2040 only knows about GP numbers (it doesn't know what PCB it will be mounted on) so it makes sense to use them wherever possible. If you can't use them for some reason then make sure those locations are *very* well commented as you'll have to change the program if you want to run it on a different RP2040 board.

Knowing what we know now, that the RP2040 has appeared on quite a few different variations of boards, it might have been wiser not to allow PCB pin numbers at all.  :)
Edited 2022-09-25 02:15 by Mixtel90
Mick

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

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1642
Posted: 04:42pm 24 Sep 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  In your example pin14 and pin15 have to be numbers or numeric variables. You can use GPI0 and GPI4 as CONST names though (but not GP0 or GP4).

There isn't a way to write a program using PCB pin numbers that will run on variations of RP2040 boards. The RP2040 only knows about GP numbers (it doesn't know what PCB it will be mounted on) so it makes sense to use them wherever possible. If you can't use them for some reason then make sure those locations are *very* well commented as you'll have to change the program if you want to run it on a different RP2040 board.

Knowing what we know now, that the RP2040 has appeared on quite a few different variations of boards, it might have been wiser not to allow PCB pin numbers at all.  :)

would CONST pin14 = gp10 work? I see problems if different rp2040 boards.
It's same with arduino, portb.0 or digital_8.  Uno and nano boards different pins.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8578
Posted: 04:53pm 24 Sep 2022
Copy link to clipboard 
Print this post

  Quote  CONST pin14 = gp10 work?

No, that would set the variable pin14 to the value 0 assuming that the variable gp10 had not been itself set to something else.
If you had set OPTION EXPLICIT then it would simply error
Edited 2022-09-25 02:53 by matherp
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1781
Posted: 02:05am 26 Sep 2022
Copy link to clipboard 
Print this post

There is no need for this now, however the SUB is easier to use when turned into a Function.

> ? gp2pin("gp19")
25
>

Dim Integer x, y
For x=0 To 28
 gp$ = "GP"+Str$(x)
 y = GP2Pin(gp$)
 If y > 0 Then : Print GP$, "Pin";y : EndIf
Next

Function GP2Pin(GP$)
 If (Left$(GP$,2) = "GP") Or (Left$(GP$,2) = "gp") Then
   PinN% = Val(Right$(GP$,Len(GP$)-2))
   PinN% = PinN% + 1 + Int((PinN%+2) / 4)
   If PinN% > 29 Then : PinN% = 0 : EndIf
   If GP$ ="GP26" Then : PinN% = 31 : EndIf
   If GP$ ="GP27" Then : PinN% = 32 : EndIf
   If GP$ ="GP28" Then : PinN% = 34 : EndIf
  Else
   PinN% = Val(GP$)
 EndIf
 GP2Pin = PinN%
End Function
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3519
Posted: 10:40am 26 Sep 2022
Copy link to clipboard 
Print this post

During the development of picomite there was a inconsistency between pin numbers used for MMBAsic and pin numbers (GP numbers) used in the PIO.

MMBasic used numerics that where related to the connector location of the pin.
PIO uses numbers that are chip specific (the port/pin numbers).

So in the earlier MMBasic versions you could end up with following inconsistency


Setpin 31,PIO1

PIO init machine 1,0,1e5,Pio(pinctrl 1,,,27,)


Where 27 was GP27, and 31 was GP27.
That's when it was proposed to standardize on GPx numbers.

It also makes it easier to port to other platforms that use the same chip.
PicomiteVGA PETSCII ROBOTS
 
Print this page


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

© JAQ Software 2024