Shop OBEX P1 Docs P2 Docs Learn Events
P2 Easy Pin Group Assignment Demo — Parallax Forums

P2 Easy Pin Group Assignment Demo

larryvclarryvc Posts: 42
edited 2020-05-06 01:18 in Propeller 2
Hi All, first post here, although I have been using Parallax products since 1995.

I received my P2 Rev B Eval board about a week ago, and have to say that I am pretty amazed by what this chip has to offer!

So after having spent most of the last few weeks reading forum threads, docs, and then playing with the P2 Eval board, I decided to write a pasm demo to show how easy it is to assign pin groups as inputs or outputs. Demo file is attached.

Hope this helps other P2 noobs understand general pin IO. Credit to Chip for the code snippet that led me to understanding the magic formula. The same formula can be used for most pin instructions, though not sure if it applies to Smart pins.

Larry
'------------------------------------------------------------------------------------------

' grpsize = 0..7, 0 for a single pin or 1..7 for 2 pin to 8 pin groups.
' grpbase = lowest pin number in the desired pin group.

' The magic formula for selecting a pin group for input or output is
' dirl/dirh = grpsize << 6 + grpbase

' Selecting a grpbase greater than 24 or 56 will wrap within DIRA or DIRB,
' e.g. Using grpbase 25 or 57 will wrap back to pins 0 and 32
' respectively within the corresponding DIRA or DIRB register.

'------------------------------------------------------------------------------------------

Comments

  • ozpropdevozpropdev Posts: 2,791
    edited 2020-05-05 10:40
    Welcome to the forum Larry. :)

    Here's some more information on this neat feature of P2.
    The span can be up to 31 pins/bits.
    By using the '##' syntax for immediate values larger values can be used.
    Another alternative is to use the SETQ instruction to set the span.
    .
    Hope this helps.
    	For: 	DIRx/OUTx/FLTx/DRVx
    	uses D10..6]
    	D = (groupsize - 1) << 6  | grpbase
    
    	For: WRPIN/WXPIN/WYPIN/AKPIN
    	Uses S[10:6]
    	S = (grpsize - 1) << 6  | grpbase
    
    	For: BITL/BITH/BITC/BITNC/BITZ/BITNZ/BITRND/BITNOT
    	Uses S{9:5]
    	S = (span - 1) << 5  | bitbase
    
    
    	'example1
    
    	drvl	##5 | 19 << 6	'20 pins (5..24)
    
    	'exxample2
    	setq	#grpsize - 1
    	drvl	#grpbase
    
  • larryvclarryvc Posts: 42
    edited 2020-05-12 20:47
    @ozpropdev, Tested your examples this morning, and found them to be very helpful. I especially liked the setq instruction!

    I have a lot more information to cover before I will be up to speed with just the chip. Then comes the learning curve of the many languages and tools that are here, many of them still in flux as expected for a new device, and with that comes the uncertainty of whether it is my code or a bug causing issues.

    Currently using Flexgui and Fastspin while concentrating more on pasm2 at the moment. A good debugger would be quite helpful right about now.

    Thanks for the reply
Sign In or Register to comment.