Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timer1 32.768 accuracy problem

Status
Not open for further replies.

xyzabcpqr

Junior Member level 3
Joined
Mar 22, 2012
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,523
Hello all,

I am currently working on PIC16F1937 . My project is Digital clock alarm with several additional features...Due to cost issue instead of using RTC Chip, I am using 32.768KHz as Timer-1 external crystal oscillator to increment time of digital clock and 4 MHz internal osc for system osc. frq. I am using PICDEM2PLUS demo board in which 32.768KHz connected with two 22pf cap.

In the application, the Clock, alarms and snooze works well. but I found that my clock is going fast by 30 sec in 60 Hours.. It is pretty less accurate..

I found reading several threads regarding this topic, that Timer1 - 32.768KHz oscillator is not reliable in-terms of accuracy. How can i increase the accuracy of clock using the same concept.(using timer1 only)?

One more thing is, in my circuit, I have used 10 switches .. every time with the clock update function,i read the switches.. So is it possible,because of that it adds the overhead timing ?


Please guide me. Thanks in advance..
 

The could be several reasons for the noted time deviation.

Timer accuracy is largely due to the accuracy of its clock source.

What are the specs and type of the 32.768KHz crystal used to drive Timer1?

Is it a tuning fork style crystal?

What is the frequency tolerance, 10ppm, 20ppm, 50ppm, 100ppm ....?



Have you provided a sufficient delay for clock stabilization?

Note: The oscillator requires a start-up and
stabilization time before use. Thus,
T1OSCEN should be set and a suitable
delay observed prior to using Timer1. A
suitable delay similar to the OST delay
can be implemented in software by
clearing the TMR1IF bit then presetting
the TMR1H:TMR1L register pair to
FC00h. The TMR1IF flag will be set when
1024 clock cycles have elapsed, thereby
indicating that the oscillator is running and
reasonably stable.

Post your code using CODE or SYNTAX tags, so that it maybe reviewed for possible timing issues.

What method are you using to determine the timer inaccuracy? The 30 seconds in 60 hours deviation.


BigDog
 

Just so you know, you don't have to use a clock crystal to get an accurate clock. You can use any crystal you want. See this page: https://romanblack.com/one_sec.htm. It very easily implemented and you can adjust it for accuracy. I haven't tried to get close to the author's accuracy, but I've gotten much better than 1s/day. I don't use watch crystals at all anymore.
 

two 20pF caps present a 10pF load...sounds right for a 12.5 rated load (assuming that's what you have)

Consider increasing one or both up to 50pF you can tuning it to zero error with the load cap. More pF lower the the frequency. Too much and it attenuates the signal below unit loop gain.


A reverse bias diode AC coupled to be in parallel with one or the other cap, can also be used with a pot to control the capacitance from a stable reference voltage.

You should be able to "pull" it down 30~50ppm. Crystals have a Q of 30000~80000 typ and Tuning Forks have a Q of 3000~10000 typ.

Measure your error in PPM and report your results. 30sec in 60hr is +139 PPM ... try 100pF and 50pF or so. They do not have to be equal.
 
Last edited:

Hello all,

I am currently working on PIC16F1937 . My project is Digital clock alarm with several additional features...Due to cost issue instead of using RTC Chip, I am using 32.768KHz as Timer-1 external crystal oscillator to increment time of digital clock and 4 MHz internal osc for system osc. frq. I am using PICDEM2PLUS demo board in which 32.768KHz connected with two 22pf cap.

In the application, the Clock, alarms and snooze works well. but I found that my clock is going fast by 30 sec in 60 Hours.. It is pretty less accurate..

I found reading several threads regarding this topic, that Timer1 - 32.768KHz oscillator is not reliable in-terms of accuracy. How can i increase the accuracy of clock using the same concept.(using timer1 only)?

One more thing is, in my circuit, I have used 10 switches .. every time with the clock update function,i read the switches.. So is it possible,because of that it adds the overhead timing ?


Please guide me. Thanks in advance..


Hi,

As you have probably seen in the other posts a typical 'watch' 32k xtal and 22pf caps on timer 1 should easily be accurate to 2-3 seconds over 60 hours, to be 30 seconds fast makes me supect something is wrong with your code or perhaps the hardware.

I use them such rtc on many units without problems.

If your switches where causing a problem you would normally expect them to cause the rtc to loose time, not gain it; again unless you have some bugs in your code.

What are you timing the rtc against ?
 

Thanks all for your guidance.

Yes, wp100. I agree.. There is something problematic in my code or hardware .. As I mention before that I am using PICDEM2PLUS Demo board as a development board, They have not mentioned specification about this Timer-1 Crystal. They just say it's a watch type crystal.

I made changes in Initialization of timer1 and run the clock for 17 Hours , again it goes 7 sec fast.I really stuck and couldn't find the solution.

Here i have attached my code.. I am using PIC16F1937 pic.
My CODE IS TOO LARGE . SO I JUST PUT CLOCK ACCURACY RELATED FUNCTIONS only .. led display init , display , Alarm and Snooze related stuff i omitted in the mail..

Please let me guide .
 

Attachments

  • CLOCK.txt
    14.8 KB · Views: 63

Hi,

Afraid I only do Assembly code so cannot help you there - but sure someone else will soon help out.

It looks a lot of code, so why not try a very basic program for just timer1 and the lcd and see if that keep time ok.
 

Hello,

In Timer1 Interrupt function When Interrupt occurs , should TMR1IF (Interrupt Flag) set to zero first or TMR1H reload first. Does it matters in clock going fast?
Below is the clock generation code. The sequence of reloading timer register and clearing Interrupt flag is shown. Please guide me if the changes required in clock sequence .
e.g

void RTC_ISR (void)
{
if (TMR1IF && TMR1IE) // If RTC interrupt
{
TMR1H = 0x80;
TMR1L = 0x00; // Re-arm the timer of another second
RTCIncDateTime(); // Count a new second
TMR1IF = 0;
}

}

void RTCIncDateTime(void)
{
Sec++;
if (Sec == Max_Sec) // Count 1 more second and Check if 1 more minute
{
Sec = 0; // Reset Seconds
Minute++;
}
if (Minute == Max_Min) // Count 1 more minute & check If 1 more hour
{
Minute= 0; // Reset Minutes
Hour ++;
}
if (Hour > Max_Hr) // Count one more hour and check if day change
{
Hour = 01; // Reset Hours

}


}
 

Hello All,

I fingered out that,
1. Tuning fork that provided on PICDEM2PLUS board , was actually not accurate.
I changed EPSON tuning fork with 20ppm and 22pf load cap.
2. I was using PC clock as reference to verify exact time. But when you start the PC it take some time to update. So initially i was misguided that my Clock was running fast. But it was the problem with clock in PC. Then i used NIST (OFFICIAL U.S TIME CLOCK website) , and I found that my clock is loosing 3sec/day .

As 20ppm , ideally it should loose 1.78sec/day. I think I should vary the load cap as well.
 

Hello All,

I fingered out that,
1. Tuning fork that provided on PICDEM2PLUS board , was actually not accurate.
I changed EPSON tuning fork with 20ppm and 22pf load cap.
2. I was using PC clock as reference to verify exact time. But when you start the PC it take some time to update. So initially i was misguided that my Clock was running fast. But it was the problem with clock in PC. Then i used NIST (OFFICIAL U.S TIME CLOCK website) , and I found that my clock is loosing 3sec/day .

As 20ppm , ideally it should loose 1.78sec/day. I think I should vary the load cap as well.


Hi,

Was a bit surprised that you used the PCs clock as your reference, just watching the second finger go round you can see it does not do it evenly.

I normally use my wrist watchs stopwatch or one of the RF/Atomic clocks used in many devices.

You can try adjusting the capacitors, but if you know it just 3 seconds a day, simply add on 3 seconds everytime you do your 24.00 / midnight routine ..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top