DT_Elapsed timer constant for 40 MHz?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156

    Default DT_Elapsed timer constant for 40 MHz?

    I'm running with the version of DT_INTS found on your website, and ASSuming those are the latest.

    http://darreltaylor.com/DT_INTS-18/home.html

    One small problem, though. I'm running this PIC at 40 MHz, and would like to use your Elapsed timer interrupts. Do you have a TimerConst that I can use at this frequency?

    Len

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    40mhz is too fast to get a 100hz interrupt without a pre-scaler.

    So what you will have to do is add this to the frequency part of Elapsed_INT-18.bas

    Code:
      If OSC == 40
    TimerConst = 0CF2Dh
      EndIF
    And then add this line somewhere near the start of your program to set a 1:8 prescaler on TMR1.

    Code:
    T1CON.4=1
    T1CON.5=1
    *note* untested

    *edit* changed values to make it more accurate
    Last edited by Kamikaze47; - 11th July 2010 at 08:16.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Wink

    Thanks for that. Inside the Elapsed_INT-18.bas file, was reference to a link that was suppose to show you how to calculate different TimerConsts for different crystal frequencies, but it is now dead. I will test this tomorrow.

    Can I add the prescaler to the Elapsed_INT-18.bas like this, or does it have to be external?


    If OSC == 40
    T1CON.4=1 ; Set a 1:8 prescaler
    T1CON.5=1 ; on TMR1
    TimerConst=0CF2Dh
    EndIF
    Last edited by circuitpro; - 11th July 2010 at 18:23.

  4. #4
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    doh! (nevermind)

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


    Did you find this post helpful? Yes | No

    Default

    Kamikaze47's numbers are theoretically correct, and it will appear to work.

    However, this is the reason I never added OSC frequencies above 20mhz to the Elapsed timer ...
    Anything over 24mhz would require a prescaler to get 100hz interrupts.
    And every time you reload the Timer, the Prescaler gets cleared.

    With a 1:8 prescaler, it could lose up to 7 counts on every interrupt.
    At 100 hz, it could lose up to 700 counts every second. That's 70uS with 40mhz OSC.
    Not good for a clock, especially in the long term.

    I was thinking about it yesterday and realized that I could make a software "postscaler" in the ISR and run the interrupts at higher frequencies for the chips running >24mhz.

    So that's what I did.
    The attached version of Elapsed_INT-18.bas (ver 1.2) should work with any OSC.

    The TimerConst is now calculated automatically instead of using "constants".
    The Timer is always 1:1, and at 40mhz will run at 200hz.
    Then the handler counts off 2 groups of 100 ticks (1:2 postscaler).
    @ 64mhz the timer is 400hz, with a postscaler of 1:4.

    You can use the INT_Handler as an ASM "type" interrupt to save overhead.

    I've only had it running a few hours @40mhz, but it seems to be keeping time really well. (better than my PC).
    We'll see what it's like after a few days.

    hth,
    Attached Files Attached Files
    DT

Members who have read this thread : 0

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