Crystal does not restart after messing with it - Page 1
Forum section: electronics / projects

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 11:43:16 am
content: I have an ATtiny441 MCU hooked up with 16MHz crystal. My loading capacitors are 33pf as per datasheet of the crystal I am using - MCRSD16000F183000RR from Multicomp.Now the problem is that it does not restart after I touch one of the loading capacitors. I have performed various tests - I use tweezers to touch one of the pins of the crystal - crystal stops - fair enough, I add huge capacitance in comparison to pF. But when I remove tweezers, it does not start oscillating again, only if I power cycle the circuit or reset MCU via reset line.I have tried increasing and decreasing load capacitors from 18pF to 90pF, also I have tried various startup times for the MCU to no avail - it does not restart oscillating.My question is -- is this normal and to be expected? Is this specific to internal crystal driving frequency of ATtiny? I have tried abusing ceramic resonator on my ATMega based Arduino and it restarts no problem.

author: wraper
author_rank: Unknown
timestamp: October 12, 2017, 12:04:26 pm
content: Quote from: miceuz on October 12, 2017, 11:43:16 amAttiny datasheet recommends 12 – 22 pF.Did you set fuses correctly for >8 MHz crystal?Also oscillator needs "a kick" to start, so not starting again might be normal behavior.QuoteIIRC it does not affect crystal oscilator, it is just a delay for CPU core reset to allow crystal frequency to stabilize.

author: RoGeorge
author_rank: Super Contributor
timestamp: October 12, 2017, 12:36:30 pm
content: First, don't abuse something, then expect it to self-recover.Still, as you noticed with the Arduino, there is a good chance for the oscillator to start again. I would check the following, in the order of their importance:1. Make sure the ATtiny is powered between 4.5V and 5.5V, as requested by the datasheet in order to work at 16MHz2. Make sure there is a decoupling capacitor for high frequencies on the power pins of the ATtiny, something like 100nF, physically located near the ATtiny power pins, as close as possible. 10-100uF parallel with the mandatory 100nF capacitor might also help a lot.3. Try lower capacitors for the crystal, not bigger, since there are always parasitic capacitance in any circuit. ATtiny datasheet recommends 12-22pF for frequencies > 1MHz when using the ATtiny on a PCB4. If you used a breadboard, don't put the crystal capacitors at all, in my experience breadboards have horrible parasitic capacitance and inductance.5. Locate the crystal as close as possible to the ATtiny pins, in order to reduce parasitic inductance6. Be careful to avoid ground loopsAfter all the above are met, there might be a chance for the oscillations to start again after abusing the circuit, but only if you are lucky, it is not guaranteed.Anything can be expected after touching the oscillator pins, including permanent damage of the ATtiny.

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 01:00:06 pm
content: I have tried lowering the load capacitance by removing caps altogether, MCU starts up, but does not start after abuse. And I can throw it off easier - by just touching the can, not a pin. Of course this is too extreme, but I don't have small capacitors on hand now. I have noticed similar behavior with just 18pF of capacitance, so I don't think going smaller is going to improve anything, but I will try later.My fuses are set up correctly. Actually this is on a product that sells for several years, I have just noticed this today.As for point listed by RoGeorge, there is "check" to all the rest of the questions. This is on a PCB with fairly tight routing.Thanks for your responses so far.

author: orolo
author_rank: Frequent Contributor
timestamp: October 12, 2017, 01:07:54 pm
content: The crystal pins are multipurpose, so maybe when you crash the MCU the Pierce crystal mode on the pins is disabled until reset. Maybe you could try crashing the MCU and then injecting a signal in each crystal pin, and testing if it is inverted in the other, or if the crystal restarts with that 'bump'. That would prove that the pins are still in Pierce mode, and it is the crystal that won't start up. The fact that this doesn't happen in the arduino is interesting, however.

author: David Hess
author_rank: Super Contributor
timestamp: October 12, 2017, 01:54:10 pm
content: The crystal might have high series resistance or the integrated oscillator circuit may lack gain to reliably start under all conditions. The later is a common problem with CMOS gate oscillator circuits; they should not require a "jump start" to operate.

author: RoGeorge
author_rank: Super Contributor
timestamp: October 12, 2017, 02:02:15 pm
content: I noticed on the PCB is written 3.3V, but you are also saying that the checklist point #1, power voltage between 4.5 and 5.5V, is also met.If the power is only 3.3V, then the ATtiny is already out of specs with a 16MHz clock, even without touching the pins. Arduino is powered at 5V, maybe that is why ATmega manage to recover, but ATtiny doesn't.Also, when touching a pin is not only the body capacitance added, but also big electrostatic spikes and possible hundreds of volts from the 50/60 Hz mains hum induced in the body. An internal latch-up can easily occur in these conditions, it is very hard, if not impossible to predict what will happen. These are just wild guesses.I don't have an ATtiny144 to test, but I remember an ATtiny13 was working just fine after touching the oscillator pins, without cycling the power. That was at 5V and on breadboard without any crystal capacitors.

author: Leo Bodnar
author_rank: Frequent Contributor
timestamp: October 12, 2017, 04:52:05 pm
content: If this is such a problem, why not use XO?In desperation, try placing a few MOhm resistor in parallel with the crystal to bias the internal oscillator.Leo

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 12, 2017, 05:28:58 pm
content: Quote from: RoGeorge on October 12, 2017, 12:36:30 pmPlease abuse something and test to see if it recovers!This is how you make reliable equipment (in part)!Quote from: David Hess on October 12, 2017, 01:54:10 pmThis.Unless specified otherwise in the datasheet, MCU oscillators contain the biasing resistor and feedback and amplification needed to excite the crystal. From a dead stop, or from an impulse. It is supposed to start up on its own, regardless.I just went through testing an STM32 with 32kHz crystal, and found that the original part was chosen wrong: the crystal needed 8pF when the oscillator could only reliably start with 4pF. Solution: same crystal mfg and series, but a special variant that's low capacitance, and advertised for STM32s as a matter of fact.The technical mechanism is two things:1. The impedance of the crystal, that is, the amount of voltage developed across it, for a given input current (V = I*Z), and is approximately equal to the reactance of the loading capacitance. A crystal with higher loading capacitance is a lower impedance load on the oscillator (the crystal will also have lower ESR).2. The oscillator is a transconductance amplifier. That is, an input voltage causes an output current. The transconductance is sometimes given in the datasheet or appnote. The transconductance must be larger than the conductance of the crystal (conductance = 1/resistance), or it won't oscillate.The oscillator is nonlinear, so it might be able to start up from a transient, and maintain operation at a fixed level, but it might not restart from a zero level. The average transconductance varies, and you need to work with the worst-case figure.Note that the loading capacitance, specified in the crystal's datasheet, is the total parallel capacitance across the crystal. Take this figure anddouble it, to get the amount of capacitance from each side to ground. The two capacitors act in series, so the crystal sees half. Finally, subtract the crystal holder capacitance (this is usually small, 1-2pF), subtract the trace and pad capacitance (probably ~1pF in a typical layout), and subtract the pin capacitance (look it up, it should be in the MCU datasheet or appnote; typically 2-10pF).Thus, if you aren't getting reliable operation, you must purchase a crystal with smaller loading capacitance. ESR may be higher.It is always safe to go with a higher impedance crystal, but, the stability and tolerance will be poorer. This may be a concern in RTC applications. For general serial communications, boring stuff like that, you won't care about precision crystal accuracy.Tim

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 08:57:43 pm
content: Quote from: RoGeorge on October 12, 2017, 02:02:15 pmYes, the traces say it is 3.3V, but I have tried it on another 5V device also. They both have this part identical.I have ordered a bunch of different crystals with lower load capacitance - 8 - 12 pF instead of 18pF, will try them next Monday and will come back here.Also, any hacks I could try with the current setup to validate any of the theory? I will try soldering 10M resistor in parallel to crystal. What else I could do?

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 09:15:27 pm
content: So, test results are as follows - the board had 5x18pF capacitance on every crystal pin from previous experimentation.I have soldered 10M in parallel with the crystal - this improved stability a bit - crystal would restart if I touched it for short time, but would hickup after longer (4 - 5 seconds) touch. Then I have soldered another 10M in parallel making 5M. This improved thing again. I still could crash the oscillator, but it seemed to be much more rare than with 10M.Then I have removed extra caps leaving 36pF on every pin (this is 18pF crystal, to 36pF should be in the ballpark). This made thing worse - oscillator stops reliably after every touch as if before adding resistors.

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 09:19:48 pm
content: Quote from: RoGeorge on October 12, 2017, 02:02:15 pmATtiny441 is one of the newer chips, more low power. I wander if they do some kick to the oscillator after reset and then reduce the drive to save the power...Note that not only power cycling starts oscillation again, but resetting the chip via reset pin also.

author: floobydust
author_rank: Super Contributor
timestamp: October 12, 2017, 09:23:04 pm
content: What are you powering the ATtiny441 with?If you are using an ungrounded SMPS wall-adapter (two prong) the common-mode noise will be very high and touching ANY crystal oscillator will upset it.The oscillator probably starts up again, just the MCU has crashed.Atmel: "A step change in frequency of more than 2% from one cycle to the next can lead to unpredictable behavior."

author: David Hess
author_rank: Super Contributor
timestamp: October 12, 2017, 09:23:49 pm
content: Quote from: miceuz on October 12, 2017, 08:57:43 pmI think Bob Pease mentioned a couple of tests which should be done:1. Make sure it starts when the supply voltage is slowly ramped up. I would monitor the output drive of the oscillator to make sure it is actually following the voltage ramp and nothing funny is going on.2. Test that it starts up at low temperature. This might only apply for bipolar transistor oscillators though where transconductance is lower at low temperatures. Maybe high temperatures for CMOS oscillators?This would not be the first time I have heard about a marginal integrated CMOS crystal oscillator. I suspect manufacturers get a little careless with them.

author: miceuz
author_rank: Frequent Contributor
timestamp: October 12, 2017, 09:43:29 pm
content: Quote from: floobydust on October 12, 2017, 09:23:04 pmYes, I am powering if from ungrounded USB charger I am powering raspberry with.Somehow I did not come to me that MCU might be crashed... Will test this tomorrow.

author: miceuz
author_rank: Frequent Contributor
timestamp: October 13, 2017, 09:05:08 am
content: Thanks to all for your help and ideas. I was misguided. Iassumed. Again.I assumed that oscillator stops and does not recover, while in reality my firmware was crashing as @floobydust pointed out. I was monitoring the device by the fact that it responds to serial communication (this is a Modbus device).Today I have finally hooked up the scope and tested the oscillator - it runs just fine after I remove my dirty fingers, but the firmware stops responding.Then I have tried enabling Watchdog via software. This improved things a lot - it would reset after the watchdog timeout on most occasions, but sometimes it will stay stuck. Then I have enabled Watchdog in fuses and this made the device rock solid - it positively recovers after WD timeout every time.Thank you all for this ride, it was really entertaining and revealing.

author: RoGeorge
author_rank: Super Contributor
timestamp: October 13, 2017, 11:40:38 am
content: I know, it happens to me too, again and again