Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

compensation for crystal errors

Status
Not open for further replies.

sanjoy

Member
Hi. I am using a ds1307 & 16f876 for making a Clock. Both the chips has crystals of 32.768MHz(ds1307) & 8MHz

(16f876). the 1307 are connected through I2C.
1)When i am using I2C1_Init() for initialization, what is the value of clock in the ().
2) im adding a compensation for errors due to crystal, i want to add or less delay in m_seconds in program, so

what is the value of crystal i have to consider to determine the delay ( as there are two crystals i,e, 32.768MHz or

8MHz).
Thanks to all.
 
The DS1307 uses a 32.768KHz clock not a 32.768MHz clock. (K)/(M)

I2C1_Init() for initialization
I looked at some code and I see "I2C1_Init()"

im adding a compensation for errors due to crystal, i want to add or less delay in m_seconds in program, so what is the value of crystal i have to consider to determine the delay
this will not add compensation for the 32.768 clock.
 
I'd love to see how are you connecting both 32.768khz and 8Mhz crystal to that ds1307.
Second thing, I2C is a sychronous bus, so I don't understand what kind of errors are you planning to compensate for.
 
The crystal oscillator in RTC causes some error in frequency everyday due to temprature. To compansate the error a function will be added in the program. this function will determine the necessary delay time wrt temprature.

so which of the crystal oscillators (32.768khz and 8Mhz) will be considered to determine the necessary delay time.
 
What delays?
Show me where you got the idea you can correct for errors in the clock. You must have read this somewhere.

I looked at many clock crystals. The worst one I can find is 100ppm of error and at low cost I can get 5ppm of error.
For temperature caused error form very cold to very hot; I find 100ppm is worst case and 20ppm is best for the low cost parts.

If you have a crystal with 20/1,000,000 of error; How long will it take for the clock to be off by 1 second?

The 8mhz has no effect on the real time. You could use 10mhz and the clock will function the same.
The 32,768 is the only time keeper.
 
Your computer is running at 8,000,000. You could change the crystal to 4M or 10M or 12M or 20Mhz or ...........
Your RTC clock is running at 32,768. No choice.
Between the computer and the RTC there are two wires. Data and Clock. The I2C clock should run at about 100khz for older parts. Some new parts can run at 400khz and some parts can run at 1mhz. This clock (100khz) is only for communication. Like the RS232 runs at 9600 baud. The compiler needs to know what your computer clock is. (8mhz) The compiler needs to know how fast your I2C clock. The compiler will take the 8mhz and do the math to get 100khz. If the slave I2C part is very slow the compiler may need to add in extra delays between each communications. The speed of the I2C clock and the amount of I2C delays has nothing to do with the real time clock accuracy.
 
Last edited:
As Ronsimpson says, the timing of the I2C bus is not critical. You can run it at any speed up to the maximum.

If you need better timing than 100 ppm, which is less than 10 seconds per day, then you would find it much easier to buy a better oscillator. You could buy something like this:-

https://uk.farnell.com/1641060 which would get better than 1 second per day over a wide temperature range.

I used to make TCXOs (Temperature Compensated Crystal Oscillators) for a living, and getting the compensation correct is hard work. If you haven't got the crystal adjusted correctly at room temperature, you could have much larger errors all the time.
 
If you need better timing than 100 ppm, which is less than 10 seconds per day, then you would find it much easier to buy a better oscillator.
Digikey.com has a large number of 10ppm crystals in stock.

In software you can add one second every day.

What are you building? Do you really need better than 1 second/day?
 
Digikey.com has a large number of 10ppm crystals in stock.

In software you can add one second every day.

What are you building? Do you really need better than 1 second/day?
The accuracy of crystals is the initial adjustment and the temperature dependence. 10 ppm over a wide temperature range is difficult or impossible. 10 ppm adjustment isn't too difficult but it assumes that the circuit has the correct load capacitance.
 
It is your job to have the correct load capacitance.
You can put a variable capacitor on the board.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top