Shop OBEX P1 Docs P2 Docs Learn Events
IF THEN Question — Parallax Forums

IF THEN Question

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-03-17 22:13 in Propeller 1
Sorry about the newbieness of this, my nose is still buried in the WebPM document...

Question:

Can someone give me an example of an IF THEN based on several pin inputs?
I'd like to create a type of lookup table based on 8 pins and have it activate routines based on the highs of the pins.

Thanks

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-03-17 13:42
    Example:

    ··· if dira[noparse][[/noparse]1] == 1··· 'if Pin 1 is HIGH then
    ····· dotask·········· 'jump to a method
    · ··else················'otherwise
    ····· start············'go back to beginning (or somewhere)

    Watch the indentation - it is critical.

    Sid


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-17 13:44
    How about writing and posting what you want in a "pseudo-code" so that you can show your algorithm without getting hung up on syntactical details. Keep in mind that you read pins by using "INA[noparse][[/noparse]<pin>]" and you can read multiple pins at once by using "INA[noparse][[/noparse]<1st pin>..<last pin>]" with the first pin # the high order bit and the last pin # the low order bit.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-17 19:20
    Mike,

    What I'm attempting to create is a table lookup that can detect how any set of eight pins are, (high/low) and excute a route depending on the detected set.

    Something along the lines of..

    'PINS 10,11,12,13,14,15,16,17,18
    IF = 00000000 THEN
    IF = 00000001 THEN
    IF = 00000010 THEN

    I intend to use the pins as input only, creating an address bus.

    I intend to slave the features of the propeller to another popular 80's microproccesor. [noparse]:)[/noparse]

    Oldbit
  • Jeff MartinJeff Martin Posts: 751
    edited 2007-03-17 19:44
    Hi Oddbit,
      case ina[noparse][[/noparse]10..17]
        %00000000 : '<routine, or call here>
        %00000001 : '<routine, or call here>
        %00000010 : '<routine, or call here>
            .
            .
            .
        %11111111 : '<routine, or call here>
    

    This will take the 8-bit binary pattern on I/O pins 10 through 17 (where 17 is the LSB) and execute one routine, or block of code, for every possibility.· The "..." between the last line and the top needs to be filled in with all the other combinations, of course.

    Depending on the nature of what you are doing, this may take MUCH more code space than another method (ie: if there are common routines to execute for a number of given input combinations, you can combine them in the case's MatchExpression (see manual)).· There's also an OTHER keyword you can use as the last MatchExpression as a "catch-all" for all the cases that were not explicitly stated by previous MatchExpressions.

    Note: You listed 9 I/O pins (10 through 18)... I cut it to 10 through 17 (8 I/O pins) since I think that's what you're really after.

    Critical Note: ina[noparse][[/noparse]10..17] makes pin 17 the LSB, and 10 the MSB, of the value... if you want to flip it around (17 as MSB and 10 as LSB), simply write it as ina[noparse][[/noparse]17..10].

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Jeff Martin

    · Sr. Software Engineer
    · Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-17 21:22
    OldBitCollector,
    Jeff's suggestion is really the most straightforward. What Jeff is referring to for combining routines would be something like this:
    case ina[noparse][[/noparse]17..10]
       %00000001, %00000100, %01010000: ' here's one routine
       %00000000, %00000010, %00111010: ' here's another
       %01111111..%11111100: ' a big group of sequential values
       other: ' this is the catch-all case
    
  • T ChapT Chap Posts: 4,199
    edited 2007-03-17 22:13
    Oldbitcollector

    In case you haven't run across this yet, there are commands to wait and respond to a changed state of pins(or pins to equal a state). Look at WAITPEQ and WAITPNE in the manual. On a state change (or State = somedesiredState), actions can be taken. I mention this because of your note below, in which case decisions may need to happen quickly on a change of pin states.

    oldbit said...
    excute a route depending on the "detected" set
    Post Edited (originator) : 3/17/2007 10:46:05 PM GMT
Sign In or Register to comment.