TMR1 100Hz Exactly Interrupt Routine


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Why 10 mS, 100 Counts? You are thinking like a person and not a computer. Computers like powers of 2s not 10s.

    Why not use a 4.194304MHz Xtal (DigiKey has them in stock for $0.70 ea), let Timer 1 run free, set the prescaler to 8, and count TMR1 overflows. 2 Overflows = 1.000 sec. This gives you lots of time to do other stuff in between interrupts.
    (math = 4/4.194304*65536 * 8 * 2 = 1000000 uS = 1 S)

    Oh yeah, you also do not have to deal with accounting for the timing for saving registers etc because the timer is free running.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  2. #2
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Hi Paul
    Thanks for your help!!!!!!!!!
    Youre right, im quite new to programming and still not used to power of 2!!
    Anyway, which crystal do you recommend to use to run close to 20MHz???
    Thanks a million
    Manuel

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink My two cents ...

    100 Hz ...

    might have very precise 100 Hz timebase from mains ... just a trafo and two rectifiers !!!

    just an idea ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have a look here http://www.pbpgroup.com

    Darrel has some excellent PBP examples.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Hi. Thanks for all the help.
    Is the line frequency accurate enough to make a clock??? Hope it is!!!!! Great idea anyway. Thanks.
    Manuel

  6. #6
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Smile math

    DigiKey has a 19.6608mhz crystal. If I did the math right...

    math = 19,660,800/4/65536 =75 cycles
    Your interrupt will happen 75 times/second. In software count to 75 and then add 1 to the second number.

    or

    last time I used a 20,000,000 crystal
    20,000,000/4/65536=76.29395hz In software dividing by 76 is not good but close.
    The interrupt happens 76.29395 times/second.
    I used a 16bit variable and on every interrupt added 859 to the number. The variable overflows once per second. I think the math is off by .001%

  7. #7
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Thumbs up

    hi ronsimpson!!! thanks for your help. i have two questions:
    to calculate the interrupts with TMR1, I thought you had to divide the value by 66535 (0xFFFF). But, as you say, its 66536 because 0x0000 counts, right?
    And one last thing. Suppose that a WORD variable is loaded with 60,000
    Now we add to that variable, say 1000. Which is going to be the next result??? Is it going to be 0000 because it overflowed, or is it going to be 4535??? (60,000 + 1,000 - 65,535)???
    Thanks for your help. Really quick answers you get in this forum!!!!!!!
    Manuel

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  2. 16F876A CCP1 Capture/Interrupt Question
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th January 2008, 03:25
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. Multi Interrupt How To ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2005, 14:48

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