New crystal will fix this? - Page 1
Forum section: electronics / general

author: Rick Law
author_rank: Super Contributor
timestamp: May 20, 2014, 08:20:52 pm
content: This is very beginner-ish, but it is about Arduino…One of my Arduino is logging 183,000 ms per day less than the other two. Average deviation is 183-190 seconds less per day. Not a big deal per-se, but when I switch Arduino and happen to pick this one to run that occasional tasks, things don’t start at the right time causing me problems.I can of course modify my program and make a specific version for this slow one. But I am thinking about fixing it for good.So, question…1. Where would be a good point to tap a Scope or a DMM to measure the actual clock frequency? I tried to tap into pin 9 and 10, it seems I just collapsed the oscillation. Is that expected or did I simply did it wrong?2. Is it more likely that I have a bad crystal or bad capacitors by the crystal?3. My thought is, just replace the crystal. Would you do that or hunt for other issues that may slow down a proper (good) crystal?Thanks for your input!Rick

author: c4757p
author_rank: Super Contributor
timestamp: May 20, 2014, 08:35:38 pm
content: Quote from: Rick Law on May 20, 2014, 08:20:52 pmThat's expected, and even if you don'tcollapsethe oscillation, you'll influence the frequency. Even a little bit of capacitance does that. Output something with known frequency (you can set them to output their own clock signal IIRC, but I don't remember how) and measure that.QuoteYou're out by 0.2%. Probably not abadcrystal, just a very, very cheap one. (Sure it's not a ceramic resonator?) Get a better crystal, or calibrate for the difference in software (set F_CPU to theactualfrequency, etc.)

author: dannyf
author_rank: Super Contributor
timestamp: May 20, 2014, 08:35:47 pm
content: 183 seconds a day is about 1000ppm. That's 10x bigger than the typical timing spec for a crystal, and likely 100x bigger than the average timing error for a crystal.So you have either an extremely bad crystal or the mcu isn't running on a crystal at all.As to measurement, put the probe on the oscillator output pin - putting it on the input pin may stop the oscillator.

author: Rerouter
author_rank: Super Contributor
timestamp: May 20, 2014, 08:38:21 pm
content: if its an older genuine arduino it would use a ceramic resonator, which is not all that crash hot, have a look on the board, as it is a non metallic package,

author: 22swg
author_rank: Frequent Contributor
timestamp: May 20, 2014, 09:24:57 pm
content: Not sure how your going to check this on a scope , unless its go a frequency counter on it ? a DMM likewise is there not a calibration value somewhere in the RTCC code.

author: Stonent
author_rank: Super Contributor
timestamp: May 20, 2014, 10:17:50 pm
content: Quote from: 22swg on May 20, 2014, 09:24:57 pmWell I would assume you could count peaks over a known time period. My analog scope's design spec says 20MHz but I was able to determine a particular clock signal was in the 30MHz range with it. I have no idea where in the 30MHz range I was, though, because I was way outside its range and that was with Dave's favorite Hung Chang series of scopes

author: retrolefty
author_rank: Super Contributor
timestamp: May 20, 2014, 11:15:43 pm
content: typicall putting a standard scope probe on a crystal pin will load down the oscillator and prevent clocking all together. Even if it doesn't the added capacitance of the probe would change the frequency by some amount so won't show you the actual frequency. There are special FET probes that will allow direct reading but they are expensive.Now as to frequency accuracy on your arduino board. First which board do you own? The earlier boards used a two terminal crystal resonator that had maybe 10-20 PPM. The newer boards now use a three terminal ceramic resonator that is maybe 50-100 PPM accuracy.Changing your crystal or ceramic resonator might help with your problem, but it's kind of a shot in the dark as the next resonator might run too fast by the same amount rather then be just right on.Most people that need longer term accuracy for timing function utilize inexpensive real time clock (RTC) modules. It give you actual time and date functions and have a small battery to maintain time when the board is power off.One example:https://www.adafruit.com/products/264

author: retrolefty
author_rank: Super Contributor
timestamp: May 20, 2014, 11:19:40 pm
content: Quote from: Rerouter on May 20, 2014, 08:38:21 pmActually the current arduino Uno and Mega2560 boards use three terminal ceramic resonators for their 328P and 2560 AVR chips, while they use a crystal resonator for the USB serial converter chip. The older boards utilized true crystal resonators.

author: Rick Law
author_rank: Super Contributor
timestamp: May 21, 2014, 01:01:37 am
content: Thanks ALLfor the insightful input.Since all has mostly the same question back to me, so I will consolidate this into one reply.(1) Good to know that connecting a probe to the xtal is expected/likely to collapse the oscillation and it is not me making a dumb mistake or equipment issue. I tried that before with my 32KHz crystal for the DS1307 clock I made and I could not measure that either. So I wanted to learn from the pros here to make sure that was not something obvious I missed.(Mr 22swg) Yeah, I use the frequency counter with my DMM... both my scope and DMM has frequency counter function.(2)Good that I posted here and you folks mentioned a ceramic resonator. The metal can crystal just exactly like the 16MHz crystals I get from Tayda - and Iassumedthat is the ATMega's clock.When DannyF said"So you have either an extremely bad crystal or the mcu isn't running on a crystal at all." I said to myself "no way, there is only one place for clock ticks to come..."Then I rememberedthe schematic shows Atmega16U2 also has a 16MHz crystal.So, I went back for another much more careful look.The crystal I have been planning on replacing (and attempting to measure) is actually the 16U2's clock and not the 328's clock.Along pin9 and pin10 of the ATMega328 is a tiny (about 2.5mm x 1mm) metal-looking container 6pins SMD with trace going to 1M resister in parallel then pin9 and 10 of the 328. No visible capacitor anywhere near there. So it must be an oscillator, or a ceramic resonator, or some sort of combined setup (no capacitor, 6 pin from this SMD) rather than just a crystal.Given I am not even sure if it is a crystal, and is looking more like a ceramic resonator, replacing that is out.Good that I posted here for advice, I was gearing up to replace the crystal I saw and stupidly assume that is the 328's crystal... That would have been a dumb thing to have done. Replacing the 16U2's ticker would have done nothing.Thanks again!Rick

author: dannyf
author_rank: Super Contributor
timestamp: May 21, 2014, 01:14:24 am
content: Putting the probe on the clock output pin (xtal2) is fine for a regular clock. The drive for 32Khz crystals is very low and putting the probe on even the output pin may stop it from oscillating - and sometimes may start it to oscillate as well.If the external thing is an oscillator, it has only one pin to to the clock input pin (xtal1).

author: retrolefty
author_rank: Super Contributor
timestamp: May 21, 2014, 01:59:42 am
content: QuoteIt's a ceramic resonator. A lot of the arduino forum members were complaining when the Uno first came out and saw them using the ceramic rather then a crystal resonator in prior boards.

author: Rick Law
author_rank: Super Contributor
timestamp: May 21, 2014, 02:23:36 am
content: Quote from: dannyf on May 21, 2014, 01:14:24 amI will try that sometime... Thanks. I like having more tricks in my beg.

author: gxti
author_rank: Frequent Contributor
timestamp: May 21, 2014, 04:21:53 am
content: You can still remove the resonator and replace it with a crystal + loading caps. Might require a little creativity but the microcontroller doesn't care either way.You'd think that if they were going to cheap out they could at least have just used the clock from the USB micro.

author: Richard Crowley
author_rank: Super Contributor
timestamp: May 21, 2014, 06:13:24 am
content: Using the processor crystal for timing is simply not reliable. As you have proved.That is why RTC (Real Time Clock) chips are made.Add an RTC module to your Arduino and forget about trusting the processor crystal (or whatever).

author: Rick Law
author_rank: Super Contributor
timestamp: May 21, 2014, 06:50:29 am
content: Quote from: Richard Crowley on May 21, 2014, 06:13:24 amYeah, I am concluding nearly the same thing. The project started with using a DS1307. I was not pleased by how poorly it kept time. It is far too sensitive to the environment. I switched over to to DS3231 and it worked a lot better. Then I pushed my luck and see how if I just use the millisec and see how it stacks up. Naaah... it doesn't work so well.This is a learning project, so I suppose to that end it is another notch towards goal.I am however glad posting here to ask for advice. Once I saw the 16MHz crystal for the 16U2, I merely assumed it was the clock for the 328. I would have felt so stupid had I replaced that, and then trying to find out why it made no differences...

author: dannyf
author_rank: Super Contributor
timestamp: May 21, 2014, 11:17:33 am
content: A clock can be accurate even if it is off, as long as it is consistently off. I have built clocks by simply dividing down the main oscillator. A RTc is useful if you want to run your mcu in sleep.A real crystal is one such a device. The ceramic resonator stuff in the Arduino was simply a design mistake.

author: cleverca22
author_rank: Newbie
timestamp: May 24, 2014, 02:41:46 am
content: the AVR chips also have the option of hooking up a 2nd crystal, always a 32khz watch crystal, to a special pair of pinsthen you can select which clock the timers run on, so you can create a timer thats using the 32khz watch crystal, and have it run entirely independent of the main system crystalin theory, the watch crystals are designed for time keeping, and will have better stability over a day

author: paulie
author_rank: Frequent Contributor
timestamp: May 26, 2014, 11:09:37 pm
content: ive found cheap ebay quartz crystals to be extremely accurate and stable for timebase. 100x better than what you have. strangely the quartz cost less these days. simplest solution is remove the ceramic resonator and use the 16mhz clock from the usb chip. make sure to connect output to input.

author: Rick Law
author_rank: Super Contributor
timestamp: May 27, 2014, 12:45:56 am
content: Thanks for all the advice. I was not interested in knowing the time-of-day. For RTC, I use DS1307 and DS3231 for that. I was merely experimenting and picking a random Arduino (on different days) board to plug as I experimented and noticed the problem of big time lost on one of the board. Had it been a crystal problem (as I thought), it would have been an easy fix...Really good that I post for advice, looking at the 16U2's crystal, I never look deeper to check if there is another one while the schematic clearly shown two... Silly me...

author: dannyf
author_rank: Super Contributor
timestamp: May 27, 2014, 01:02:31 am
content: QuoteIt is not difficult to make the mcu keep time as accurately as possible, as long as the the crystal oscillator is consistent.So a RTC isn't needed at all, and you can run the time keeping entirely in the background so it is transparent to the user.It does require that you know the crystal's frequency. That can be measured with a frequency meter or by the mcu itself against a known frequency source.Using a ceramic resonator there is a mistake by team arduino.

author: Rick Law
author_rank: Super Contributor
timestamp: May 27, 2014, 02:48:23 am
content: Quote from: dannyf on May 27, 2014, 01:02:31 amI wrote a software RTC as part of my learning/experimentation. The Arduino actually is a better clock than the DS1307. It runs more consistent than the DS1307 over the course of a day. The DS1307 is very noise and temperature sensitive. The DS3231 with its compensated crystal is another story. It is far more consistent than the DS1307.When I want to know actual time/date, I turn to RTC. For elapse time, I like to to system clock tick - force of habit, I suppose.

author: 22swg
author_rank: Frequent Contributor
timestamp: May 27, 2014, 08:30:44 am
content: The DS1307 does seem to be a little sensitive , think it needs correct guard bands around xtal / chip , I have used the MCP79410 , this also should be guarded correctly and it needs a little more sw but has a osc trimmer byte +/- 129 ppm each min .

author: Sailor
author_rank: Regular Contributor
timestamp: May 29, 2014, 12:23:12 pm
content: Quote from: 22swg on May 27, 2014, 08:30:44 amTrue enough, and the RTC oscillators in the modern chips that are striving down into the nA range are getting *really* picky about everything - the xtal characteristics, the bulk+stray capacitance, guarding, everything.

author: dannyf
author_rank: Super Contributor
timestamp: May 29, 2014, 12:26:12 pm
content: QuoteAgreed. And I would go beyond that to all modern RTC oscillators: the drive power is so low (to minimize current consumption) that if you blow a candle near them, the time is off,Having said that, low frequency crystals are generally more difficult to get going than high frequency crystals.