Shop OBEX P1 Docs P2 Docs Learn Events
Main and Aux IO - conditional loop — Parallax Forums

Main and Aux IO - conditional loop

edited 2005-11-30 20:44 in BASIC Stamp
Is there a was way to do something like:

DO WHILE (IOTERM 0 IN8 = 1: IOTERM 1 IN0 = 1)

Or will I have to seperate the processes like:
IOTERM 0
 
DO WHILE (IN8 = 1)
 
  IOTERM 1 
 
  DO WHILE (IN0 = 1)
 
    XXXXXXXXXX
  LOOP
 
LOOP


I'd like to not to have to do something like the latter.

I am using a BS2P.

My ultimate goal is to monitor several I/O pins at (mearly) the same time. Then go into a subroutine to time how long the pin is high. When the pin goes low again then return to the main loop.

I am pitiful at good programming technique, so if you need to get too advanced to do this, be gentle. I can get it, but I may be a little (a lot) slow in comprehension.

Thanks!

Freeing smoke from wire and IC captivity since 1972
<!-- Edit -->

Comments

  • edited 2005-11-30 16:35
    I think it may be done with polling...
    Can polling be done with both Main and Aux i/o's at the same time?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Freeing smoke from wire and IC captivity since 1972
    <!-- Edit -->
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-30 17:06
    Sometimes "good" software starts with clever hardware -- you might want to move your inputs to the save "bank" (IOTERM 0 or IOTERM 1) and, if possible, put then into a logic group (Nib or Byte) that can be monitored with one line of code.· If, for example, you had four pins and you put them on P0..P3 you could watch for a state-change like this:

    · oldState = INA
    · DO WHILE (INA = oldState)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-30 18:03
    Hi Smoke,
    Supposing it is not possible to move your i/o pins to one bank, your program alternative is workable. Your DO:LOOP code seems a little unweildy. I'd do something like this, using a RAM variable to "shadow" the value on the auxio pins:

    MAINIO
      DO
        AUXIO
           shadowAux0 = in0   ' this shadows one bit, but a word variable could shadow all 16 auxio pins
        MAINIO
        LOOP WHILE in8=1 OR shadowAux0=1
      DEBUG "HERE",BELL
    




    That will jump out of the DO:LOOP when either one of the pins goes to 1. I just like to keep the logical conditions concentrated in one place. Note that AUXIO is equivalent to IOTERM 1, and MAINIO == IOTERM 0.

    Question: How long are durations of the events you need to time on the pins, and to what accuracy do you need to time them? Also, is it possible that events occur simultaneously on more than one pin?

    It is possible to do this with POLLing, too, as you surmised. The BS2p handles polling on MAINIO and AUXIO simultaneously. That is, even if MAINIO is selected, the Stamp will respond to POLLing events that have been set up previously on either main or aux io.

    It needs to be set up and then activated with a POLLRUN and/or POLLWAIT so that a change to a target state on any of your selected pins would immediately branch to the timing code.

    AUXIO 
       POLLIN 8,1   ' poll for 1 on x8
       MAINIO 
       POLLIN 0,1   ' poll for 1 on p0
       POLLMODE 10   ' 
       POLLWAIT 8  '  program holds here until one of the pins changes to its target state
       DEBUG "HERE",BELL
    



    That is the essence of it. The devil will be in the details, of course!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • edited 2005-11-30 19:24
    Tracy,

    Polling is a faster execution time (IIRC), so maybe that's the way to go. How do I set up the Stamp to poll the aux pins?

    Only one pin at a time will be high.

    Exact time is not really needed. Only cumulative a cumulitive count comapred to a known value.


    I am going to give some more details, as I know it is hard to help when the full picture is not known. I am sorry for not doing to earlier.

    I am monitoring several solenoid valves.·Each valve, when opened, will let out fluid from·its own container. I am planning to monitor to amount of fluid released and when approx. 75% of the fluid has been released, I plan for an LED to light up. I am going to conduct several trials to get a mean count for the time required to drain the container. From that i will derive the 75% mark.

    As a pin goes high (signalling that the soleniod is activated), the program will run a secondary program which will have an incremental counter. The secondary program exits to the main (primary) program which then compares the value to the 75% mark (Actually this could happen in the·secondary program, as well). If the count is => the mark, an LED will light up, signalling a need to change the container with one that is full. Then a button is pressed for that container to reset its counter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Freeing smoke from wire and IC captivity since 1972
  • edited 2005-11-30 19:26
    Ooops..

    Jon, I did not mean to have appearently ignored you.

    I am trying your approach as we speak (err. type?).

    I'll let you know how I fare.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Freeing smoke from wire and IC captivity since 1972
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-30 19:45
    The activation durations still do matter. If you are monitoring a valve opening for seconds or minutes, a few miliseconds in the response one way or another is not going to matter. huh? Are you using a real time clock (RTC) chip/ external time base to accumlate the times, or are you going to rely on the Stamp processor clock for that? I guess I still don't understand your intent.

    POLLing with it set in the latched mode can allow the Stamp to capture brief events, and POLLWAIT 8 can respond very fast to an event on any of the polled pins, but I don't see how that will help you here.

    The example I gave above sets up polling on one pin on auxio and one pin on mainio:

    AUXIO
    POLLIN 8,1 ' poll for 1 on x8
    MAINIO
    POLLIN 0,1 ' poll for 1 on p0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • edited 2005-11-30 20:02
    I am thinking like this...

    I'll run a looped event with the following structure

    DO WHILE (var = oldvar)
     
         i=i+1
         var = ins
     
    loop
     
    if i >= seventy_five_percent then out1
     
    run 0
    

    While it's in the DO WHILE loop, I know the value of i is incrementing about every (4/12,000) seconds or so. This is because the Stamp can process roughly 12,000 instructions per second (according to the white sheet). Where I get the 3 is because I assume the DO WHILE is one, the increment statement is one, reading in the·pin states in one·and finally the loop is one. This wouold mean I get a rough resolution of 0.3 microseconds. I am only concerned about +/- 2 microseconds, so this should be fine.

    I am sure there is a better way, probably using additional components, but to implement them I'll need more help. I am struggling to work in a world of EE's, but my background is ME. I am hip some circuit analysis and some electronics, but this is my first foray into microcontrollers.

    I am sure I am missing something and am looking forward to hearing feedback.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Freeing smoke from wire and IC captivity since 1972
  • edited 2005-11-30 20:44
    In a related topic... Related only by the mentioning of polling...

    Can I store a variable in program 0 to be used in program 1 and have it unchanged when I return to program 0?

    I am trying to use Jon's suggestion, but each time I return to prog. 0, "oldstate" get updated with the newstates.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Freeing smoke from wire and IC captivity since 1972
Sign In or Register to comment.