Reading Timer1 value


Results 1 to 9 of 9

Threaded View

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


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by DynamoBen
    In the datasheet there is a note stating "...the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads"

    ... That (DynamoBen's) max. value should not get to the point where the timer would overflow:
    You not only need to worry about the timer overflowing from $FFFF to $0000 but from $xxFF to $x(x+1)00. IF you read the lowbyte and then the lowbyte overflows before you read the high byte, you will get the wrong answer. If you cannot stop the timer in your application, try something like this

    Code:
    X var BYTE ' in addition to your variables
    
    period.highbyte = TMR1H
    period.lowbyte = TMR1L
    X = TMR1H – period.highbyte
    If X = 0 then Continue
    period.highbyte = TMR1H
    period.lowbyte = TMR1L
    Continue:
    to ensure you get the correct time. (If at all an option, I would stop timer before reading and then your issue goes away.) Although you did not mention it, you should stop the timer before you write to it per a recommendation from Microchip.

    Paul Borgmeier
    Salt Lake City, Utah
    USA
    Last edited by paul borgmeier; - 19th June 2006 at 08:29.

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 16:25

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