Electronic Circuits and Projects Forum



Xtal oscillators for timekeeping.

12 Last »
  1. #1
    dr pepper dr pepper is offline

    Xtal oscillators for timekeeping.

    I have implemented a real time clock in software, not the first time I've done this but the first time using the primary xtal oscillator.
    I'm using a 4.096Mc's xtal for the instruction clock and timer1, no interrupts just polling one of the bits.
    Accuracy is out by a few seconds a day.
    Would I get better accuracy using a 32.768Kc xtal on timer1's oscillator?, if I use the pic's internal oscillator for the instruction cycle I'd free up 2 pins for timer1's external osc.
    Last edited by dr pepper; 1st May 2012 at 10:24 AM.

  2. #2
    JimB JimB is offline
    Without knowing the EXACT frequency of the oscillator, there is no point in debating which one is better.

    Also, polling sounds like a bad idea.
    How do you know if you are polling at the correct point in time?
    I think that you need to use interupts.

    JimB
    0
    Experience is directly proportional to the value of the equipment ruined.

  3. #3
    kubeek kubeek is offline
    32768 crystals have lower drift than others. The lower frequency also means lower power consumtion in the coutner, so that is why they are used in RTCs.
    0

  4. #4
    dr peppers dr peppers is offline
    I use interrupts within the code allready to do other stuff, the interrupts run at 500 hz, and the bit I'm polling toggles at 125 hz, so I know theres no chance of a missed poll, if I was missing polls then I'dve thought the clock would have been slow not fast.

    I didnt know drift was less with 32.768 kc xtals, the low power bit makes sense as these are common in watches which obviously are battery powered.
    I'll have to mess about shifting one bit of my 7 segment display bits to another port pin, but that looks like the way to improve accuracy.

    Incidently my initial idea used interrupts for timekeeping rather than polling timer1, and that didnt work it ran slow, I think what was happening was that every time I reloaded the timer to get the correct interrupt duration the prescaler was reset (the pic resets the prescaler when you write to the timer register) causing an error of a few clock cycles every interrupt.
    0
    Last edited by dr peppers; 1st May 2012 at 03:13 PM.

  5. #5
    dr peppers dr peppers is offline
    I have just reconfigured the circuit, the 4 mc xtal is now removed and the chip runs from its internal rc, I've shifted one of the bits off portb to porta (not very elegant but works), and timer1 now runs from a 32,768 kc xtal.
    hSo I'll leave the clock to run overnight and we'll see how accurate it is.
    The circuit is built on vero so I'm not expecting the best possible result, but hopefully better than 10 secs per day.
    0
    Last edited by dr peppers; 1st May 2012 at 04:31 PM.

  6. Thread Starter #6
    dr pepper dr pepper is offline
    Obviously I'm missing something, with a 32kc xtal accuracy is worse.
    0

  7. #7
    ericgibbs ericgibbs is offline
    Super Moderator
    Quote Originally Posted by dr pepper View Post
    Obviously I'm missing something, with a 32kc xtal accuracy is worse.
    hi dr,
    You can buy 32.768KHz xtals in different stability ranges, some 'bog' standard 32KHz xtals have very poor temperature stability.

    The other point are you using high stability xtal caps.?
    0
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    "Nigels Asm tutorials:" www.winpicprog.co.uk/
    "Ian Rogers 'C' conversion of Nigels Asm tutorials:" http://www.electro-tech-online.com/c...torials-c.html

  8. Thread Starter #8
    dr pepper dr pepper is offline
    That could be the issue, the caps are ceramics out of the scrap box, judging by the lack of the black dot at the top they dont look like npo's.
    What do you mean by high stability, silver mica or polystyrene, or the likes?
    0

  9. #9
    ericgibbs ericgibbs is offline
    Super Moderator
    Quote Originally Posted by dr pepper View Post
    That could be the issue, the caps are ceramics out of the scrap box, judging by the lack of the black dot at the top they dont look like npo's.
    What do you mean by high stability, silver mica or polystyrene, or the likes?
    I would use poly or silver mica, if you 'know' the temperature drift range of your xtal, you can choose caps which drift with temperature in the 'opposite' sense.

    One method I have used in the past is a xtal small oven, running at say 5 or 10C above the worst case ambient.

    If you could find an old watch xtal, thats also an option.

    If you require really precise time keeping, there are improved versions of the DS1307 IC available, for about £5.

    EDIT:

    http://uk.farnell.com/jsp/search/bro...D2031%2B203436
    Attached Files
    0
    Last edited by ericgibbs; 2nd May 2012 at 08:07 AM.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    "Nigels Asm tutorials:" www.winpicprog.co.uk/
    "Ian Rogers 'C' conversion of Nigels Asm tutorials:" http://www.electro-tech-online.com/c...torials-c.html

  10. #10
    Gobbledok Gobbledok is offline
    I have a PIC32 (with RTCC module) and am using a 32.768KHz crystal for the clock.

    It is accurate to about 2 seconds a day (compared to my computer). That's a minute a month without any compensation (software or oscillator tuning).

    Accurate enough for me
    0
    There are 10 types of people in this world: Those who understand binary and those who don't.

    If it wasn't for Thomas Edison, we'd be all watching TV by candlelight.

12 Last »
Tags
Similar Threads
Thread Starter Forum Replies Last Post
Don't know squat about Xtal oscillators... captainkirksdog General Electronics Chat 9 13th April 2009, 09:01 PM
Oscillators, crystals, and resonators for clock pulses DSG General Electronics Chat 3 12th March 2008, 09:42 PM
tutorial for crystal oscillators adnan012 Electronic Projects Design/Ideas/Reviews 2 29th January 2008, 02:17 AM
Xtal Oscillators 32768 Khz RetiredHAL General Electronics Chat 16 2nd November 2007, 06:19 AM
Xtal freq for Z8671 2K ROM BASIC, member of old Z8 family eblc1388 Microcontrollers 3 20th September 2007, 01:09 PM
Electronic Circuits  |  Learning Electronics

Join our community with over 100,000 Members! It's free, easy and when you're logged in you have many more features! Click to register.
Page Time: 0.10501 seconds      Memory: 7,746 KB      Queries: 17      Templates: 0