DT’s Elapsed Timer Magic Trick


Closed Thread
Results 1 to 22 of 22
  1. #1
    Join Date
    Aug 2003
    Posts
    985

    Default DT’s Elapsed Timer Magic Trick

    Hi Guys

    Do you think it's possible for a program running on pic 16F628A with no additional hardware,
    connected only to:
    1) a power supply
    2) a single wire clock signal to pin 16 CLKIN
    3) an LED
    to tell what frequency the hardware is running at and adjust DT's Elapsed Timer constant
    accordingly so the LED will flash once per second no matter what crystal is connected?

    I think the answer will be no, but already disagree
    If it turns out too easy, I won’t bother posting the video so fire away!
    Cheers, Art.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    This is the hardware....
    A hardware selectable logic buffered clock, or you can turn them all off and the pic won’t run at all.


  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    So where's the LIKE button?

    Robert

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Thanks
    If it is figured out I want it outed, and if not I’ll take it to the world of YouTube but will then give it up

  5. #5
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    It's easy, when PIC have internal osc...
    You can use same method to calibrate internal OSC, when OSCCAL value is erased.
    Just feed in known clock reference and adjust internal clock Until you get correct result.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    There’s no known clock reference being fed into it.
    It can currently be any of three clocks so it’s unknown.
    The pic’s clock is set to HS, and is clocked by one of the three signals connected.
    8, 16 or 24 MHz.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Honestly, I don't understand.
    Are you asking us to help you come with a way to do it or have you already done it and asking us if we too can figure it out?
    I can't help thinking about what date it is today....

    /Henrik.

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Is it ok to swear here?

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I’m asserting it’s done, and asking if you too can figure it out.

    I should have picked another day. It’s the 2nd now in Aus, but I’ll come back tomorrow
    It is what I say it is I swear.

  10. #10
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    That’s awesome. I just need to make a YouTube video right now 10 hours ahead UTC.
    This should be a pretty good April Fool’s joke.

  11. #11
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I’m disappointed
    I guess I’ll have to spill the answer tomorrow.


  12. #12
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I am a total noob, but I feel such cleverness deserves a guess - even if only to prove how far superior your skills. I am unwilling to just shrug and wait for you to reveal your skill without so much as voicing the consideration I have given - not so much a joke, but puzzle - you have provided.

    I will guess that there is some capacitance in the circuit and that you use some application of the RCTime constant as a reference; different clocks would, I think, reveal the clock speed by the timer values measured when charging and discharging a capacitor from a known voltage. I take my guess from watching the LED (which, I believe has a capacitance associated - and conveniently a resistor in series) which is slow to start - I'm hoping, because it is busy measuring...

  13. #13
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Interesting idea, but not tested by me so I don’t know if it would work

    The virtue in what I’m doing is someone might come up with a better way,
    and at the moment I would appreciate that.
    It’s not genius trust me, you’ll find out. Someone is close on another forum.

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    2015 nominee for best computer generated animations.

    Robert

  15. #15


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    628A has two internal clocks

  16. #16
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I know of the 4MHz RC clock. What’s the other?

  17. #17
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    It got figured out on another forum. A better way actually, without writing to the on-chip EEPROM at all.

    Code:
    '***********************************************************************************
    '*                                                                                 *
    '*                    Microchip Pic 16F628 @ 8,16 or 24MHz                         *
    '*                                  Art 2015                                       *
    '*                                                                                 *
    '*                          [email protected]                               *
    '*                                                                                 *
    '***********************************************************************************
    '
    '
    DEFINE OSC 20								'
    DEFINE NO_CLRWDT							'watchdog is cleared manually
    '
    INCLUDE "Elapsed.bas"							‘modified to take a variable
    '
    ' execution time!
    '
    '
    percount var byte							'
    wrtcount var byte							'
    clkvalue var byte							'
    xdata var byte								'
    'oscfreq var word							‘this is declared in Elapsed Timer file
    notreset var bit							'
    '
    CMCON = 7									'set ports digital
    trisb.4 = 0									'set led output
    portb.4 = 0									'
    '
    percount = 0								'
    clkvalue = 0								'
    '
    '
    notreset = status.bit4						'check wdt reset occured - 0 is did reset
    '
    '
    if notreset = 1 then						'was not reset by watchdog
    portb.4 = 1									'turn led on
    for percount = 0 to 255						'do eeprom writes until wdt reset
    pause 100									'
    write percount,$00							'
    next percount								'
    makereset:									'failsafe to make reset occur
    @ nop										;
    goto makereset								'
    else									'was reset by watchdog
    @ clrwdt									;clear the watchdog from now on
    wrtcount = 0								'reset write counter
    countwrites:								'count eeprom writes
    read wrtcount,xdata							'read byte
    @ clrwdt									;
    pause 10									'
    if xdata != $00 then						'
    goto donecount								'exit counting loop
    endif										'
    wrtcount = wrtcount + 1						'increment count
    goto countwrites							'
    donecount:									'
    for percount = 0 to 255						'erase the eeprom for next time
    pause 10									'
    @ clrwdt									;
    write percount,$FF							'
    next percount								'
    endif										'
    '
    'gosub flashout								'for testing only
    '
    oscfreq = 0									'reset oscillator frequency
    '
    if wrtcount > 8 then						'11 
    oscfreq = $B1E7									'set oscillator frequency
    endif										'
    if wrtcount > 18 then						'21
    oscfreq = $63C7								'set oscillator frequency
    endif										'
    if wrtcount > 27 then						'30
    oscfreq = $15A7								'set oscillator frequency
    endif										'
    '
    '
    gosub ResetTime								'reset time 00:00:00
    gosub StartTimer							'start clock timer
    '
    '
    '
    cycle:
    @ clrwdt
    if Ticks > 49 then
    portb.4 = 1
    else
    portb.4 = 0
    endif
    goto cycle
    '
    '
    '
    flashout:									'flash out the count of eeprom writes before wdt reset
    for percount = 0 to wrtcount				'with the red led
    portb.4 = 1									'flash rate will still depend on oscillator frequency
    pause 250									'at this stage
    @ clrwdt									'
    pause 350									'
    @ clrwdt									'
    portb.4 = 0									'
    pause 250									'
    @ clrwdt									'
    pause 350									'
    @ clrwdt									'
    next percount								'
    pause 500									'
    @ clrwdt									'
    pause 500									'
    @ clrwdt									'
    pause 500									'
    @ clrwdt									'
    return										‘
    '

  18. #18


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I know of the 4MHz RC clock. What’s the other?
    Actually there are three, 4 Mhz and 48Khz internal clocks and the WDT

  19. #19
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    I always thought the wdt clock was derived from the internal RC clock, but some Googling confirms it's not.

    Fortunately it appears Timer1 does not get reset with the wdt, so the byte values in the timer register
    could be used instead of writing to EEPROM.

  20. #20
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DT’s Elapsed Timer Magic Trick

    Pretty clever Art!
    Regards,
    TABSoft

  21. #21
    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.

  22. #22
    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