CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Measure timer1 32.768 khz accuracy

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yossihagag1978



Joined: 04 Apr 2013
Posts: 19

View user's profile Send private message

Measure timer1 32.768 khz accuracy
PostPosted: Sun Jul 29, 2018 11:55 am     Reply with quote

Hi
I am using 32.768khz crystal for timer1 sosc in pic16lf1789 in order to counts sec while in sleep. When wakeup i move to internal 4 mhz.
My question is : is there a way to measure the accuracy of the sosc crystal with the pic?
Verify the accuracy of the TIMER1 32.768 KHz crystal oscillator ?
Regards
Yossi
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 29, 2018 1:04 pm     Reply with quote

You really can't have the PIC check itself for accuracy using the internal RC 4 MHz oscillator. It is not 4.000000 MHz and varies according to temperature and other reasons.
Also the PCB layout is critical to having xtals run at correct speed.
What you can do is run the PIC on the 32KHz xtal and have it compared to a known stable clock source (say another PIC with TXCO Xtal) for several days. Be aware that NO two PICs will run at exactly the same speed. Minor variations based on PCB layout, components, VDD, etc.
If you want a good clock, I suggest an external RTC like the DS3231. Typically it's on a PCB with an EEPROM for about $2 CDN.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jul 29, 2018 1:12 pm     Reply with quote

What are you proposing to use as your frequency reference?

Mike

Jay got in as I thought & typed!
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 29, 2018 1:28 pm     Reply with quote

great minds think alike Shocked
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jul 29, 2018 2:17 pm     Reply with quote

The key problem is that anything else you compared it with, would be no better. Another crystal etc...

This is why the old 'traditional' way of calibrating such clocks was to use a radio transmission that came from a high accuracy source. For instance in the UK, the old 'long wave' Rugby transmitter was a 'warranted' standard. 60KHz, +/- on a few parts per billion. This has now been moved to Cumbria, still transmitting at 60KHz, and the accuracy is now guaranteed to be better than 2 parts in 10^12.
What you did was divide both clocks to produce a common tone (perhaps 1KHz), and then measure the 'beat' between these signals. Then adjust the loading capacitors on the clock crystal to produce the lowest frequency beat. With a little care it was possible to adjust crystals to give only a few parts per billion error. However you then had to deal with temperature (unless you have the crystal maintained at a regulated temperature, it will drift), and crystal aging (crystals all change frequency a little with time).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Measure timer1 32.768 khz accuracy
PostPosted: Sun Jul 29, 2018 7:25 pm     Reply with quote

yossihagag1978 wrote:

My question is : is there a way to measure the accuracy of the sosc crystal with the pic?
Verify the accuracy of the TIMER1 32.768 KHz crystal oscillator ?

What's your purpose ?

1. Do you want to test the crystals before you install them on boards
as part of incoming inspection ?

2. Do you want to test them after they're installed, during board test ?

3. Do you want to test the crystal in the field periodically, to see if it's
still working correctly ?
yossihagag1978



Joined: 04 Apr 2013
Posts: 19

View user's profile Send private message

PostPosted: Sun Jul 29, 2018 10:31 pm     Reply with quote

My entire project consumes 10 uA... ds3231 is not relevant.
I have no problem to use an external crystal for more accuracy.
The seconds i count is critical for me. That is why i need to verify it when the pic start timer1. If it will detect that 32 external crystal is not accurate then it should stop and notify the user.
There is a bit for timer1 to be ready and i use it.
But i need to test the accuracy of the 32 external crystal.
There must be a way for it
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 1:35 am     Reply with quote

Basically there isn't.

The only way you can test something, is by having something 'better' to compare against. Now to get a crystal oscillator that is going to be known to be better than the standard 32K crystals, would involve either a crystal oven (lots of power), or a TCXO oscillator. Both relatively complex and involving some power. An alternative as I already mentioned, is to read an external source. Even a TCXO will still drift 'long term'.

You could add a GPS receiver module. Leave this 'powered down', and then once a day for a short time enable this. GPS gives a fairly accurate clock as one of it's 'derivative' functions. The little units like the U-blox, are low power in themselves, and can achieve lock when being powered up at a fixed location in only a few seconds. You can then compare the time this is giving with the value from your internal clock. Either adjusting the latter, or warning.
yossihagag1978



Joined: 04 Apr 2013
Posts: 19

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 1:41 am     Reply with quote

Hi
what do you think about this post i saw on microchip forum:
One possible method to do this is:
Use TIMER1 to count the 32.768 KHz crystal oscillator output.
Use an external 4.000 MHz oscillator module in location Y2 of your PICDEMO2PLUS board to provide an accurate system clock.
Use TIMER2 with a prescale of 1:4 and PR2 set to 249, for a 250 count period, set postscaler to 1:10.
(This will set the interrupt rate of TIMER2 to 100 interrupts per second.)

Every 100 interrupts of TIMER2:
1 - Copy the value of the 16-bit unsigned variable named: Timer1_Value to a variable name: Timer1_Value_Previous.
2 - Read the value of TIMER1 and save it to a 16-bit unsigned variable named: Timer1_Value.
3 - Subtract the Timer1_Value_Previous variable from the Timer1_Value variable and store the result in the 16-bit unsigned variable named: Timer1_Count.
4 - Add the value of Timer1_Count to a 32-bit unsigned variable named Timer1_Count_Total.
5 - Add the constant value 32768 to a 32-bit unsigned variable named Timer2_Count_Total.

The difference between Timer1_Count_Total and Timer2_Count_Total is the difference in the one second intervals of the 32.768 KHz crystal oscillator circuit and the external 4.000 MHz oscillator module.

If Timer1_Count_Total is greater than Timer2_Count_Total then the TIMER1 crystal oscillator circuit is running fast.
If Timer1_Count_Total is less than Timer2_Count_Total then the TIMER1 crystal oscillator circuit is running slow.

After one second an error of at least 1 part in 32,768 can be observed.
After 10 seconds an error of at least 1 part in 327,680 can be observed.
After 100 seconds an error of at least 1 part in 3,276,800 can be observed.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 2:01 am     Reply with quote

The point is you have no guarantee that your PIC crystal is any better than the watch crystal. In fact it'll probably be worse. You seem to have the mistaken belief that the PIC oscillator is miraculously going to be better than the RTC....

If you want a better timing standard, spend the money on your watch circuit, whether buying a TCXO version, or just a more accurate crystal. People like Golledge do I2C RTC's warranted to give better than 0.26 seconds/day over a wide temperature range (typically much better over normal temperatures), or as I have already suggested use GPS to keep your clock set accurately.
yossihagag1978



Joined: 04 Apr 2013
Posts: 19

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 5:19 am     Reply with quote

Ok understand !
i am trying to find on the pic16lf1789 datasheet what is the delta on % of internal OSC on diffrent temp !!
please advice if you can
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 5:32 am     Reply with quote

While that method can work, what is key to it working is the 4MHz EXTERNAL clock module, which is $$$ and power hungry! If you need a very,very accurate,ultra stable clock source you'll have to 'pay the price', either in actual part cost or power, neither you probably don't want to do.
You won't get what you want by using the internal RC oscillator, or a common 4MHz/2 caps attached to the PIC.
While there are better grade 32KHz xtals($$$), pay keen attention to board layout and cleanliness ! ANY minor imperfection WILL change the speed of the clock.You may also need to add a trim cap to the circuit to get 32.768 KHz. More cost and EACH PCB WILL be different, so you need to test and adjust. Another consideration is temperature. If the device is always run at 'room temperature', timing should be fairly stable except of course when the air conditioning or furnace comes on....then the numbers WILL go 'funny'. That I found out the hard way! A product worked great for 3 months,as soon as furnace came on, bamm...'funny things' happened. The only solution was to design/install a daughter PCB with xtal/caps/CMOS to replace the RC osc. section and a bigger battery.
How you proceed depends on several factors. Is this a 'one off' or 1,000 unit device? What is your time worth ? Spend a day( 10 hrs) trying to test 'this should work solutions' can easily cost you $500 whereas buying a proper TXCO module might be $10 , bigger battery another $5.
However if you can't add parts or more power, your options are very ,very limited.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jul 30, 2018 6:59 am     Reply with quote

Element OS08 in table 31-7. +/-5% for the whole rated temperature range, improving to +/-2% for the nearer to 'room temperature' range.

Now compare with even a cheap watch crystal +/- 50PPM. 0.005%.

Now even if you added a crystal to the PIC, this would typically only be 50PPM, unless you paid for something like a 20PPM part.

If you want a good stable clock, your solution is to pay for a more accurate RTC part. The TCXO parts I've already mentioned are crystal oscillators with built in temperature compensation. Give you typically at least 5* the best normally possible for a crystal. For better accuracy, you get 'OXCO', which are crystal oscillators with a built in oven, but these use a lot of power. The key about TCXO parts is that many are very low power, they just involve adding a temperature sensor to the crystal, and knowing it's temperature co-efficient, and adjusting the oscillator to correct for temperature changes. Neat thing is that the RTC's I already mentioned do all this for you. There are dozens available.

There is no 'free lunch'. If you want to 'check' your frequency accuracy, you have to add a signal source that is 'better' than the frequency you are trying to check. If you are doing this, then surely it is better to spend the time and money improving the clock source itself....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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