Shop OBEX P1 Docs P2 Docs Learn Events
2p40 : problem with handling main and aux I/O pins. — Parallax Forums

2p40 : problem with handling main and aux I/O pins.

SebastienSebastien Posts: 7
edited 2005-08-25 14:19 in BASIC Stamp
Hi everyone,
I've just discovered this forum yesterday and I already learned some interesting things.

May I expose my problem ?·Here is a simple version of it :
Let's say I am controlling an engine thanks to 2 Pins in the main I/O pins (1 pin for each way of rotation).
- This engine is able to move a tray from point A to point B.
- Points A and B are both equipped with a sensor that may detect the presence of the tray. these two sensors are linked with 2 I/O auxiliary pins.

My goal is to move the tray from A to B. That means, activation the engine until the arrival at B.
I plan to use a DO WHILE function :
(Basic stamp used : 2p40)
As you may guess, the whole function is not written·here.

'main pins
main_engine_rotation_1 PIN 1
main_engine_rotation_2 PIN2
 
'auxilary pins
aux_sensor_A PIN 1
aux_sensor_B PIN 2
 
          DO WHILE (aux_sensor_B = 0)
                HIGH main_engine_rotation_1
          LOOP
 
MAINIO
LOW main_engine_rotation_1


Now the problem is : where do I put the MAINIO and AUXIO functions ?
Like this ?

DO WHILE (AUXIO aux_sensor_B = 0)
     MAINIO
     HIGH main_engine_rotation_1
LOOP



I really don't find easy to handle main and aux i/o pins and I'm still wondering why the auxiliary pin numbers have not been incremented after the main pins.

Before discovering·BS 2.5,·I programmed this function by using the BUTTON function·over and over again. I really hope it is possible to use a DO WHILE since it's way more logical and understandable

Any advice would be appreciated.

PS : Please let me know if it's not easily understandable (I'm not a native english speaker)

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-08-24 07:14
    Sebastien -

    I'm not sure whether you're doing this as just an exercise, or representing a real world application. Unless you have a real need to use them, there is no particular advantage to using the auxio pins, as far as I'm aware. Said somewhat differently, there is never a requirement that the AUXIO pins MUST be used, that I'm aware of, except as noted below.

    In fact, if you DO use them, and DON'T need to, you're going to pay a small time penalty for doing so, if that's of any importance to you. This presumes you've not run out of mainio pins to use, and I DO get that impression from what you've said so far.

    I'm not sure what you mean by "I'm still wondering why the auxiliary pin numbers have not been incremented after the main pins?" Pin numbers per se, are never incremented, except by the programmer using certain programming techniques which may scan multiple input pins. Did you mean to say "updated", rather than incremented?

    Regards,

    Bruce Bates
  • SebastienSebastien Posts: 7
    edited 2005-08-24 08:12
    Thanks for your answer.
    Obsviously, it was not a good idea to simplify [noparse];)[/noparse]

    It's definitely not an exercise, it's a part of my daytime job.

    I have to program a "free falls machine". Please take a look at the picture.
    In 3 words : you let fall an object on the center area, a shock sensor detects the fall, a brush (that I called "tray") pushes it towards the edge A (or B). It then falls in a plexiglas box (in red, called 1 and 2). Finally one of the plexiglas box is lifted up.
    This machine allows a man to retrieve the object without having to bend himself.
    Why such a machine ? i'm working for a mobile phone company, and lots of free falls tests are made on the phones.
    the picture shows :
    - In yellow, 6 sensors.
    - in blue, various parts that needs pins : 3 engines, a footpedal (a second one will come), a display (with some buttons), and some other things
    - in red, the moving parts : 2 plexiglas box ("godet" in french), and a brush (my tray in my first post).
    - hidden, a shock sensor.
    with all these stuffs a 2p40 is just enough : 2 engines need 2+2 pins, the 3rd one needs 3 pins, 4 pins for 4 leds, 6 sensors...
    => in the end, only 2 pins are still available
    I am sufficiently clear ?
    I think there's no need to post my whole program since all my aliases are french words, and it wouldn't take just 5 minutes to get the whole thing. Finally, the program is not finished yet.

    ·
    bruce said...
    I'm not sure what you mean by "I'm still wondering why the auxiliary pin numbers have not been incremented after the main pins?" Pin numbers per se, are never incremented, except by the programmer using certain programming techniques which may scan multiple input pins. Did you mean to say "updated", rather than incremented?
    Sorry I wasn't clear. It would be easier (for me) if it was :
    MAIN PINS : 0, 1, 2, 3...15
    AUX PINS : 16, 17...
    instead of AUX PINS : 0, 1, 2 and the need to use MAINIO and AUXIO.


    Message Edité (Sebastien) : 8/24/2005 9:21:59 AM GMT
    960 x 1280 - 112K
  • SebastienSebastien Posts: 7
    edited 2005-08-24 10:19
    idea.gif

    Hey, what about that ?
    I'm gonna test it as soon as possible, but maybe someone will be able to tell me if this code is right or wrong.

    AUXIO
    DO WHILE (aux_sensor_B = 0)
         MAINIO
         HIGH main_engine_rotation_1
         AUXIO
    LOOP
    
    

    For the first execution, it sounds ok. Then, as it loops, the AUXIO will be activated just before checking again my sensor, right ?
    Any comments appreciated.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-08-24 17:56
    That last code should work fine, to address the pins where required. FYI, the loop can run a little bit faster if you use UNTIL instead of WHILE, and leave out the expliicit condition test.


    AUXIO
    DO UNTIL aux_sensor_B   ' until =1
         MAINIO
         HIGH main_engine_rotation_1
         AUXIO
    LOOP
     
    
    



    Another point, in the code as stated there is no apparent need to repeatedly make the motor HIGH. Once high, it will stay high.

    MAINIO :  HIGH main_engine_rotation_1
    AUXIO
    DO:LOOP UNTIL aux_sensor_B   ' until =1
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • SebastienSebastien Posts: 7
    edited 2005-08-25 05:59
    Thanks a lot Tracy, I will use that code.
    I didn't know Until was faster than While, I will remember it.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-08-25 14:19
    It is a matter of when the condition checking takes place Sebastien that determines the use of Do..Until vs. Do/While....


    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com
Sign In or Register to comment.