Shop OBEX P1 Docs P2 Docs Learn Events
PIN symbol assigments on BS2p40 — Parallax Forums

PIN symbol assigments on BS2p40

ZootZoot Posts: 2,227
edited 2006-04-10 19:57 in BASIC Stamp
I will be using a BS2p40 for a large robot I am working on (this is my 4th or 5th robot and my second Stamp-based project).

I am getting a head start on my code, and the documentation for the BSP2p40 doesn't seem to answer how you can (or can't) assign and use PIN symbols for the two I/O groups.

On my BS2 I can do this

SerOut   PIN   15



How would I do the equivalent on the BSP2p40? Can you do this only for the MAINIO group? Or would I do a workaround using INS, OUTS and DIRS?

Related question: is there a flag or bit or anything set by the BS2p40 that can tell you during runtime which set of I/O registers has been swapped into the main memory map? Or am I just better off setting my own bit flag in my code each time I switch I/O groups like the Manual code below?
Stamp Manual said...
The 40-pin BS2 model has an additional set of INS, OUTS, and DIRS registers that are
switched in and out of the memory map (in place of the main INS, OUTS, and DIRS registers)
by using the AUXIO, MAINIO, and IOTERM commands.

IOTERM port ' Switch to main or aux I/Os
' -- depending on port
TOGGLE 3 ' Toggle state of I/O pin 3
' -- on main and aux, alternately
port = ~port



P.S. This is my first post at the forums and I just *have* to say -- the community and support that Parallax has built is just *superb*. As are the products, of course.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 16:03
    Hello,

    ·· Attached is some BS2p40 code I am in the process of updating.· You can, however, see how the pin definitions were handled.· Basically the differentiation occurs when using the pin name.· At this point you should know which bank is currently selected.· Note: the function section of the code has been removed because it is incomplete, but you can see how things are being handled.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ZootZoot Posts: 2,227
    edited 2006-04-10 16:26
    Very, very cool. Extremely helpful, thanks. So I also presume I'm correct that the BS2p40 doesn't set any I/O bank flag of it's own, outside of starting with the MAIN bank upon reset? After that it's just working with whatever I/O register set is in main memory? Thinking out loud, though, if it's swapping I/O registers after a MAINIO, AUXIO or IOTERM command, where does it store the "unused" set of registers? Are those accessible?

    What kind of amp is that you're building?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 16:39
    I'm not sure if we're talking the same language, so I will elaborate.· If I set in my main I/O definitions the following:

    LCD· PIN· 0

    and in my aux I/O defs:

    But1· PIN· 0

    Then to access the LCD, then read the button·I would use:

    MAINIO
    SEROUT LCD, Baud, [noparse][[/noparse]"Hello!"]

    AUXIO
    temp = But1

    So I need to switch banks before I address the given pin.· PIN definitions are similar to constants with the exception that the compiler can decide on the context of the usage and make certain changes, but it still needs to know what bank you are referring to.· I hope this helps better.· BTW, you don't need to swap banks when making the declarations, just when you refer to them later.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ZootZoot Posts: 2,227
    edited 2006-04-10 16:59
    Yes, we're talking the same language but thanks for making sure smile.gif I was clear from your first post and your code.

    I am still curious, though, more as a technical point-of-fact, where does the BS2p40 keep the inactive I/O register set when it swaps 'em? I'm guessing that those locations are inaccessible via code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 17:04
    Zoot,

    ·· Yes, they are inaccessable.· But they are handled by the core controller, which is an SX.· In the posted code I will actually be handling the switching between the banks within the subroutines themselves, so in my main code loop I don't have to be aware of which hardware is on which bank, although you may have noticed that the MAINIO is all inputs and the AUXIO is all outputs.· This really simplifies things.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ZootZoot Posts: 2,227
    edited 2006-04-10 17:09
    Yeah, I'm following a similar PIN map -- my AUXIO is all my sensor and user input and my MAINIO is my motor controller, PSC, LED display outputs, etc. I'm using one or two program slots in the BS2p40 for handling all the sensors, so all those routines switch to AUXIO and then back again. Thanks again for your help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-10 18:34
    Hi Zoot,

    You can retrieve the current ioterm assignment from location 134 in the scratchpad RAM:
    GET 134,mybyte
    DEBUG "ioterm =", BIN1 mybyte

    So, for example, you could write a subroutine that tests that flag and takes different action depending on which bank of pins is selected at entry, without having to maintain your own flag.

    Locations 128 to 135 in scratchpad hold read-only information about the current state of the IO pins on both mainio and auxio. This is very useful if you get into the polling commands, especially the one that latch the state of pins for later action (POLLMODE X ' X>7). Location 127 holds the value of your current run and store banks.

    I have a writeup on using POLLing at
    www.emesystems.com/BS2poll.htm
    and that lists functions of the read-only SP bytes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ZootZoot Posts: 2,227
    edited 2006-04-10 18:49
    Stamp Manual said...
    134 n/a Bit 0: Active I/O group; 0 =Main I/O, 1 = Auxiliary I/O.

    I had the SPRAM organization chart right in front of me and didn't see that. More coffee! Thanks. This is esp. helpful.

    Your document on POLLing is great, btw.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 18:54
    Zoot,

    ·· Sorry, I thought you wanted to be able to affect those registers without switching banks...For reading Tracy has provided that information.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • ZootZoot Posts: 2,227
    edited 2006-04-10 19:30
    Actually, I want to do BOTH! It just hadn't occurred to me till saw your explanations. For some purposes (mostly digital I/O) it's much more elegant to change the registers directly since the Finite State Machines in my code make heavy use of bitmapping and bitmasking. For some of my sensor subroutines that need SERIN, SEROUT, etc. I'll be checking the bank bit flag and switching banks in my subroutines. You both have save me a lot of time ahead of time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 19:57
    Since you're more into using flags you should also know there is another command that can select the bank based on a flag as well.· Lookup the IOTERM command.· Hope that helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.