Change Timer settings?


Closed Thread
Results 1 to 6 of 6
  1. #1
    brodin's Avatar
    brodin Guest

    Question Change Timer settings?

    How do i change the internal Timer settings? I need to make the ticks occur more often than every 16.384 ms.

    I am building a stopwatch that is going to show the time like xx:xx:xx (minutes, seconds, hundreds of a second).
    It would be perfect with a tick every 10 ms or less.

    I have read that it should be possible to change the "prescaler". Don't really know what it means though...



    Is there any more manual than the original PBP manual from MEL? I would like some with more information. Or is there any good internet site?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Download the Datasheet for the PIC that you're using. Read the Timer sections, they explain in detail how the timers work. Your timer tick will depend on the oscillator frequency (Xtal) that you've set for your PIC.

    At 4MHz, the timers tick every 1uS. The smallest tick therefore is 1uS. The longest tick depends on a number of factors... Timer0 is an 8-bit Timer, giving a maximum of 255uS (@ 4MHz), Timer1 and Timer2 (if you have them) are 16-bit timers. Interrupts and Flags get set when the Timers roll from $FF ($FFFF) back to zero. By presetting the Timer Registers you can have them count up from whatever preset value you want. Additionally, pre and post scalers are available (depending on your PIC) to extend the range of the timers. Again consult your Datasheet.

    The BEST manuals (other than MEL's PBP one) are actually the manufacturers product Datasheets for what you're using. I can't stress enough that you should study them. It's pretty much all that I use, and what every professional engineer uses.

    Melanie

  3. #3
    brodin's Avatar
    brodin Guest


    Did you find this post helpful? Yes | No

    Default

    I have read the datasheet for my 16F84. But i still don't know how to change the values of the prescaler in PBP.

    I mean, what command should i use? Is it a DEFINE command? Or do i have to make this in ASM?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Just address the Registers by name directly... for example... you want to access Timer0 prescaler... Bits 3 thru 0 of the OPTION_REG Register do that.

    By default, Timer0's prescaler is assigned to the WDT, to reassign it to Timer0 execute the instruction...

    OPTION_REG.3=0

    Any register can be accessed directly by name just as if it was a variable... so TMR0 can be preset...

    TMR0=$2F

    Timer0's overflow flag can be checked like this...

    If INTCON.2=1 then ****

    The only thing you have to remember is that some Registers are used for multiple functions... so setting Timer0's prescaler to 1:256 with this command OPTION_REG=7 is not advised, as bits 4 thru 7 have just been set to zero will affect other completely unrelated things. It's better to do it bit-by-bit like this...

    OPTION_REG.2=1
    OPTION_REG.1=1
    OPTION_REG.0=1

    ...unless you are knowingly setting all eight bits of the port in one hit. That way you're unlikely to inadvertantly set or reset other register bits.

    The PBP manual told you and gave examples of how to access PIC Registers in several places (4.10 Ports and other Registers) is just one such place.

    Melanie

  5. #5
    Mrfarag's Avatar
    Mrfarag Guest


    Did you find this post helpful? Yes | No

    Default Re: Change Timer settings?

    plz I want avery simple program for making a clock on lcd and an explnation of it

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Change Timer settings?

    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  4. Totally Baffled with Elapsed Timer
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th June 2008, 21:01
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 08:41

Members who have read this thread : 1

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