Avoiding getting stuck in a loop


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104

    Default Avoiding getting stuck in a loop

    I'm writing some code for a photography application which looks for i/p A, then waits for i/p B to change state. I/P B should change within say 500msec max. My naive approach would be to just to stick the program in a FOR count = 1 to xxxx loop, check I/P B inside the loop and if it has changed jump out of the loop with a GOTO statement. Something is bugging me about this approach and it seems that there might be a better way, perhaps using an interrupt ? Any comments ? I've never programmed with interrupts before.

    Also, is there an easy way of working out how many clock cycles a particular set of PBP instructions is going to take so I can calculate what to set the count to.

    Thanks, Andrew

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    This may not find favour with the experts, but you could try this code. No interrupts
    Code:
    Counter   var   byte
    
    for Counter = 1 to 500      ' 500 mS time to find inputb
      pauseus 1000                ' pause a millisecond.  You may need to trim this value
      if InputB then ProcessB
    next
    ' .....   do code following 500mS timeout of not getting InputB
    return                            ' to wherever
    
    ProcessB:
    ' do whatever you want here. You could also tell after how long InputB has come by reading the value of the Counter which counts in 1mS increments
    return
    The grain here is 1mS between samples of the inputB which I guess should be overkill for a photography application if InputB is a manual push button

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    This may not find favour with the experts, but you could try this code. No interrupts
    No interrupts!
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Feb 2006
    Location
    Brussels, Belgium
    Posts
    104


    Did you find this post helpful? Yes | No

    Default

    Thanks Jerson, that is pretty much what I was proposing. This is actually for the flash sync part of a laser trigger for capturing flying insects. To reduce the granularity I coded it without the PAUSEUS. Jumping out of the FOR ... TO ... loop works fine. I was just wondering what the alternatives might be.

    Andrew

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. Getting Stuck in loop
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 19th November 2008, 15:46
  3. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  4. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  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