Shop OBEX P1 Docs P2 Docs Learn Events
Help with SELECT-CASE — Parallax Forums

Help with SELECT-CASE

CogburnCogburn Posts: 62
edited 2005-01-24 05:54 in BASIC Stamp
Hey guys,
I am using a linear taper potentiometer and the RC-Time command to obtain readings for a wind direction indicator.· The pot has been modified by removing the stop so that it is free to move in all directions.· I have mapped out the values that are stored in my variable "result" for 8 compass directions.· I am trying to use "select case " as the basis for the debug output.· I am getting proper readings as I am temporarily displaying the DEC result along side of the direction so I know the variable is being updated properly but I cannot seem to get the direction to debug correctly.· I am only getting "SOUTHEAST" and "NORTH" no matter what the value of "result" is.· I am including my code here and I wonder if someone might be kind enough to make a suggestion as to a fix for it.

'{$STAMP BS2}································ ' specifies a BS2
' {$PBASIC 2.5}
result· VAR Word······························· ' Word to hold result
Main:
· DO
··· HIGH 7····································· ' Discharge the cap
··· PAUSE 1000·······························'·· for 1 s
··· RCTIME 7, 1, result······················' Measure RC charge time
·SELECT result
· CASE result = 0
· DEBUG "WIND FROM EAST·· " , DEC result
· CASE· result = 1
· DEBUG "WIND FROM NORTHEAST·· ", DEC result
· CASE 1 < result < 200
· DEBUG· "WIND FROM NORTH·· " , DEC result
· CASE 200 < result < 420
· DEBUG "WIND FROM NORTHWEST·· "· , DEC result
· CASE 420 <· result < 550
· DEBUG "WIND FROM WEST·· "· , DEC result
· CASE 550 <· result < 700
· DEBUG "WIND FROM SOUTHWEST·· " , DEC result
· CASE 700 <· result < 722
· DEBUG "WIND FROM SOUTH·· "· ,DEC result
· CASE·· result > 723
· DEBUG "WIND FROM SOUTHEAST·· " , DEC result
· CASE ELSE
· DEBUG "OBTAINING WIND DIRECTION·· " , DEC result
· ENDSELECT


······················· ' Show value on screen
· LOOP

Post Edited By Moderator (Jon Williams) : 1/20/2005 8:18:31 PM GMT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 20:18
    Your format is incorrect -- this should fix things:

     SELECT result
       CASE 0
         DEBUG "WIND FROM EAST   " , DEC result
       CASE 1
         DEBUG "WIND FROM NORTHEAST   ", DEC result
       CASE 2 TO 200
         DEBUG  "WIND FROM NORTH   " , DEC result
       CASE 201 TO 420
         DEBUG "WIND FROM NORTHWEST   "  , DEC result
       CASE 421 TO 550
         DEBUG "WIND FROM WEST   "  , DEC result
       CASE 551 TO 700
         DEBUG "WIND FROM SOUTHWEST   " , DEC result
       CASE 701 TO 722
         DEBUG "WIND FROM SOUTH   "  ,DEC result
       CASE > 722
         DEBUG "WIND FROM SOUTHEAST   " , DEC result
       CASE ELSE
         DEBUG "OBTAINING WIND DIRECTION   " , DEC result
     ENDSELECT
    
    


    And don't forget to add a subject title to your threads (I fixed this one).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • CogburnCogburn Posts: 62
    edited 2005-01-20 20:29
    Thanks Jon- You are the man!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Showing up to school doesn't·mean you are a student any more than crawling up in an oven means that·you are a biscuit.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 22:06
    Can I assume -- based on that high praise -- that it worked?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • MikeSMikeS Posts: 131
    edited 2005-01-21 03:25
    Cogburn said...
    (I am using a linear taper potentiometer and the RC-Time command to obtain readings for a wind direction indicator.· The pot has been modified by removing the stop so that it is free to move in all directions.)
    I like the·idea of using the pot for windirection, but dont you have a dead spot on the pot where the resistance taper stops and begins?

    Mike S.
  • CogburnCogburn Posts: 62
    edited 2005-01-22 22:57
    It is working now beautifully.· Yes I do have a "dead spot" but the wind hardly ever comes from the east here so I am placing the dead spot there.· Most wind we get comes from the northwest when a cold front is moving in or from the southwest otherwise.· We do get strong southerly winds immediately before an approaching cold front however.· I tried in vain to find an inexpensive pot that could be read anywhere on the 360 degree circle but I couldn't find one.· I also looked for an inexpensive encoder but I couldn't find one.· So I settled for less accuracy and it only cost me $3.00.· If anyone knows of a 360 degree pot or an inexpensive encoder that would improve accuracy, please let me know.·

    Thanks to all for the help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Showing up to school doesn't·mean you are a student any more than crawling up in an oven means that·you are a biscuit.
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-01-23 21:23
    Cogburn,
    you could try the Parallax Boe-Bot encoders and design your own disk.
    bugg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    So many projects, so little time.
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-24 00:54
    Someone can correct me....but I don't think they make a POT that would work for the entire 360degrees of rotation.

    They all have deadzones...but it's nice to find them with a very small deadzone.

    I work for Environment Canada and I think our sensors are rated for a 5deg deadband...but they are sometimes less!

    On one of our newer sensors we use an optical mask that rotates with the vane and masks out different LEDs for a given direction (very fancy looking mask!).

    Our newest sensor looks nearly like a trident...but picture each point making up a triangle.· This one uses ultrasonic vibrations and temperature to determine direction and speed.· It's nice because there are no moving parts and we don't have to worry about it icing up (has a built in heater).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • SPENCESPENCE Posts: 204
    edited 2005-01-24 01:02
    Yes they do make pots that run full 360 degree's.

    I have used them in the past, both carbon which wore pretty bad and wire used in azmuth indicators.

    73
    spence
    k4kep
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-24 01:28
    Is the 'band' overlapped then?

    In our radars we use synchro's for angle readback....more like a motor/gen...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-01-24 05:54
    Here is a URL for a pot that has two wipers--If one is in the dead band, use the other..

    www.fascinatingelectronics.com/weatherinst.html#windvane


    Cogburn,

    Another way to skin the original problem is to use the LOOKDOWN command:

    LOOKDOWN result,<=[noparse][[/noparse]0,1,2,200,420,550,700,65535],index

    that leaves values from 0 to 7 in the variable, index, corresponding to the 8 directions. That simplifies the SELECT CASE statements, or the index can be used to address the strings to print stored more efficiently in DATA eeprom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.