Long Timer


Closed Thread
Results 1 to 13 of 13

Thread: Long Timer

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    William, thanks very much for your reply.

    Your right about the abort routine. I wonder if there is another was to stop the effect where if the button is held down for the ABORT phase, when it jumps back to the main code, it will still be HIGH and thus start the delay routine again.

    With this you'll need to be quick off of the button to stop this from happening.

    Any other thoughts?

  2. #2
    ccsparky's Avatar
    ccsparky Guest


    Did you find this post helpful? Yes | No

    Default Long Timer

    Tissy,
    How about a button just for abort purposes? Say PORTC.1
    Or maybe a 3 second pause after seeing PORTC.0 high during abort, allowing 3 seconds to get off the button, i.e.
    If PORTC.0 = 1 then
    pause(3000)
    goto main code
    end if

    I am curious to see other solutions also!!!

    William

    Also after reading more of your orginal post and seeing that you need to time by seconds, would this be more of what you needed:

    Low PortB.1

    Red VAR PORTB.1

    MinuteDelay VAR BYTE
    SecondDelay VAR BYTE

    Main Code:

    MinuteDelay = 2 '1 To 60
    SecondDelay = 0 '1 To 60

    If PORTC.0 = 1 Then Goto Timer

    Goto Main Code

    Timer:

    If MinuteDelay > 0 then
    For Minutes = 1 to MinuteDelay
    For Seconds = 1 to 60
    if PORTC.0 = 1 Then goto main code
    Pause(1000)
    Next Seconds
    Next Minutes
    EndIF

    If SecondDelay > 0 then
    For Seconds = 1 to SecondsDelay
    if PORTC.0 = 1 Then goto main code
    pause(1000)
    Next Seconds
    EndIF

    For loop = 1 to 10
    if PORTC.0 = 1 Then goto main code
    HIGH red
    pause(125)
    LOW Red
    pause(250)
    Next loop

    Goto Main Code

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Another way that has no PAUSE statements, so has very quick
    response to all inputs.

    ; Assumes 20 Mhz Oscillator

    T0CON =$86


    LOOP:

    IF INTCON.2 = 1 THEN
    INTCON.2 = 0
    TMR0H = $69
    TMR0L = $7A
    GOSUB SecondsTimer
    EndIF

    'Run regular code here (check for inputs, timeouts, etc)

    GOTO LOOP

    SecondsTimer:
    Seconds = Seconds + 1
    IF Seconds >= 60 THEN
    Seconds = 0
    Minutes = Minutes + 1
    IF Minutes >=60 THEN
    Minutes = 0
    Hours = Hours + 1
    ENDIF
    ENDIF
    RETURN

    END

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Hang-on, i think i may have it !!

  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Right cracked it, thanks very much for everones help.

    Regards,

    Steve

  6. #6
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Ok, i got greedy. I have now added hours to the routine.

    However, i have done a test, setting the delay at 8hrs 45min 32 seconds
    and it triggered at 8hrs 44min 06 seconds.

    Two things really, is the the type of result expected. I know its a small margin of error, but i thought 1000ms is a 1000ms. Alternatively is there an error in the code that someone can see?
    Code:
        If HoursDelay > 0 then
        For Hours = 1 to HoursDelay
        For Minutes = 1 to 60
        For Seconds = 1 to 60
        If SW2 = 1 Then Goto main
        Toggle Red ' flashing light for reference
        Pause(1000)
        Next Seconds 
        Next Minutes
        Next Hours
        EndIF    
    
        If MinutesDelay > 0 then
        For Minutes = 1 to Minutesdelay
        For Seconds = 1 to 60
        If SW2 = 1 Then Goto main
        Toggle Red ' flashing light for reference
        Pause(1000)
        Next Seconds 
        Next Minutes
        EndIF
    
        If SecondsDelay > 0 then
        For Seconds = 1 to SecondsDelay
        If SW2 = 1 Then goto main
        Toggle Red ' flashing light for reference
        pause(1000)
        Next Seconds
        EndIF
    I thought it would be a little more accurate than that. If i set the delay at 32seconds then it triggers at 32seconds.

    There are only so many lengthy test you can do, waiting 8hrs for an event to trigger is a long time !!

    Cheers,

  7. #7
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Can anyone answer the above ?

Similar Threads

  1. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  2. Replies: 5
    Last Post: - 24th February 2009, 18:55
  3. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  4. long countdown timer, how to save power?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 15th November 2008, 05:15
  5. Timer and long (hours) sleep period - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th January 2007, 07:32

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