DT’s Elapsed Timer Magic Trick


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Thanks
    It wasn’t my idea to use timer1 values as RAM that survives WDT reset,
    but I figure as long as you haven’t started timer1, you could just write the count into
    one of the timer1 bytes instead of on-chip EEPROM and read the value after the reset.

    For my clock board I have swapped the 8MHz crystal with a 20MHz crystal,
    and added a dual flip flop to divide two of the clocks, so now have:
    8,12,16,20 & 24MHz. One dual more flip flop, and I’ll have 6 & 10MHz as well.
    It has been reliable so far with the freqs I can test, bust suspect any 1MHz increment is easy to detect.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Ok, after a little experimentation today, finding the frequency without any use of EEPROM at all is really this easy:
    Code:
    '
    DEFINE OSC 20				‘needed so the 100ms pause period is known
    '
    if status.bit4 = 1 then			'was not reset by watchdog
    for percount = 0 to 255			'do eeprom writes until wdt reset
    pause 100				'
    @ MOVF	_percount	,W		;copy counter value to timer low byte 
    @ MOVWF   TMR1L				;load timer with count value
    next percount				'
    makereset:				'failsafe to make reset occur
    goto makereset				'
    '
    else					'hardware was reset by watchdog
    @ clrwdt				;
    @ MOVF	TMR1L	,W			;copy counter value to timer low byte 
    @ MOVWF  _wrtcount			;reload timer with correct value
    endif					'
    '
    Then you have a number in wrtcount that represents the crystal frequency i.e. a couple of values either side of 25 = 20MHz.
    This is with the power timer also set, but I doubt that matters as the pic isn’t doing anything in power timer period.

    In any case, it’s very handy to know that if you’re not using Timer1,
    you have an ordinary word variable that survives WDT for certain.

    If your program was going to use Timer1 after this, the values should probably be reset to zero, then the clock started.
    DT’s Elapsed Timer code does have a Reset feature which probably does this as well as clearing it's real time variables.
    Last edited by Art; - 3rd April 2015 at 08:43.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Compiling error on Elapsed timer
    By tacbanon in forum General
    Replies: 2
    Last Post: - 9th September 2012, 13:09
  3. SPWM and Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th May 2008, 03:16
  4. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 01:22
  5. 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 : 1

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