Elapsed Timer findings


Results 1 to 40 of 48

Threaded View

  1. #12
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Temporary central repository of Darrel Taylor's works (including Mr E's Multicalc

    I know the instruction time is 20/4 (assuming 20MHz clock).
    So if the timer registers were larger it would count 5M timer ticks per second.

    DT’s Elapsed timer works by subtracting whatever value (depending on the clock speed)
    from the timer overflow value to achieve 100 interrupts (and 8 instruction timer reload) per second.
    I understand the 8 instruction cycles are compensated for in the constant value that will be continually reloaded to the timer.

    My position is that one doesn’t subtract the value from $FFFF, but from $0000 which is where the overflow interrupt occurs.

    The way that I synced the 1Hz pulse generated by the Elapsed timer code to a GPS pulse per second output
    is by connecting it to portb.0 interrupt, and only allowing the interrupt to reset the second once.
    The port.0 interrupt does not look at the timer value, only resets ticks so only synchronised within 1/100th of a second.

    It only takes a little over an hour for a Human to notice (looking at two flashing LEDs) for them to desynchronise.
    If the constant value is incremented by one, I’m on the third hour watching it so far.
    Initially I was using a crystal running the Elapsed timer, but now rubidium.

    Code:
    'in the ISR after time variables are incremented
    ‘so don’t look at this yet, execution hasn’t gone here
    '
    if INTCON.4 = 1 then		' check if portb.0 interrupt enabled
    if INTCON.1 = 1	then		' check if portb.0 interrupt occurred
    INTCON.4 = 0			' disable portb.0 interrupt
    INTCON.1 = 0			' clear portb.0 interrupt flag
    Ticks = 0			' reset current second to gps pulse
    endif
    endif
    ‘
    ‘since the timer ISR was called by port.0 interrupt,
    ‘and not by timer overflow, any value could be in the timer.
    ’The Ticks are reset to extend the length of the current second.
    ‘We are only synchronised to within 1/100th of a second now,
    ‘but that’s enough for this purpose.
    
    ‘
    'at the start of main program
    '
    '
    INTCON.4 = 0			' disable portb.0 interrupt
    INTCON.1 = 0			' clear portb.0 interrupt flag
    '
    INCLUDE "ElapsedTimer.bas"
    '
    'reset, and start the timer, etc.
    ‘
    
    ‘
    ‘when the main program has run for some seconds
    ‘the qualify bit can be set with a button, or auto set after some seconds have passed
    ‘
    if qualify = 1 then		' synchronise command was qualified
    OPTION_REG.6 = 1		' interrupt on rising edge of portb.0
    INTCON.1 = 0			' clear portb.0 interrupt flag
    INTCON.4 = 1			' enable portb.0 interrupt
    '
    ‘some audible verification the sync command was qualified
    ‘
    ENDIF
    Last edited by Art; - 16th May 2015 at 13:21.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. SPWM and Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th May 2008, 03:16
  3. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 01:22
  4. DT Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th March 2008, 23:17

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