Counting Timer0 and Timer1 overflows without any interrupt handler


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    I had a question...but connected the dots when I posted it.
    Last edited by dw_picbasic; - 19th February 2014 at 21:12. Reason: tried to remove the question....got it :-]

  2. #2
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Hi Darrel,
    I'm curious about something in the code
    I see that you capture the Timer1 overflow count and load it into RESULTS.[bit16-31]
    Then load the remaining count in TMR0 into RESULTS.[bit8-15]
    But I thought that TMR0 is a 16 bit register....how is it we're loading its value into an 8 bit location in RESULTS?

    Thanks!!
    Duane :-]

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Hi Duane,
    No, the TMR0 register is only 8 bits wide, that's why you need to use the trick with getting the remaining count out of the prescaler.
    So, RESULT is a total of 4 bytes where the two most significant bytes are the number of TMR0 overflows, the next byte is the TMR0 count (where each count equals 256 transitions of the inputsignal due the 1:256 presacaler ratio) and the least significant byte is the number of transitions "stored" in the prescaler.

    /Henrik.

  4. #4
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Ah!
    Thats right!!...sorry... I forgot the Timer0 is an 8 bit register.
    I slipped on that one :-/

    Thanks!

  5. #5
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Can I pose another question:
    Lets say that the frequency that is being measured within the 1 second gate period is 301234hz
    Is it the case that the value that will be captured within T0overflow, RESULTS.[bit16-31] = (301234/256)?
    Which (in integer form) would resolve to 1176 overflows of the Timer0 8 bit register?
    And then the remainder value of 178, which remains within TMR0 will be loaded into T0value RESULTS.[bit8-15]?
    Thanks!!
    Duane

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


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    The prescaler divides by 256, and TMR0 divides by 256.
    So the overflows only happen every 65536 counts.

    With a frequency of 301234, there will only be 4 overflows, with 39090 remaining.
    That's 152 in TMR0, and 178 in the prescaler.

    Another way to look at it is to convert the Frequency to a HEX number
    #301234 = $4:98B2

    Now it's easy to see that there will be 4 overflows, TMR0 will have $98 = 152, and the prescaler has $B2 = 178.

    HTH
    DT

  7. #7
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Thanks Darrel,
    I didn't see the prescaler settings in setup code.
    I see "PSA [OPTION_REG.3] set to 0 which sets the prescaller from the WDT to Timer0
    But I don't see any settings for OPTION_REG.0, 1 and 2.
    Are they there in the code and I missed them?
    Thanks!!
    Duane

  8. #8
    Join Date
    Oct 2005
    Location
    Stuttgart, Germany
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Counting Timer0 and Timer1 overflows without any interrupt handler

    Quote Originally Posted by Darrel Taylor View Post
    The prescaler divides by 256, and TMR0 divides by 256.
    So the overflows only happen every 65536 counts.

    With a frequency of 301234, there will only be 4 overflows, with 39090 remaining.
    That's 152 in TMR0, and 178 in the prescaler.

    Another way to look at it is to convert the Frequency to a HEX number
    #301234 = $4:98B2

    Now it's easy to see that there will be 4 overflows, TMR0 will have $98 = 152, and the prescaler has $B2 = 178.

    HTH
    Hello Darrel,

    found your excellent example and i would like to build the same counter based on PIC16F870. From your above post i understand, that with prescaler 256 minimum measured frequency is 65536Hz, otherwise TMR0 will not overflow, or am i wrong? To measure lower frequencies i would have to change the OPTION_REG bits 2-0 , which will set prescaler to 1:2?

    P.S. My target measurement range is 1 HZ - 1 MHz.
    Last edited by Rufinus; - 16th March 2015 at 14:53.

Similar Threads

  1. Expanding Timer1 counting range
    By sycluap in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 3rd February 2014, 22:00
  2. PIC18 timer0 interrupt handler, still not getting it
    By ImAnEE in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th April 2011, 00:25
  3. DT-INTs Interrupt handler question
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2010, 00:06
  4. Synchronising Timer0 and Timer1
    By manxman in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th April 2008, 23:12
  5. 16F690 TIMER0 and TIMER1
    By nickdaprick in forum mel PIC BASIC
    Replies: 2
    Last Post: - 18th April 2007, 14:49

Members who have read this thread : 2

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