Shop OBEX P1 Docs P2 Docs Learn Events
setting an pin to output understanding — Parallax Forums

setting an pin to output understanding

DXCDXC Posts: 33
edited 2011-02-01 11:25 in Propeller 1
Hello all,

I did some programming in ASM with the Propeller now some time.
The question I have is when setting an pin to output I also have to set the rest of the pins.

eg,
cog 1 uses 3pins as outputs, pin 1 ,2 and 3. (spin basic language)
cog 2 uses 2pins as outputs, pin 28 and 29. (assembly )

dira has to be set to 110000 00000000 00000000 00000000 binair
but doing so will I not set pins 1,2 and 3 as inputs?

Or do I have to set dira to 110000 00000000 00000000 00000111?

gr,
Bart

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-01-31 23:49
    Check the propeller datasheet chapter 4.5 I/O Pins (available with the latest proptool). In a nutshell a cog should only set pins as outputs which it is going to drive, i.e.one cog should drive pins 1..3 (or do you mean 0..2, your post isn't entirely clear in that respect) the other one 28 and 29.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-02-01 04:17
    First of all the naming convention should be claryfied:
    Usually the pin numbers range from 0 to 31 and not from 1 to 32. The reason can be found in the binary nature of microcontrollers. The least significant bit is also called bit 0. If you have a look at one byte, the least significant bit has a value of 2 to the power of 0 = 1, whereas the most significant bit has a value of 2 to the power of 7 = 128.

    So, in your description either cog 1 or the binary mask you show on the end is wrong:

    110000 00000000 00000000 00000111
    | these are bits 28 and 29 | these are bits 0-2

    Now to the DIRA thing ... each COG has it's own copy of DIRA. You should only set the pins to output which are used by the COG, all other pins should stay as input.
    So, in the SPIN COG you say
    DIRA := %111
    and in the PASM COG you say
    mov dira, pin_mask
    ...
    pin_mask long %110000 00000000 00000000 00000000
  • DXCDXC Posts: 33
    edited 2011-02-01 11:25
    Hello,

    thnx for the explanation.

    Allways worked with it but never thought of how it would work in the propeller.

    I also ment 0..2 yes, my fault.

    gr,
    Bart
Sign In or Register to comment.