Time limit while waiting for input ?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: Time limit while waiting for input ?

    Hi Richard,

    I've been studying your code, (again) I haven't tried to compile the items added in red below as I'm on a different PC right now. I just posted a small part of it for learning.

    Can you tell me if I'm on the right track with how I've added it ?

    So after 100 seconds, if the limit hasn't sent a low, limup pin will still go low ?

    Thanks !


    Code:
    maxrun con 2000  ;  2000 = 100 sec
    RUN_COUNT VAR word
    
    
    moveup:
    high blue
    pause 500
    low blue
    while limup = 1
    high up
    wend
    IF   RUN_COUNT  THEN    ;should the motion continue ?
                 RUN_COUNT = RUN_COUNT -1
    ENDIF
    if limup = 0 then
    low up
    goto run
    else
    goto moveup
    endif

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Time limit while waiting for input ?

    hi sam

    I will make some assumptions here
    blue is a led that should flash when moving
    up enables movement
    limup stops movement when low


    this is the movement loop / the only way it stops is if limup = 0
    while limup = 1
    high up
    wend
    its not what you want

    try some thing like this

    Code:
    moveup:
    high blue   ;  led on 
    high up     ;  motor on
    RUN_COUNT=200  ; set time limit 200*500mS  ie 100 sec
    while (limup = 1 ) && ( RUN_COUNT>0) ; do this till time runs out or limit sw trippe
    pause 500
    toggle blue  ; flash led
    RUN_COUNT = RUN_COUNT -1 
    wend   ; all done 
    low blue       
    low up
    Warning I'm not a teacher

  3. #3
    Join Date
    Mar 2004
    Posts
    92


    Did you find this post helpful? Yes | No

    Default Re: Time limit while waiting for input ?

    Richard, you're awesome ! thanks very much !

    This morning is the first chance I've had to try it without constant interruption. I must have done something a little different because it wouldn't work until I added...
    moveup:
    high blue ; led on
    high up ; motor on
    RUN_COUNT=200 ; set time limit 200*500mS ie 100 sec
    while (limup = 1 ) && ( RUN_COUNT>0) ; do this till time runs out or limit sw trippe
    pause 500
    toggle blue ; flash led
    RUN_COUNT = RUN_COUNT -1
    wend ; all done
    IF limup = 0 OR RUN_COUNT =>0 THEN
    low blue
    low up
    ENDIF
    Not sure why it doesn't work right without the ">0" but in any case, it's working great. Thanks again !!

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Time limit while waiting for input ?

    I have some doubts about your modification, perhaps you have some noise entering the system, or the limit switch is "bouncing"

    IF limup = 0 OR RUN_COUNT =>0 THEN
    low blue
    low up
    ENDIF

    firstly operator precedence make this If test dodgy, parentheses ensure correct result
    IF (limup = 0 ) OR (RUN_COUNT =>0) THEN
    secondly
    RUN_COUNT =>0
    since pbp vars are unsigned , this will always be true it can only be 0 or greater
    since the run_count test always tests true the if statement is always true

    thirdly
    the while loop will only exit if limup is 0 or run_count is 0 , the statement is or should be redundant
    Last edited by richard; - 10th July 2017 at 02:01.
    Warning I'm not a teacher

Similar Threads

  1. Upgrade time limit?
    By fowardbias in forum Off Topic
    Replies: 1
    Last Post: - 5th August 2012, 17:34
  2. Limit of PokeCode??
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th June 2012, 21:18
  3. Replies: 0
    Last Post: - 1st December 2010, 23:48
  4. Replies: 11
    Last Post: - 14th May 2010, 11:11
  5. Replies: 4
    Last Post: - 5th October 2007, 11:25

Members who have read this thread : 0

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