Timer Questions


Closed Thread
Results 1 to 10 of 10

Thread: Timer Questions

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Thanks to all, this helps tremendously.

    I have it firing to the second over a 30 minute period so I must have done something right.

    BaudRates.... I normally use either 4 or 20 Mhz clocks and this is my first time with an 8 mhz.

    With the 8 mhz, I can do 9600,N81 Easy and reliable, but at 19,200 N81, I get lots of errors and garbage.

    Is the 8 mhz to slow to do 19,200 reliably or is it something else maybe? I'm not doing much in the program at all, mainly just a SerIn2 with a 50ms timeout, after the timeout, I just go back to serin2 and wait.

    TIA,
    Richard

  2. #2
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    I found a chart on the net. It pretty much states that 8 mhz is too slow for 19,200 so I jumped to a 20 mhz and all is well. Even recalibrated my timer routines.

    Thanks for all the help here.

    Richard

  3. #3
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Smile Timer - More

    Okay, See if I learned anything.

    OSC 20

    20 mhz / 4 = 5 mhz
    1 second / 5,000,000 = 0.0000002

    Each tick is 0.0000002 seconds

    So, I would need 50,000 ticks to make it fire 100 times per second.

    Since the timer counts up to 65535 and we roll over I would do this....

    65,535 - 50,000 = 15535

    Preload the timer with 15535 then
    0.0000002 x 50,000 = 0.01
    So the Timer would fire every 100 times per second

    Why then do I have to preload the timer with 15543 to make it dead on? Is this just a difference in osc frequency.

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


    Did you find this post helpful? Yes | No

    Default

    65,535 - 50,000 should be 65,536 - 50,000. Your load value would be 15536.
    It takes 65,536 cycles (0 to 65,535 + 1 additional cycle) for the 16-bit
    overflow or roll-over from 65,535 back to 0.

    Why then do I have to preload the timer with 15543 to make it dead on? Is this just a difference in osc frequency.
    Because the timer is still counting while you're doing things after it rolls-over.

    You need to compensate for time passed (timer counts) while your program is
    doing something after the roll-over. The timer is still counting during this time
    frame.

    You can either write an adjusted value to the timer, or simply "add" your real
    value to the existing count already held in the timer registers.

    Adding the real value to the existing timer count is the prefered method as
    long as your program doesn't tinker around long enough to where adding to
    the count would cause immediate over-flow after the add.
    Regards,

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

  5. #5
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Red face

    If the time is not precise enough for you, you can use CCP1 in order to restart Timer1 automatically.
    But I think it is to heavy for a beginner.
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  6. #6
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Oh, the time is plenty close enough for what I'm doing. I just asked so I could learn and take notes.

    Thanks agin for the help...

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 + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  4. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  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 : 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