help with random pause times; PIC16f88


Results 1 to 5 of 5

Threaded View

  1. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: help with random pause times; PIC16f88

    I believe you can. I was unable to (quickly) find an example to verify, but it should not take but a moment to try it.

    I think that one of the reasons I was unable to find an example is that long pauses are often avoided because the processor does nothing during a pause but spin a tight, uninterruptable, loop. Most often pauses are kept short purposely, during longer waits other constructs or functions are used to fill the time - such as NAP or SLEEP - that put the processor into low power mode.

    Consider: Pause 10000. For approximately 10 seconds nothing happens. Any display is not updated, any serial communications fail, no user input will be serviced, and no interrupts are processed. All that is going on is that the processor is burning thru (battery most significantly) power without any other purpose but to wait.

    Now:

    For LP0 = 0 to 9 'Loop 10 times (Loop 10 times (Loop 10 times))
    For LP1 = 0 to 9 'Loop 10 times (Loop 10 times)
    For LP2 = 0 to 9 'Loop 10 times
    Pause 10 'Pause 10
    Next LP2
    Next LP1
    Next LP0

    In this example the processor pauses an equivalent time, but interrupts can be serviced (between the much shorter pauses) and, by inserting code inside the outer loops, buttons can be checked, displays updated...

    Typically, when there is truly nothing for the processor to do, delays are managed with functions that put the processor "to sleep" so as to save power. In your case, this has the added benefit that these functions are not particularly accurate - thus adding a random element to their timing.

    One last...
    For no particular reason, you may consider a construct to make a loop of a known duration, then call the loop a random number of times, as:

    Main:
    Toggle LED
    For RandomDuration = 0 to (RandomNumber between 1 and 10)
    Gosub PauseTime
    Next RandomDuration
    Goto Main

    PauseTime:
    For LP1 = 0 to 9
    For LP2 = 0 to 9
    Pause 100
    Next LP2
    Next LP1
    Return

    The only advantage I see in this scheme is that the random waits will be (likely) clearly different in duration between one and the next, where straight random pauses may vary by hundreds or even thousands of cycles and not be noticeably different in duration to the user.

    HTH,
    Another Buzz Aldrin
    Last edited by Amoque; - 27th April 2014 at 14:22. Reason: Extraneous prepositional faux pas

Similar Threads

  1. 16F777 resetting - at seemingly random times
    By orjon1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th June 2011, 03:47
  2. Drive relay between two times
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th December 2009, 10:19
  3. Instruction times
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2009, 10:16
  4. pic18f252 hserout some times is incomplete
    By edysan in forum Serial
    Replies: 5
    Last Post: - 21st June 2006, 00:55
  5. Strange HSEROUT execution times
    By SteveB in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st May 2006, 19:34

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