Shop OBEX P1 Docs P2 Docs Learn Events
SX Pin numbering — Parallax Forums

SX Pin numbering

GAFGAF Posts: 25
edited 2007-03-02 16:34 in General Discussion
Hi,· I have a question on SX/B.· When using the Basic stamp I could use
IN3 to·use pin 3 as an input.· How do I do the same thing in SX/B?

Thanks

Post Edited By Moderator (Bean (Hitt Consulting)) : 2/22/2007 8:52:37 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2007-02-22 20:53
    GAF,
    On the SX pins are labeled by their port and position on that port.
    For example: RB.0, RB.7, etc.

    If you wanted to use pin RB.0 as an input you would do:

    INPUT RB.0
    IF RB.0 = 1 THEN

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    ·
  • JonnyMacJonnyMac Posts: 8,941
    edited 2007-02-22 21:36
    It's a good idea to declare your I/O pins -- this makes the program easier to read and, with outputs, saves you some setup. For example:

    LED     PIN    RC.0 OUTPUT
    



    This will define pin RC.0 as "LED" and make it an output (saving you the trouble) so your program can do this:

    LED = 1
    



    Better yet, define constants for on and off like this:

    IsOn    CON    1
    IsOff   CON    0
    



    ... and then do this:

    LED = IsOn
    



    See how much easier that is to read/debug -- especially when giving your programs to others?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-02-23 02:50
    JonnyMac,

    That's so well presented -- that even a hard-core "magic number" like me1 can get it.



    Update --

    ·1·However unrepentant.· wink.gif

    Post Edited (PJ Allen) : 2/23/2007 2:58:05 AM GMT
  • SailerManSailerMan Posts: 337
    edited 2007-03-02 02:21
    IT doesn't cause an error, but crashes the IDE. Why?· Is there a solution to this?



    DEVICE          SX28, OSCHS1, TURBO, STACKX, OPTIONX, BOR42
    FREQ            50_000_000
    
    ID  "Sensor"
     
    Sensor Var Byte(8)
     
    Sensor(0) Pin RC.3
    Sensor(1) Pin RC.2
    Sensor(2) Pin RC.1
    Sensor(3) Pin RC.0
    
    Sensor(4) Pin RB.3
    Sensor(5) Pin RB.2
    Sensor(6) Pin RB.1
    Sensor(7) Pin RB.0
     
    Temp Var Byte
    
     
    PROGRAM Start  
     
    Start:
              
    Main:
      
    Do
      For Temp=0 to 7
        Pulsout Sensor(Temp),100,25
      Next 
      Pause 250
    Loop
     
    

    Post Edited (SailerMan) : 3/2/2007 12:14:51 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-03-02 02:58
    IT doesn't like the array that you're trying to set up.
    Is this what you're trying to do?
    DEVICE sx28, oschs3, TURBO, STACKX, OPTIONX
    IRC_CAL  IRC_SLOW
    FREQ     50_000_000
    PROGRAM Start 
    ID  "Sensor"
    Start:
     
     
    Sensor0 Pin RC.3
    Sensor1 Pin RC.2
    Sensor2 Pin RC.1
    Sensor3 Pin RC.0
    Sensor4 Pin RB.3
    Sensor5 Pin RB.2
    Sensor6 Pin RB.1
    Sensor7 Pin RB.0
      
      Do
      Pause 250
      Loop
    

    Update -- Forgot to add that this much compiles.· It's disallowing combining an array and Pin Numbering.· I think that you'll need to add input/output after the Pin Number, too [noparse]/noparse]i.e. [i]Sensor Pin RC.3 INPUT[/i

    Post Edited (PJ Allen) : 3/2/2007 3:07:33 AM GMT
  • JonnyMacJonnyMac Posts: 8,941
    edited 2007-03-02 04:07
    Pin names must conform to label specs: up to 32 characters, must start with an alpha, the only non-alphameric character allowed is underscore. If you inputs are simple digital inputs then there is an easy way to iterate through them as your declarations suggest you want to do.
  • BeanBean Posts: 8,129
    edited 2007-03-02 11:38
    SX/B does not support bit arrays.
    I will look into the crashing, it should cause an error.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Coming soon! Propeller based OSD module www.hittconsulting.com
    ·
  • SailerManSailerMan Posts: 337
    edited 2007-03-02 12:11
    Bean,

    Is there a good way to do what I'm trying to do in the above code?

    I need to iterate through non sequential pins.

    Regards,

    Eric
  • BeanBean Posts: 8,129
    edited 2007-03-02 14:02
    Eric,
    You can use a bit mask.
    It would be alot easier if you connected all the sensors to one port (either RB or RC).

    Will the order change at runtime ? If not then just change the connections so they are in order.

    Assuming you are using the RB port for all sensors, and the array bitPos holds the bit position of the sensor to pulse, you would do:

    FOR temp = 0 TO 7
    · mask = 1 << bitPos(temp)
    · RB = RB XOR mask ' Invert bit
    · PAUSE 25 ' PULSOUT x, 100, 25 = 25 mSec
    · RB = RB XOR mask ' invert bit
    NEXT


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Coming soon! Propeller based OSD module www.hittconsulting.com
    ·
  • SailerManSailerMan Posts: 337
    edited 2007-03-02 14:34
    I was going to put them all on the same port, but the layout and routing of my board was so much easier.

    I guess that I will have to spend some more time re-routing my board and just use Port RB. It seems the most Logical course of action... Thanks for your code snipet.

    Regards,
    Eric
  • BeanBean Posts: 8,129
    edited 2007-03-02 15:03
    Eric,
    · If you want to use both RB and RC then you just need to make "mask" a Word variable and use RBC.
    · bitPos() elements can be from 0 (RB.0) to 15 (RC.7)


    FOR temp = 0 TO 7
    · mask = 1 << bitPos(temp) ' mask is a WORD variable
    · RBC = RBC XOR mask ' Invert bit
    · PAUSE 25 ' PULSOUT x, 100, 25 = 25 mSec
    · RBC = RBC XOR mask ' invert bit
    NEXT

    · I always optimize my layouts and adjust the software to work. It's much easier to make a software mod, then a hardware mod.


    · The drafting dept as work loves me because I don't show what pin a connection is to on the SX. I just say "It can be connected to any of these pins". It really freaks them out, they are not used to being able to do that. Then I always find lots of ways to simplify the layout after they do it, by using a different pin for something.

    · Just don't forget about I2C pins, they must be in a specific order. I've got them backwards a couple times then the SX/B I2C commands don't work.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Coming soon! Propeller based OSD module www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 3/2/2007 3:10:16 PM GMT
  • SailerManSailerMan Posts: 337
    edited 2007-03-02 15:53
    It took me a sec, but I see the you're·creating a pulsout with this.

    RBC = RBC XOR mask ' Invert bit
    PAUSE 25 ' PULSOUT x, 100, 25 = 25 mSec
    RBC = RBC XOR mask ' invert bit
    

    ·So I should define an Array of Bit Positions.

    What is the Best Way to load the Array with Bit Position info.


    BitPos(0) = %0000_0000_0000_1000
    BitPos(1) = %0000_0000_0000_0100
    BitPos(2) = %0000_0000_0000_0010
    BitPos(3) = %0000_0000_0000_0001
    
    BitPos(4) = %0000_1000_0000_0000
    BitPos(5) = %0000_0100_0000_0000
    BitPos(6) = %0000_0010_0000_0000
    BitPos(7) = %0000_0001_0000_0000
    




    Am I thinking of this in the right way? I'd test it but I 'm not at home.

    Regards,
    Eric

    Post Edited (SailerMan) : 3/2/2007 3:59:47 PM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-03-02 16:12
    Hi,

    maybe, this is a bit off-topic here as I'll show examples in ASM here, and not in SX/B...

    In general, I agree with Bean that assigning SX I/O pins to specific signals can be arbirtrary in most cases. Nevertheless, sometimes, it makes software design easier, or more compact when you use specific pins. For example, in a serial receiver code, you will often find the instruction

    movb C, RxD

    where RxD can be any port pin used as serial input. The movb instruction is a compound instruction, i.e. expanded to

    sb RxD
    clrb C
    snb RxD
    setb C

    so it takes four program words, and four clock cycles for execution.

    If you were using RB.7 as RxD input pin, for example, you could move the status of RxD into the C flag with just one instruction:

    mov w, <<RB

    This moves the left-rotated contents of RB into w but also rotates bit 7 of RB into the C flag.

    You can also use RB.0, for example, together with

    mov w, >>RB

    Besides this, keep in mind that only the port B inputs allow for wake-up, and interrupts, and the RA pins can't be configured as Schmitt-Trigger but they have symmetric source/sink characteristics when configured as outputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • BeanBean Posts: 8,129
    edited 2007-03-02 16:33
    Eric,
    No, you just want to put the bit position VALUE into the array.

    0 to 7 = RB.0 to B.7 ; 8 to 15 = RC.0 to RC.7

    So:

    PUT bitpos, 11, 10, 9, 8, 3, 2, 1, 0

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Coming soon! Propeller based OSD module www.hittconsulting.com
    ·
  • SailerManSailerMan Posts: 337
    edited 2007-03-02 16:34
    Gunther,

    That was way over my head but thanks. [noparse]:)[/noparse]



    Bean,

    Great thanks for clarifying that for me.

    Regards,
    ERic


    Post Edited (SailerMan) : 3/2/2007 4:38:52 PM GMT
Sign In or Register to comment.