DT Interupts PortA or PortB?


Results 1 to 6 of 6

Threaded View

  1. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: DT Interupts PortA or PortB?

    Hello Shane,
    I'm jumping in here with my couple of cents worth...
    TMR3 trips an interrupt when it overflows. It's 16bits wide so it counts from 0 to 65535 and then overflows back to 0, tripping the interrupt. If you have the TMR3 prescaler set to 1:1 (which you have) the timer "ticks" at Fosc/4 or 5Mhz in the case of a 20MHz x-tal. 5MHz/65536=76.3Hz which is your interrupt frequency.

    If you want it to interrupt at higher frequency all you need to do is preload TMR3 with a suitable value each time it interrupt. If you preload it with 51350 then you'll get an interrupt frequency of roughly 5Mhz/(65536-51350)=352Hz.

    Remember that you have to load the timer each time it overflows, not just once. This is best done by stopping the timer and then ADD the preload value to the content of the timer registers, this way the interrupt latency is catered for.

    Using TMR2 may be better since it interrupts when it matched PR2 and automatically resets so you don't need to preload in each interrupt.

    With all that said, if you're already HAVE a timer interrupt (TMR1 in your case) why not use that. There's no reason you can't check your input AND keep time (if that's what you're doing) from within the same ISR. There's usually no need to have a separate timer for each and every task.

    /Henrik.
    Last edited by HenrikOlsson; - 8th December 2011 at 09:59.

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