Author Topic: New crystal will fix this?  (Read 6508 times)

0 Members and 1 Guest are viewing this topic.

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
New crystal will fix this?
« on: May 20, 2014, 08:20:52 pm »
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
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: New crystal will fix this?
« Reply #1 on: May 20, 2014, 08:35:38 pm »
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?

That's expected, and even if you don't collapse the 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.

Quote
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?

You're out by 0.2%. Probably not a bad crystal, 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 the actual frequency, etc.)
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New crystal will fix this?
« Reply #2 on: May 20, 2014, 08:35:47 pm »
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.
================================
https://dannyelectronics.wordpress.com/
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: New crystal will fix this?
« Reply #3 on: May 20, 2014, 08:38:21 pm »
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,
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: New crystal will fix this?
« Reply #4 on: May 20, 2014, 09:24:57 pm »
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.
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: New crystal will fix this?
« Reply #5 on: May 20, 2014, 10:17:50 pm »
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.

Well 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 :)
The larger the government, the smaller the citizen.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: New crystal will fix this?
« Reply #6 on: May 20, 2014, 11:15:43 pm »
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

 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: New crystal will fix this?
« Reply #7 on: May 20, 2014, 11:19:40 pm »
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,

Actually 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.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: New crystal will fix this?
« Reply #8 on: May 21, 2014, 01:01:37 am »
Thanks ALL for 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 I assumed that 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 remembered the 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
« Last Edit: May 21, 2014, 01:05:53 am by Rick Law »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New crystal will fix this?
« Reply #9 on: May 21, 2014, 01:14:24 am »
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).
================================
https://dannyelectronics.wordpress.com/
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: New crystal will fix this?
« Reply #10 on: May 21, 2014, 01:59:42 am »
Quote
Given I am not even sure if it is a crystal, and is looking more like a ceramic resonator, replacing that is out.

 It'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.

 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: New crystal will fix this?
« Reply #11 on: May 21, 2014, 02:23:36 am »
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).

I will try that sometime...  Thanks.  I like having more tricks in my beg.
 

Offline gxti

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Re: New crystal will fix this?
« Reply #12 on: May 21, 2014, 04:21:53 am »
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.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: New crystal will fix this?
« Reply #13 on: May 21, 2014, 06:13:24 am »
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).
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: New crystal will fix this?
« Reply #14 on: May 21, 2014, 06:50:29 am »
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).

Yeah, 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...
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New crystal will fix this?
« Reply #15 on: May 21, 2014, 11:17:33 am »
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.

================================
https://dannyelectronics.wordpress.com/
 

Offline cleverca22

  • Newbie
  • Posts: 1
Re: New crystal will fix this?
« Reply #16 on: May 24, 2014, 02:41:46 am »
the AVR chips also have the option of hooking up a 2nd crystal, always a 32khz watch crystal, to a special pair of pins

then 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 crystal

in theory, the watch crystals are designed for time keeping, and will have better stability over a day
 

Offline paulie

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: New crystal will fix this?
« Reply #17 on: May 26, 2014, 11:09:37 pm »
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.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: New crystal will fix this?
« Reply #18 on: May 27, 2014, 12:45:56 am »
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...
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New crystal will fix this?
« Reply #19 on: May 27, 2014, 01:02:31 am »
Quote
it doesn't work so well.

It 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3423
  • Country: us
Re: New crystal will fix this?
« Reply #20 on: May 27, 2014, 02:48:23 am »
Quote
it doesn't work so well.

It 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.

I 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.
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: New crystal will fix this?
« Reply #21 on: May 27, 2014, 08:30:44 am »
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 .
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline Sailor

  • Regular Contributor
  • *
  • Posts: 170
Re: New crystal will fix this?
« Reply #22 on: May 29, 2014, 12:23:12 pm »
The DS1307 does seem to be a little sensitive
True 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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: New crystal will fix this?
« Reply #23 on: May 29, 2014, 12:26:12 pm »
Quote
True enough

Agreed. 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.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf