Elapsed Timer Demo


Closed Thread
Results 1 to 40 of 112

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    I'm trying this code on an 877 and it work great, nice job. I would however like to run it on a 452 or a 4620. What would I have to change for this? I was looking thought the files and came across the lines:

    Code:
      IF OSC == 4                       ; Constants for 100hz interrupt from Timer1
    TimerConst = 0D8F7h                 ; Executed at compile time only
      EndIF
      If OSC == 8
    TimerConst = 0B1E7h
      EndIF
      If OSC == 10
    TimerConst = 09E5Fh
      EndIF
      If OSC == 20
    TimerConst = 03CB7h
      EndIF
    What would these be if I wanted to say run a PLL at 4 MHz or a PLL at 10 MHz?

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


    Did you find this post helpful? Yes | No

    Default

    The easiest way to figure out the constant at any OSC is to use the Timer Calc form at ...
    http://www.picbasic.co.uk/forum/showthread.php?t=2031

    For instance, in the form, enter 4 in the OSC field, then put 100 in the bottom Freq field. Press Calculate, and it shows that it takes 10,000 "Ticks" of the timer. And the number to reload into the Timer on each interrupt is 55543, or 0D8F7h This is the same number shown in the ASM section you listed, for 4Mhz.

    That's 65536 - 10000 + 7

    7 is the number of instructions used to reload the timer. (Elapsed.bas : ADD2_TIMER)

    So, just plug in the new OSC value (Any crystal or PLL Freq) and enter 100 in the FREQ field. The new constant can be added to the ASM section of Elapsed.bas.

    Also, I have a version of "Elapsed" for the 18F's. I'll send it, later tonight, when I get off work.

    L8R,
    Darrel
    Last edited by Darrel Taylor; - 7th December 2005 at 04:44.

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


    Did you find this post helpful? Yes | No

    Default Elapsed-18.bas

    Here's the version for 18F's.

    It should be a drop-in replacement for the old version. Everything works the same, except for the registers saved on entry to the INT routine.

    So, you can still use the Test_Elapsed_LCD/SER.bas demo's from the original version for testing. Just add the "-18" to the INCLUDE line.
    <br>
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 7th December 2005 at 06:39.
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    It works like a charm, thank you vary much. Now I can finish making my waterbed temperature controller.

  5. #5
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile To Darrel

    Hi Darrel

    I was wondering if elapsed timer code is accurate enough to make a digital clock and calender, showing time and date.

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Hi crematory,

    That depends on the accuracy of the crystal being used, and the ambient temperature.
    And, you'd probably need to have some kind of backup battery, to keep it going during any power outages.

    I think I calculated it at around +/- 4 minutes per year with a standard 20mhz crystal. It was around 20 seconds/year with one of those temperature compensated TTL Oscillators.
    <br>
    DT

  7. #7
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor
    Hi crematory,

    That depends on the accuracy of the crystal being used, and the ambient temperature.
    And, you'd probably need to have some kind of backup battery, to keep it going during any power outages.

    I think I calculated it at around +/- 4 minutes per year with a standard 20mhz crystal. It was around 20 seconds/year with one of those temperature compensated TTL Oscillators.
    <br>

    4 Minutes a year, that is more than acceptable for me, I will be happy with that in deed.

    I was wondering if you can through a hint for using the rest of interrupts in the PIC when using the elapsed timer code, shall I use your way to handle other interrupts, or what should I exactly do.

    Thanks Darrel

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Hi crematory,

    That depends on the accuracy of the crystal being used, and the ambient temperature.
    And, you'd probably need to have some kind of backup battery, to keep it going during any power outages.

    I think I calculated it at around +/- 4 minutes per year with a standard 20mhz crystal. It was around 20 seconds/year with one of those temperature compensated TTL Oscillators.
    <br>

    Hi Darrel,

    Could you suggest a good "one of those temperature compensated TTL Oscillators" please ?

    Also, if aging for an oscillator is stated, say, +/-5ppm a year or +/- 100ppm a year, what would it mean in your elapsed timer application?

    Last question, if I modify your routine to work for 100years, forget about power failures etc., and use a good osc as you may suggest, what would be a possible problem as years pass by?

    Thanks.


    --------------
    Last edited by sayzer; - 24th December 2008 at 18:43.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #9
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Any idea why I get this error?

    Quote Originally Posted by Darrel Taylor
    Here's the version for 18F's.

    It should be a drop-in replacement for the old version. Everything works the same, except for the registers saved on entry to the INT routine.
    <br>

    Hello Darrel,

    I tried using your Elapsed-18 for use with my 18f452 and when I compile I get these errors:

    Error(113)c\pbp\10tim~2asm 503:Symbol not previously defined (TimerConst)
    Error(113)c\pbp\10tim~2asm 507:Symbol not previously defined (TimerConst)

    Would you have any ideas why I'm getting these errors or what I could try to get it to compile? I got my new version of PBP 2.47 installed now.

    Thanks
    jessey

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


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default

    Hi Jessey,

    What OSC are you using?

    The Elapsed-18.bas only has constants for 4,8,10,20 and 40 mhz.

    If it's something different, it needs a new constant.
    See Post #17
    <br>
    DT

  11. #11
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default It was the define for the crystal

    Quote Originally Posted by Darrel Taylor
    What OSC are you using?
    <br>
    Hi Darrel,

    I was running my pic at 16 mhz, I changed it to 4 and its working great now.

    Thanks A Lot
    jessey

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