|
|
View previous topic :: View next topic |
Author |
Message |
zhiyongwoo
Joined: 18 Jul 2010 Posts: 9
|
Watch Crystal App |
Posted: Tue Aug 03, 2010 2:50 am |
|
|
Hi all,
I hope someone can give me some helps here.
I was trying to embedded the real time clock into my PIC. I had successfully drive my PIC toward with the crystal and it works but the the clock errors is huge.
I use this method to update or reload initial value every time the timer1 overflow.
Code: | TMR1H += 0x80
TMR1L += 0x00 |
I assume it will add these value on top of the TMR1 counter. The result is, I got 4 seconds errors after 24 hours running.
The CCS support team recommended me to use this code:
Code: |
set_timer1(get_timer1() + 0x8000) |
But I realise the error just start showing after 4 minutes running and 1 - 2 second delay.
So, I assume the 2nd is not suitable........unless someone came across my problem before?
I use the closest load capacitance that the crystal manufacturer's recommended with is 12pF NP0 with +/-5%.
Can anyone give me some helps in order to make the MCU run the clock more reliable and accurate.
I do some time thinking about the prescale counter in Timer1. The data sheet mention, if any write operation happen on Timer1's counter then the prescale will be reset.
I set my prescale to 1:1, so does it mean every time I write something on my TMR1 counter, I will lost 1 tick?
Please feel free to put now your comments!!! Thank you very much!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Aug 03, 2010 4:48 am |
|
|
First thing, if the crystal load capacitance is specified as 12pF, you do _not_ want 12pF capacitors.....
The crystal 'sees' as it's load, the two external capacitors, in parallel with the PCB/leg capacitances, _in series_ with each other. If you have a well designed board, the PCB/leg capacitances will be around 5/6pF, so for a 12pF crystal, you would want about 18/19pF (18pF in parallel with 6pF gives 24pF, then two 24pF capactors in series gives 12pF 'seen' by the crystal. If you are using 12pF capacitors, the crystal will be seeing (12+5)/2 - about 8.5pF. Significantly 'wrong'...
The second problem, is that it takes _time_ to get into the interrupt. Typically 30+ instructions. Also as you have realised, even the act of loading a count value resets the prescaler, so time _will_ be lost. This is why for accurate timekeeping, you really need to let the timer free-run.
Would it really matter to halve the interrupt frequency, and not reload the timer?.
Then even if everything is perfect, the crystal _will_ have errors. Typically perhaps 20PPM or more, even in ideal conditions. Depending on the temperature of your environment etc., the errors will be worse. Also you need to be very careful about board layout round the crystal, with these oscillators being quite sensitive to picking up signals from tracks that pass close to the legs - careful design needed....
Your error, is 46PPM. What is the quoted accuracy of your crystal?.
Best Wishes |
|
|
zhiyongwoo
Joined: 18 Jul 2010 Posts: 9
|
|
Posted: Tue Aug 03, 2010 5:49 am |
|
|
Thank you for your quality information. It is extremely useful.
The watch crystal is specified by 12.5pF but I use 12pF. As you had mention, I need more than 18/19pF instead of 12.5pF? The crystal is +/-20PPM.
here is the link: http://www.abracon.com/Resonators/AB38T.pdf
Can you please tell me the effect (Frequency increase/decrease?) if the load capacitances are lower or higher than the crystal manufacturer specified?
I build my main oscillator circuit on strip board and an IC holder then the rest of the pins is plug on a bread board.
If I want to build a proper PCB, can you please recommended me what kind of the layout should be looking at & please give me some guideline if possible.
Thank you. |
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Aug 03, 2010 7:05 am |
|
|
Ttelmah wrote: | First thing, if the crystal load capacitance is specified as 12pF, you do _not_ want 12pF capacitors.....
The crystal 'sees' as it's load, the two external capacitors, in parallel with the PCB/leg capacitances, _in series_ with each other. If you have a well designed board, the PCB/leg capacitances will be around 5/6pF, so for a 12pF crystal, you would want about 18/19pF (18pF in parallel with 6pF gives 24pF, then two 24pF capactors in series gives 12pF 'seen' by the crystal. If you are using 12pF capacitors, the crystal will be seeing (12+5)/2 - about 8.5pF. Significantly 'wrong'...
|
Thanks for that info. Now THAT'S useful information. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Aug 03, 2010 9:09 am |
|
|
How much the frequency of a crystal changes with capacitance, is known as the 'trim sensitivity' (since you can use this to 'trim' the crystal frequency).
It is approximately:
TS = 0.5*(C1/((C0+CL)^2)))
Where C0, and C1, are the motional, and static capacitances of the crystal itself.
Your crystal will probably be an XY cut, which has a relatively low ratio of C0/C1. Expect perhaps +100PPM, if the capacitance is only 2/3rd the specified value.
Microchip have a good guide to oscillator layout in general, including PCB notes.
Best Wishes |
|
|
zhiyongwoo
Joined: 18 Jul 2010 Posts: 9
|
|
Posted: Tue Aug 03, 2010 9:25 am |
|
|
Sorry I am not quite understand what you were trying to tell me. Do you mean, my crystal is not a good crystal? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|