TMR0 Pre Scale Question


Results 1 to 7 of 7

Threaded View

  1. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yep. So with a 16-bit timer, 1:1 prescaler, 20MHz osc, it will count up & roll-over in
    200nS * 65,536, which = ~13.1mS.

    If you can live with a few uS short of 1 second, then you can change the prescaler
    to 1:256, and do something like this;

    Code:
        DEFINE OSC 20
        TMR0_FLAG VAR INTCON.2  ' Timer0 over-flow flag bit
        
        TMR0H = $B3       ' $B3B5 = 46,005
        TMR0L = $B5
        TMR0_FLAG = 0     ' clear TMR0 over-flow flag
        T0CON = %10000111 ' 16-bit, 1:256 prescale, TMR0 ON
        
    Main:
        REPEAT            ' just loop waiting for over-flow flag
          @ NOP
        UNTIL TMR0_FLAG = 1
        
        TMR0_FLAG = 0     ' clear over-flow flag
        TMR0H = $B3       ' reload for 1 second over-flow
        TMR0L = $B5
        TOGGLE PORTB.0
        
        GOTO Main
    Works out to roughly 0.999 seconds per toggle.
    Last edited by Bruce; - 8th March 2008 at 15:34.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  3. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  4. using TMR0 as a counter..
    By sirvo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th July 2007, 02:56
  5. Help to Pre Scale 4mhz to 20mhz
    By jetpr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th September 2005, 03:30

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