Help with loop


Closed Thread
Results 1 to 3 of 3

Thread: Help with loop

  1. #1
    Join Date
    Nov 2005
    Location
    Ontario Canada
    Posts
    30

    Default Help with loop

    Greetings to all for 2007. Let's hope we will be wiser this year. All members have been very helpfull. I am have great difficulty figuring out how to get this done. I have included some of the code below. The code reads the adc value and stores it. Then it checks to see if the value is in range. When it is the code carrys on to the next command which checks and now that it is in range for the first time it starts counting to 30 before going to the main label to turn on port pins and display on the LCD. Here is where I am stuck. While the counting is running, if the real value at Pin 0 (adval pin) changes and goes out of range. I want at the end of the count for the program to check if the value is still in range before carrying to main label. Remember, this is what caused it to start counting, being in range. If it is out of range go back to loop. The problem is that the code cannot do this because it is counting and even though pin 0 has changed adcin does not have chance to read Pin 0.
    I hope I have explained this clearly. If not I will try again. Thanks to all.

    loop:

    adcin 0, adval ' Read adc value and store in adval
    if adval <= 668 or adval >= 839 then ' if adval is out of range
    restore = 0 ' clear restore
    LCDout $FE,2," Water Level = ",DEC Level ' Display Level
    lcdout " Out of Range " ' Display out of range
    goto loop
    ENDIF

    if adval > 668 OR adval < 839 then ' If adval is in range
    restore = restore + 1 ' Increment restore timer var
    if restore = 1 then ' If restore is equal to 1 then
    goto Wait_timer ' Go to Wait_timer
    else ' else
    goto main ' go to main label
    Wait_timer: ' Wait label

    for i = 1 to 30 ' Count to 30
    lcdout $fe,2
    lcdout " "
    lcdout $FE, $C0 ' Move cursor to second line
    lcdout " Waiting to Restore" ' Display Waiting to Restore
    lcdout $FE, $94 ' Move cursor to third line
    lcdout " Level " ' Display Level
    lcdout $FE, $D4 ' Move cursor to fourth line
    lcdout " ", dec i ' Display Count value
    Next i ' next count value

    endif
    endif

    main:

    IF adval >= 737 AND adval <= 770 THEN ' Check if adval is in a range
    leds = 17
    LCDout $FE,2," Water Level = ",DEC Level,
    endif

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Why not duplicate the ADCIN and IF-THEN in your count to 30 loop, thus checking each time through the count loop?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Nov 2005
    Location
    Ontario Canada
    Posts
    30


    Did you find this post helpful? Yes | No

    Default

    Thanks Paul. I had a good laugh when I read you response. I would have responded the same way you did. I went dud! What was I thinking? Sometimes I think I make things much too difficult than it really is.

    Thanks..

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. newbie Q - edge detection?
    By RMCRAVEN in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 9th October 2006, 08:20
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts