Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Ticks = Ticks + 1
    if Ticks = 100 then
    Ticks = Ticks-100
    Seconds = Seconds - 1
    SecondsChanged = 1
    if Seconds = 0 then
    Minutes = Minutes - 1
    MinutesChanged = 1 Seconds = 59
    endif

    if Minutes = 0 then
    Hours = Hours - 1
    HoursChanged = 1 Minutes = 59
    endif

    if Hours = 0 then
    Days = Days - 1
    DaysChanged = 1 Hours = 23
    endif
    endif

    To my untrained eyes, this would count down the time at every 100 ticks. I guess the issue, if this works, is how to preloaded the timer with the required start time and how to get it to stop at 0.

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Seem to be having an issue I cant resolve. I've only use the timer software on a 18F2550 and it worked perfectly. I'm now using a 18F1320 and I've ran into an issue when compiling.

    ERROR Line 23: Redefinition of VAR. (DT_INTS-18.bas)
    ERROR Line 24: Redefinition of VAR. (DT_INTS-18.bas)
    ERROR Line 25: Redefinition of VAR. (DT_INTS-18.bas)

    Which are these lines in the code:

    Code:
    wsave       var byte  BANKA  SYSTEM   ' location for WREG
    ssave       var byte  BANK0  SYSTEM   ' location for STATUS register
    bsave       var byte  BANK0  SYSTEM   ' location for BSR register
    I am unsure as to what the problem is and where to start.

    I'm using PBP 2.60A and MCS 3.0.0.5

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Fixed the above issue.

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Getting frustrated! :-) I've tried a bunch of things to get the counter to count down correctly.

    There is a problem at rollover. Let's say the timer is set to 1 hour 1 minute zero seconds, it should start there and one second later change to 1:00:59. It doesn't, it stays at 1:01:00 for 1 second and then counts down from 1:01:59. Then when it gets to 1:00:00 it rolls over to 0:00:00 for 1 minute then the next second its at 0:59:59.
    Not really sure what to try. What about a "first run through the interrupt" flag that automatically makes minutes = minutes - 1 and starts the seconds at 59?
    Last edited by jmgelba; - 25th October 2012 at 02:12.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Hi,
    Without thinking too much, how about this:
    Code:
    Hours VAR BYTE
    Minutes VAR BYTE
    Seconds VAR BYTE
    
    Hours = 1
    Minutes = 1
    Seconds = 0
    Ticks = 100
    
    ISR:
      Ticks = Ticks - 1
      If Ticks = 0 THEN              ' Ticks rolled over, one second has passed
        Ticks = 100                    ' Reset ticks (10ms ticks)
    
        Seconds = Seconds - 1     ' Count down a second.
    
        If Seconds = 255 THEN      ' Seconds rolled over
          Seconds = 59                 ' Reset seconds
          Minutes = Minutes - 1      ' Count down a minute
    
            If Minutes = 255 THEN  ' Minutes has rolled over
              Minutes = 59              ' Reset minutes
              Hour = Hour - 1         ' Count down an hour
            ENDIF
        ENDIF
      ENDIF
    /Henrik.

  6. #6
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Henrik, thank you for your reply. It is very logical.

    I came up with this before you posted your reply last night:

    Code:
    if seconds => 59 then
    minutes = minutes - 1
    minuteschanged = 1
    endif
    if seconds > 59 then
    seconds = 59
    endif
    
    
    if Minutes => 59 and seconds => 59 then
    hours = hours - 1
    HoursChanged = 1
    endif
    IF Minutes > 59 then
    Minutes = 59
    endif
    
    if hours = 0 then
    Days = Days - 1 
    DaysChanged = 1 
    Hours = 0 
    endif
    
    IF HOURS > 23 then
    HOURS = 23
    ENDIF
     
    endif
    ENDIF
    It works and has been running all night. Yours is cleaner though! My issue was I was trying to change numbers at 0 not 0 - 1. Once I realized this is took 2 minutes to fix it.

  7. #7
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    This interrupt based timer runs in the background. Does that mean a pause in the main program will stop it or will it continue to run in the background? I am trying to de-bounce a switch.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 23:14
  2. Get elapsed time while TIMER samples pulses
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th March 2009, 17:27
  3. Elapsed Timer Demo in a PIC12F675
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st November 2008, 01:01
  4. Totally Baffled with Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th June 2008, 22:01
  5. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 02:22

Members who have read this thread : 5

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