Time limit while waiting for input ?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    92

    Default Time limit while waiting for input ?

    I'm using a 16F628A to control a DC motor, also using hall effect sensors as limit switches. All working fine however I'm concerned that if one of the hall sensors should fail the motor will keep running, NOT GOOD !

    The code waits for a low from the hall sensor, is it possible to have a time limit on how long to wait for that low input and if it doesn't happen, the timer will effectively provide the low and the program can continue just as if the sensor worked ?

    For example, the sensor should go low at about 16 seconds, At 18 seconds the timer could provide the low if the sensor didn't. (?)

    Thanks for advice !

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


    Did you find this post helpful? Yes | No

    Default Re: Time limit while waiting for input ?

    is it possible to have a time limit on how long to wait for that low input and if it doesn't happen, the timer will effectively provide the low and the program can continue just as if the sensor worked ?

    the code I posted in this link

    http://www.picbasic.co.uk/forum/show...ht=#post136604

    effectively does this. that's what "run_count" is all about

    when the motor is moving the limit switches are checked every so many mS and the run count decremented
    if a limit is reached or the run count reaches 0 then movement is terminated.

    a run count of 2000 @ 50mS = 100 seconds till timeout
    or
    a run count of 185 @ 100mS = 18.5 seconds till timeout , simply adjust to suit
    Last edited by richard; - 3rd July 2017 at 02:37.
    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 ?

    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

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


    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

  5. #5
    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 !!

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    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 01: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, 16:34
  2. Limit of PokeCode??
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th June 2012, 20:18
  3. Replies: 0
    Last Post: - 1st December 2010, 22:48
  4. Replies: 11
    Last Post: - 14th May 2010, 10:11
  5. Replies: 4
    Last Post: - 5th October 2007, 10:25

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