TMR1 100Hz Exactly Interrupt Routine


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    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%

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

  3. #3
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Sorry in my last post, it should have been:
    The variable should have been loaded with 65.000!! NOT 60.000
    And when we add a thousand, do we get just 0x0000 or 465 (65000 + 1000 - 65535)??? Thanks
    Manuel

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


    Did you find this post helpful? Yes | No

    Smile

    1st question divide by 0x010000
    2nd question = 464

    Do you really need 1 second intervals and how exact do you need to be?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Smile

    Thanks paul. I am planning to build a temperature datalogger, that will collect data every two minutes for a month or two, so I need to get it as accurate as possible. Also, in my country, Argentina, there are not RTC availables....

    Now following Ronsimpson way, (the second one, with the 20.000 MHz), the variable to which we add 859 on every interrupt, I should never clear it, right??? Or should I clear it every time the variable overflows???

    Sorry for my english, and thanks again.
    Manuel

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


    Did you find this post helpful? Yes | No

    Smile

    >>collect data every two minutes for a month
    Check out
    http://www.picbasic.co.uk/forum/showthread.php?t=2129
    It would be easy to add in the data logger every two minutes.

    With Ron's approach, do not stop the timer, just add fast after the interrupt.

    Why 20MHz for a datalogger?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Jan 2007
    Posts
    44


    Did you find this post helpful? Yes | No

    Thumbs up

    Hey
    Thanks so much for the links. There great because the dont have interrepts and they are not too complicated!!!
    Yes youre right 20MHz is WAY too much for this project. I could use only 32KHz and bring down the current draw.
    I am going to use an LM34 or LM35 to measure temperature, and I was thinking of shutting it down while im waiting to save power. How long before making the actual measurement do you think I should turn it on so that the sensor has stabilized???
    Thanks
    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, 03:35
  2. 16F876A CCP1 Capture/Interrupt Question
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th January 2008, 04:25
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 21:58
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07
  5. Multi Interrupt How To ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2005, 15: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