Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    No, the Elapsed Timer Demo can only have one timer at a time.
    The same concept can be used to create multiple timers, but this demo doesn't do that.

    Since the ON and OFF periods can't happen at the same time...
    When one period is finished, Reset the timer and measure the next period.
    You only need one timer.

    You don't have to stop and start the timer, just GOSUB ResetTime, and the time will revert to 0d-00:00:00.0 and keep counting.
    Use it like a Stopwatch.

    The interactive LCD on this page shows how it works. (Click on the "GOSUBs")
    http://www.darreltaylor.com/DT_INTS-14/elapsed.html
    But that page is for the DT_INTS version of the Elapsed Timer.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Well I've had an implementation of this working great for months now. Its counts down 20 minutes, turns off the output, flashes an LED using the pause command, then sits there waiting for the input to start again.
    I need to add a feature now though. As the time reaches 15 minutes, I need it to flash an LED at 2Hz while still counting down and turning off at 20 minutes.

    Currently the code is like this:

    Code:
    
    IF MinutesChanged THEN
        MinutesChanged = 0
        IF Minutes = 20 THEN
        HPWM 1, 0 , 30000
        POWER = 0
        LEDS = 0
        CURRENT = 0
    If I change it to this will it do what I need it to do? Second thing is if it will, how do I flash an LED while still running the main program? I am using HPWM already.

    Code:
    IF MinutesChanged THEN
        MinutesChanged = 0
        IF Minutes = 15 THEN
        GOSUB Flashyflashy
    ENDIF
    
    
    IF MinutesChanged THEN
        MinutesChanged = 0
        IF Minutes = 20 THEN
        HPWM 1, 0 , 30000
        POWER = 0
        LEDS = 0
        CURRENT = 0
    ENDIF

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Hi,
    I'm not that familiar with the code but the way you suggest will only call FlashyFlashy when minutes is 15 - not more, not less. If you want FlashyFlashy to keep executing all the way to 0 you need IF MINUTES <= 15 THEN You could also streamline it a bit, there's no real need to check and reset MinutesChanged twice, perhaps something like
    Code:
    IF MinutesChanged THEN
        MinutesChanged = 0
    
        IF Minutes <= 15 THEN
        GOSUB Flashyflashy
    
        IF Minutes = 20 THEN
        HPWM 1, 0 , 30000
        POWER = 0
        LEDS = 0
        CURRENT = 0
    ENDIF

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Jim,

    I think that'll just flash it once at the 15 minute point.

    This should work.
    Code:
     Flashing VAR BIT
    
       IF MinutesChanged THEN
            MinutesChanged = 0
            IF Minutes = 15 THEN Flashing = 1
            IF Minutes = 20 THEN
                Flashing = 0
                HPWM 1, 0 , 30000
                POWER = 0
                LEDS = 0
                CURRENT = 0
            ENDIF
        ENDIF
    
        IF Flashing THEN
            SELECT CASE Ticks
              CASE IS <25 : HIGH LED
              CASE IS <50 : LOW  LED
              CASE IS <75 : HIGH LED
              CASE ELSE   : LOW  LED
            END SELECT
        ENDIF
    
    Last edited by Darrel Taylor; - 26th April 2012 at 22:08.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Darrel, can this be used as a countdown timer with the time left updated each second and displayed on a LCD?

    Thanks.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    It Can ...

    But you would need to create the count down routine.
    The demo only counts up.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    OK thanks. I will play around with it and see what mess I can create.

Similar Threads

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

Members who have read this thread : 2

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