help with random pause times; PIC16f88


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: help with random pause times; PIC16f88

    Ah! Does that mean I was on the "right" track with my original idea? Although it does sound very inefficient. I'm just looking for something simple that works on a breadboard and power supply situation, as we have a limited time to do the project.. unfortunately.

    I liked your second example and it got me thinking...

    Would it be better (in my case) to have loops; say, 0-9, each loop contains a different pause duration between lighting the LED and updating the display, I would have the main loop call a random number 0-9, which would go to each loop.

    Let's see if I can mock it up...

    MyWord var Word
    MyByte var Byte

    mainloop:

    Random MyWord
    MyByte=(MyWord//9)+1

    If (MyByte == 1) Then
    GoTo loop1
    EndIf
    If (MyByte == 2) Then
    GoTo loop2
    EndIf
    If (Mybyte == 3) Then
    GoTo loop3

    ;this continues to MyByte == 9

    If (MyByte == 9) Then
    GoTo errorloop ;error loop displays "E" on the LED display and waits for the user to press the reset button
    Return

    loop1:
    High led1
    pause 100
    GoSub updatepins ;updates the display with the count, (not included yet in example)
    Low led1


    the loops would increase in pause duration of course. I hope I am on the right track here. I still have a couple days to complete this, but aside from one introduction to C# class, this is the first time I've had any experience with coding.

  2. #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

    In every project there are a myriad ways to accomplish the goal. If what you conceive meets your goal and is within your skill level - I count that as success! I'd say, yes... you were on track.

    The purpose of the "PauseTime" subroutine is to demonstrate how a long pause may be achieved without paralyzing the processor for undue lengths of time. It is FUNCTIONALLY equivalent to Pause 10000. It is not "better" in your case, only offers advantage when other processes require service.

    First priority is to complete your assignment on time - do that using the method you understand best; I have no wish to derail your train of thought, only to explain why long pauses are not well illustrated by random example. I really enjoy the opportunity to payback some of the help I have received here, but I don't wish to influence your design decisions. Ask whatever you like, I'll (and many others likely) will try and help, but please don't let me be a distraction to your instructor's curriculum.

    That said, my approach would be to write a subroutine that provides a simple pause of a minimum acceptable length then, call the routine multiple times to provide a random factor, except in the case of "9" where you branch to the error handling routine.

    Main:
    Generate random number

    If number is 9 goto Errorhandler 'If our random number is 9 GOTO where we deal with it

    This part only happens when our random is NOT 9

    Display the random number

    For Delay = 1 to Random number ' Use the variable Delay as a counter from 1 to our random number.
    gosub delay 'Go find our pause
    Next Delay 'If Delay < our random number, +1 to Delay then go back and pause again

    Goto Main 'do it all over



    Delay:
    pause 1000 'this is the shortest pause, we'll do this once if our random number was 1, three times if it was 3....
    Return 'go back to the line after the gosub

    ErrorHandler:
    Here's where we do whatever we want to happen when 9 is the random number
    Dispay an "E"....

    Goto Main: 'Go back to "Main", generate a new random number and start over

    Do you follow the logic here? The Main loop picks a number, if that number is nine, it leaves the loop for Errorhandler to handle the special case. Otherwise, it displays the number before the "For Delay" loop pauses 1 second "RandomNumber" times. Goto Main starts the process again. What the user will see: A random number, then a pause of equal number of seconds, another random number will appear and another pause of equal seconds... If a nine is our random number, an "E" appears and whatever else you code in errorhandler. Once the errorhandle coder is completed another number is generated, appears on the display, and the pause begins.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,159


    Did you find this post helpful? Yes | No

    Default Re: help with random pause times; PIC16f88

    Good ideas, but as stated, make it so it fulfills your needs.

    If your mcu does nothing else, PAUSE with a random number works. If your project will evolve, then it might be worth the effort to implement the ideas above.

    I'd go for simple, a random number between 1 and 9, multiply by 200. This gives a range of .2 - 1.8 seconds.

    Robert

Similar Threads

  1. 16F777 resetting - at seemingly random times
    By orjon1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th June 2011, 02:47
  2. Drive relay between two times
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th December 2009, 09:19
  3. Instruction times
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th June 2009, 09:16
  4. pic18f252 hserout some times is incomplete
    By edysan in forum Serial
    Replies: 5
    Last Post: - 20th June 2006, 23:55
  5. Strange HSEROUT execution times
    By SteveB in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st May 2006, 18: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