How to start/stop TMR0?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default How to start/stop TMR0?

    I'm using a 16F688, trying to figure out this timer thing and I'm missing something...

    How do I start and stop it?

    I see TMR1 has an enable bit which apparently serves to start/stop Timer1, but can't find any such bit for Timer0.

    Also, there is a paragraph in the data sheet that says the prescaler is not readable or writable.

    Datasheet: 5.1.3 pg 46:
    "The prescaler is not readable or writable. When assigned to the Timer0 module, all instructions writing to the TMR0 register will clear the prescaler."

    Eh?!?! This seems to tell me I can't change the prescaler, and even if I could, as soon as I write a value to TMR0 (like to pre-load it with a value so it times out sooner) then this prescaler will be cleared. This makes no sense.


    I'm just trying to do the super simple task of:

    -setting a prescaler of 1:8
    -load the TMR0 with 5
    -clear the overflow flag
    -start the timer
    -watch for the flag to occur at overflow


    There are also times I'm going to want to stop the timer, read the value, then perhaps re-start it. This would seem to be super simple with a start/stop flag.

    I checked to see if there were any notes in the section about the WDT - maybe starting / stopping the WDT also controls Timer0 as they seem closely linked, but still nothing that was obvious.

    Stumped. Please help.

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


    Did you find this post helpful? Yes | No

    Default

    Timer0 is the Energizer Bunny of the 14-bit PIC world.
    It keeps going and going .... and there is no on/off bit.

    The prescaler value and assignment is in the OPTION_REG register.
    When it says the prescaler will be cleared, it means the value that the prescaler has counted so far. Not the division ration used by it.

    Once you set the prescaler to 1:8, it'll stay there till you change it.
    There are also times I'm going to want to stop the timer, read the value, then perhaps re-start it.
    Not with Timer0.
    It is possible to stop it by switching the clock source to T0CKI (PORTA.4), but that means you can't use that pin for anything else.
    <br>
    DT

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Timer0 doesn't have an enable/disable control bit like timer1 does, but you should be able to
    start/stop timer0 by toggling TOCS in the OPTION_REG.

    If there are no pulse inputs on the timer0 clock input, it should stop incrementing when you
    set TOCS, and restart in timer mode when you clear TOCS.
    Last edited by Bruce; - 29th August 2007 at 15:00. Reason: Boy what timing...;o}
    Regards,

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

  4. #4
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Ahhhh...... that explans a lot.

    Thanks for the tip on how to trick it into sort of stopping for a read.

    I don't feel quite so dumb now.

Similar Threads

  1. 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
  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. Strange behaviour from PIC16F877 on TMR0
    By mikebar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th August 2006, 01:31

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