Timer Accuracy


Closed Thread
Results 1 to 9 of 9

Thread: Timer Accuracy

Hybrid View

  1. #1
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default Timer Accuracy

    Thanks Steve,

    The 60 HZ is out as this will be used on AC and Battery power. I'll do a search for TMR1H and TIMR1L. It's all new to me with only a couple of months experience.

    The Geezer

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


    Did you find this post helpful? Yes | No

    Default

    I hate to tear other peoples code apart, but I think it's shot.

    In one spot you're playing with TMR0...

    TMR0 = 7

    and then you're messing with TMR1...

    T1CON.0 = 1 'TURNS TIMER ON

    So which Timer are you using? And then what interrupt time interval are you keeping track of?

    Also those Pause commands... what are you going to do when an interrupt occurs in the middle of one? Remember, you don't get an interrupt until the current PICBasic command completes.

    As an example (including interrupt usage), have a look at this...

    http://www.picbasic.co.uk/forum/showthread.php?t=632

  3. #3
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default Timer Accuracy

    Thanks Melanie, you just shot my whole timer plan. I didn't think about the pauses.

    I have been writing computer routines in basic anc C for more than 20 years, 50 years of amatuer and professional electronics experience, and about 2 months of experimenting with this PIC.

    This timer was to be used in a pic program that includes a 4 button - 4 line lcd interface, the analog converters and a number of digital pots, to precisely control and monitor the work of four power transistors. This program will probably strain the 8k program limit of the 16F877A.

    I guess starting small is just not me.

    The systems are all working except for the timer and the digital pots which arrived yesterday.

    My mind just can't seem to run at 20 mHZ.

    I guess I am going to have to add an outboard RTC and find a way to access it.

    Is there any other way?

    I surely appreciate the suggestions I have been given on this forum by you and others.

    Thanks again,

    The Geezer

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


    Did you find this post helpful? Yes | No

    Default

    It would help if you gave us an idea of what are you are using your "exact second" for, and why it has to be so accurate.

  5. #5
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default Timer Accuracy

    Actually, Melanie, hundreths or thousandths would be even better. I am monitoring the current flow through transistors and keeping track of the mAH as it counts up on the LCD. When the current stops the count stops. I will be monitoring the current through 4 transistors simultaneously. With a time reference that each sub program can access, the math in the sub program can make the calculations and display them on the four lines of the LCD. When the current flow stops, the readings will remain on the LCD until the user decides otherwise.

    I can do this with seconds, but the math will work even better with hundredths or thousandths, without floating point.

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


    Did you find this post helpful? Yes | No

    Default

    You're obsessed! Look, you're charging/discharging batteries for Gawds sake, not measuring the velocity of a speeding bullet!

    Who cares if it's exactly an hour, or an hour and 15 seconds...

    Do your ADC's, do your calculations (assuming a 100mS time interval), insert a Pause 100 and simply Loop. Just forget the time for the ADC's to operate and your math time. Just do a Pause 100.

    The first time you run your program insert a message to appear on your LCD after 36000 loops... (an hours worth of 100mS loops). You run a stop-watch and compare your watch against the PIC. You'll probably find it'll be an hour and a few minutes. Calculate the overspill time and reduce the Pause 100 statement accordingly. Hey presto - you're done.

    Now, if it ends up a few seconds out per hour, the batteries aren't going to care, after all they're a big chemical pile and you can't predict how chemicals will react from charge to charge, let alone down to fractions of a second. You're going to charge a 2200mAH Battery for example... it'll behave differently when factory fresh to when it's a year old. Best guess is close enough. So if you're charging a Battery for an hour, so what if you charge for one hour, one minute and seventeen seconds? It's not going to hurt.

  7. #7
    GEEZER's Avatar
    GEEZER Guest


    Did you find this post helpful? Yes | No

    Default Timer Accuracy

    Very perceptive Mel, I'm impressed! I'll give it a try. 15 sec. an hour is less than 1%, I could live with that. One minute and fifteen seconds would not let an obsessed geezer sleep at night.

    I am an old broadcast engineer, +/- 20 cycles per million in the days of vacuum tubes and crystal ovens. I'm too old to change very much now.

    I didn't expect the pause command would be that accurate, but i'll try anything once.

    This is a great forum, lots of idea exchange, and helpful people. It's a fast track for those just getting started, especially the chronologically handicapped.

    Thanks for your help.

    The obsessed Geezer

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