help: countdown with timer0 interrupt


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Well, it does not work as expected.

    First I have a problem with the other interrupts (I poster a message today about this) but with my settings I was expecting a TMR0 overflow evey 10ms but it happens every 1ms...

    TMR0 starts at 98, and I'm using a 8MHz intosc.
    0.5Us per instruction cycle (FOSC/4).

    Strange...

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    Well, it does not work as expected.

    First I have a problem with the other interrupts (I poster a message today about this) but with my settings I was expecting a TMR0 overflow evey 10ms but it happens every 1ms...

    TMR0 starts at 98, and I'm using a 8MHz intosc.
    0.5Us per instruction cycle (FOSC/4).

    Strange...
    8,000,000 Hz oscillator / 4 = 2,000,000 instructions/second = 2,000,000 increments of TMR0 using a prescale of 1:1 (prescaler assigned to WDT).
    TMR0 is an 8 bit timer, max count = 256. You're reloading it with 98, leaves you with 158 counts.
    2,000,000 / 158 = 12,658.228 Hz = 79us per interrupt.
    2,000,000 / 256 = 7812.5 Hz = 128us per interrupt.
    So, you're 10ms theory (since we don't have any better information) isn't going to work.
    But this might:
    http://www.mister-e.org/pages/picmulticalcpag.html

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    8Mh/4 = 2000000 op per s.
    1:128 prescale = 2000000/128 = 15625 per s.
    Preload with 98, 158 counts.
    15628 / 158 = 98.89 Hz
    1000ms/100 = 10ms

    What's wrong?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    1:128 prescale = 2000000/128 = 15625 per s.
    What's wrong?
    You left out that vital bit of information (the 1:128 prescale).

    So, it's happening every 1ms instead of 10ms?
    Are you sure you're correctly clearing/re-enabling the correct interrupt after you are done processing the interrupt...or is the interrupt sequence 'jumping right back into itself' after you are done processing it?
    Last edited by skimask; - 19th August 2008 at 15:07.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. 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
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. Ping Darrel Taylor - Timer0 Instant Interrupt
    By JEC in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2007, 11:20
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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