Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    Hi,
    A Pause (or any other command) will not interfere with the interrupt - it'll keep running in the background.
    However, if you're interrupting at a high rate the context saving, interrupt code and context restore will take cycles from the main PBP program without it knowing so your pause may be a bit longer than what you specify. For non critical timings it's not a problem.

    /Henrik.

    EDIT: Obviosuly interrupting at ANY rate will take cycles away from the main program. What I mean is that the faster you interrupt the more cycles will "vanish" and any software timed routines like Pause, SERIN, Pulsin that you have in the main program will be affected.
    Last edited by HenrikOlsson; - 25th October 2012 at 18:50.

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


    Did you find this post helpful? Yes | No

    Default Re: Elapsed Timer Demo

    No the pause length isnt critical. I'm trying to get one switch to start and stop the elapsed timer. So it needs a debounce and a wait period so that it doesnt immediately stop the timer again.

    Here's what I have but it doesnt work to well:

    Code:
    loop1:
    
    For A = 0 to 1000
         IF PORTB.7 = 1 and TimerRunning = 0 then 
         gosub StartTimer
       endif
    next A
    
    if SecondsChanged = 1 then
               LCDout $FE,2, dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
               SecondsChanged = 0
            endif
            
    For B = 0 to 1000
         If PORTB.7 = 1 and timerrunning = 1 then 
         gosub StopTimer
       endif
    next B
    goto loop1
    This means the user has to press and hold the button for 1 second before the timer will start. However, if they press it for 1.5 seconds, then they only need to press it again for half a second and it stops. If they press it for 2.5 seconds, then timer has started, stopped and is half way to starting again.

    I was wondering id something like this would work?

    Code:
    
    'If PORTB.7 = 1 then
    'gosub StartTimer
    'TimerRunning = 1
    'pause 150
    'endif
    
    If SecondsChanged = 1 then
               LCDout $FE,2, dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
               SecondsChanged = 0
            endif
    
    If PORTB.7 = 1 AND TimerRunning = 1 then
    'gosub StopTimer
    'TimerRunning = 0
    'pause 150
    'endif
    I think the problem with both of them is that there is no time between the on if then and the off if then, and there needs to be some sort of logic that says that if the timer is running and the button is still pressed, do not stop the timer until the button has been released and pressed again.
    Last edited by jmgelba; - 25th October 2012 at 19:14.

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 : 4

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