Shop OBEX P1 Docs P2 Docs Learn Events
Grasping at the OUTA[] command and what it means... — Parallax Forums

Grasping at the OUTA[] command and what it means...

Kaos KiddKaos Kidd Posts: 614
edited 2006-05-04 20:30 in Propeller 1
Ok... I know this may sound silly, but...
'Understanding the following from the manual :
'  P0 ~ P7 are Outputs.
'  Temp = %11111111
'  OUTA[noparse][[/noparse]0..7] := Temp
'  P0~P7 would all be high...  
 
'Now the question...
'#1:
'After executing the following...
  var byte Temp
  Temp = 5                           'Give some value to assign to the outputs
  OUTA[noparse][[/noparse]0..7] := Temp                 'assign Temp's bits to the outputs P0~P7 (should be P0 ~ P7 = %0000101)
 
'#2:
'After executing the following...
  var byte temp
  Temp = 15                  'Max out a 4 bit number
  OUTA[noparse][[/noparse]0..3] := Temp         'Only assign the lower 4 bits to the outputs...  P0~P3 should = %1111
  Temp = 11                  'Some number to out put...
  OUTA[noparse][[/noparse]0..3] := Temp         'Only assign the lower 4 bits to the outputs...  P0~p3 should = %1011
 
'#3:
REPEAT Index 0 TO 15         'Count from 0 to 15
  OUTA[noparse][[/noparse]0..3] := Index        'Put the count as binary onto the IO pins P0~P3 (for something else to read!)
  WAITCNT(2_000 + CNT)       'Wait for the something else to read the data...
 
OUTA[noparse][[/noparse]0..3] := 6              'Put the number 6, binary %0110 on P0~P3


·What I'm trying to fingure out is do I have to convert·a decimal number to binary before I assign it to the outa pins.
I just can't wait until my dev board is completed... then I wouldn't be asking... I'd be doing!






▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket


KK
·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-04 16:48
    KK,

    ·· Values can be specified in Binary, Decimal or Hex...In the memory they are all in Binary anyway so it doesn't matter.· It just depends on your readability.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-04 17:17
    Thanks Chris... that is just exactly what I was hoping for... !!
    (Remember some time ago I was asking for a register type object... well, now it really doesn't matter... two questions answered for the price of one!)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-04 17:22
    Additional info: The OUTA[noparse]/noparse register is the eqivalent to the OUTS register on the BASIC Stamp. albeit with 32 bits.· Spin is really cool in that it lets you select which bits you want to affect.· For example, if you had a five-bit counter that you wanted to output on pins 4 - 8, you would do it like this:

    · dira[noparse][[/noparse]8..4]~~····················' make P4-P8 outputs
    · repeat
    ··· outa[noparse][[/noparse]8..4] := counter++·······' output counter
    ··· waitcnt(clkfreq / 4 + cnt)··· ' wait 1/4 second·

    Notice the order bits in the brackets -- this is important.· If I'd used [noparse][[/noparse]4..8] the LSB would actually be moved the the MSB LED (this can be useful in some apps).


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-04 18:53
    Jon:
    In my example I used 0~7 expecting a bit for bit copy... where as your example was reversed 8..4
    Oh, and I like your short hand for a 1/4 a second... neat...
    And, according to the docs,
    Temp := Out[noparse][[/noparse]0..7] would put that bit pattern into Temp... but again, I'd have to verify if I'v got the order reversed or not... simple enough to test.

    Oh, I just cant wait!!! Two more little thinggies and my Dev board is done... YES!!!... then it's play time...
    I'v been through all the printed matierals from the web site, in "fast glance, get to see it" order...
    Now it's time for the "full and detailed" and "lets try it"

    Thanks Jon... And Chris...
    Shucks, my first APP worth noting is going to have a lot of "contruibiting programmers" listed in it!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-05-04 19:04
    Something discovered early on by the first users of spin is waitcnt should be formed as waitcnt(x + cnt) and not waitcnt(cnt + x). The reason why is the order of execution, if using the second form, you limit the smallest availible wait period attainable. In the second form cnt is retrieved, added to the argument stack, x is evaluated, added to the stored copy of cnt, then the waitcnt is entered. Since cnt increments every cycle, placing it first in the expression means that the stored value becomes much more stale than if you placed cnt last in the expression.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-05-04 20:30
    Ahhh, very nice to know.
    See, it's these little things that make it so exciting, and fun.
    I would hope someone posted this stuff into the thread tips & tricks and gotchyas (or something like that...)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Just tossing my two bits worth into the bit bucket


    KK
    ·
Sign In or Register to comment.